diff --git a/js/components/__tests__/checkbox_input.test.js b/js/components/__tests__/checkbox_input.test.js index dd4d9d42..6be9c1e4 100644 --- a/js/components/__tests__/checkbox_input.test.js +++ b/js/components/__tests__/checkbox_input.test.js @@ -5,30 +5,30 @@ import checkboxinput from '../checkbox_input' import { makeTestWrapper } from '../../test_utils/component_test_helpers' const WrapperComponent = makeTestWrapper({ - components: { - checkboxinput - }, - templatePath: 'checkbox_input_template.html', + components: { + checkboxinput, + }, + templatePath: 'checkbox_input_template.html', }) describe('CheckboxInput Renders Correctly', () => { - it('Should initialize checked', () => { - const wrapper = mount(WrapperComponent, { - propsData: { - name: 'testCheck', - initialData: true - } - }) - expect(wrapper.find('.usa-input input').element.checked).toBe(true) + it('Should initialize checked', () => { + const wrapper = mount(WrapperComponent, { + propsData: { + name: 'testCheck', + initialData: true, + }, }) + expect(wrapper.find('.usa-input input').element.checked).toBe(true) + }) - it('Should initialize unchecked', () => { - const wrapper = mount(WrapperComponent, { - propsData: { - name: 'testCheck', - initialData: false - } - }) - expect(wrapper.find('.usa-input input').element.checked).toBe(false) + it('Should initialize unchecked', () => { + const wrapper = mount(WrapperComponent, { + propsData: { + name: 'testCheck', + initialData: false, + }, }) + expect(wrapper.find('.usa-input input').element.checked).toBe(false) + }) }) diff --git a/js/components/__tests__/upload_input.test.js b/js/components/__tests__/upload_input.test.js index a5c4cbeb..96a1be89 100644 --- a/js/components/__tests__/upload_input.test.js +++ b/js/components/__tests__/upload_input.test.js @@ -5,45 +5,45 @@ import uploadinput from '../upload_input' import { makeTestWrapper } from '../../test_utils/component_test_helpers' const UploadWrapper = makeTestWrapper({ - components: { uploadinput }, - templatePath: 'upload_input_template.html' + components: { uploadinput }, + templatePath: 'upload_input_template.html', }) const UploadErrorWrapper = makeTestWrapper({ - components: { uploadinput }, - templatePath: 'upload_input_error_template.html' + components: { uploadinput }, + templatePath: 'upload_input_error_template.html', }) describe('UploadInput Test', () => { - it('should show input and button when no attachment present', () => { - const wrapper = mount(UploadWrapper, { - propsData: { - initialData: null - } - }) - - const fileInput = wrapper.find('input[type=file]').element - expect(fileInput).not.toBe(undefined) + it('should show input and button when no attachment present', () => { + const wrapper = mount(UploadWrapper, { + propsData: { + initialData: null, + }, }) - it('should show file name and hide input', () => { - const wrapper = mount(UploadWrapper, { - propsData: { - initialData: 'somepdf.pdf' - } - }) + const fileInput = wrapper.find('input[type=file]').element + expect(fileInput).not.toBe(undefined) + }) - const fileInput = wrapper.find('input[type=file]').element - const fileNameSpan = wrapper.find('.uploaded-file__name') - - expect(fileInput).toBe(undefined) - expect(fileNameSpan.html()).toContain('somepdf.pdf') + it('should show file name and hide input', () => { + const wrapper = mount(UploadWrapper, { + propsData: { + initialData: 'somepdf.pdf', + }, }) - it('should correctly display error treatment', () => { - const wrapper = mount(UploadErrorWrapper) + const fileInput = wrapper.find('input[type=file]').element + const fileNameSpan = wrapper.find('.uploaded-file__name') - const messageArea = wrapper.find('.usa-input__message') - expect(messageArea.html()).toContain('Test Error Message') - }) + expect(fileInput).toBe(undefined) + expect(fileNameSpan.html()).toContain('somepdf.pdf') + }) + + it('should correctly display error treatment', () => { + const wrapper = mount(UploadErrorWrapper) + + const messageArea = wrapper.find('.usa-input__message') + expect(messageArea.html()).toContain('Test Error Message') + }) }) diff --git a/js/test_utils/component_test_helpers.js b/js/test_utils/component_test_helpers.js index 4339e81f..e81d9603 100644 --- a/js/test_utils/component_test_helpers.js +++ b/js/test_utils/component_test_helpers.js @@ -16,24 +16,25 @@ to be passed as a prop to checkboxinput at mount time v-bind:initial-checked='initialvalue' > */ -const makeTestWrapper = ({components, templatePath}) => { - const templateString = fs.readFileSync(`js/test_templates/${templatePath}`, 'utf-8') +const makeTestWrapper = ({ components, templatePath }) => { + const templateString = fs.readFileSync( + `js/test_templates/${templatePath}`, + 'utf-8' + ) - const WrapperComponent = { - name: 'WrapperComponent', - components, - template: templateString, - props: ['initialData'], - data: function() { - return { - initialvalue: this.initialData - } - } - } + const WrapperComponent = { + name: 'WrapperComponent', + components, + template: templateString, + props: ['initialData'], + data: function() { + return { + initialvalue: this.initialData, + } + }, + } - return WrapperComponent + return WrapperComponent } -export { - makeTestWrapper -} +export { makeTestWrapper } diff --git a/script/render_vue_component.py b/script/render_vue_component.py index 11e776d5..989afb9e 100644 --- a/script/render_vue_component.py +++ b/script/render_vue_component.py @@ -12,35 +12,33 @@ from wtforms import Form from atst.filters import iconSvg -env = Environment(loader=FileSystemLoader('templates')) +env = Environment(loader=FileSystemLoader("templates")) -env.filters['iconSvg'] = iconSvg +env.filters["iconSvg"] = iconSvg # override tojson as identity function to prevent # wrapping strings in extra quotes -env.filters['tojson'] = lambda x: x +env.filters["tojson"] = lambda x: x + class InitialValueForm(Form): - datafield = StringField( - label="initialvalue value", - default="initialvalue" - ) + datafield = StringField(label="initialvalue value", default="initialvalue") errorfield = StringField( - label="error", - validators=[InputRequired(message="Test Error Message")] + label="error", validators=[InputRequired(message="Test Error Message")] ) -checkbox_template = env.get_template('components/checkbox_input.html') -ci_macro = getattr(checkbox_template.module, 'CheckboxInput') + +checkbox_template = env.get_template("components/checkbox_input.html") +ci_macro = getattr(checkbox_template.module, "CheckboxInput") checkbox_input_form = InitialValueForm() checkbox_input_form.datafield.widget = CheckboxInput() rendered_checkbox_macro = ci_macro(checkbox_input_form.datafield) with open("js/test_templates/checkbox_input_template.html", "w") as fh: fh.write(rendered_checkbox_macro) -upload_template = env.get_template('components/upload_input.html') -up_macro = getattr(upload_template.module, 'UploadInput') +upload_template = env.get_template("components/upload_input.html") +up_macro = getattr(upload_template.module, "UploadInput") rendered_upload_macro = up_macro(InitialValueForm().datafield) with open("js/test_templates/upload_input_template.html", "w") as fh: fh.write(rendered_upload_macro)