diff --git a/src/ui/atoms/SelectField.tsx b/src/ui/atoms/SelectField.tsx index e3fd5089..7458ec4d 100644 --- a/src/ui/atoms/SelectField.tsx +++ b/src/ui/atoms/SelectField.tsx @@ -67,7 +67,7 @@ const SelectField = ({ /> ); return ( -
+
diff --git a/src/ui/molecules/ToggleComponent.test.tsx b/src/ui/molecules/ToggleComponent.test.tsx new file mode 100644 index 00000000..8821afe1 --- /dev/null +++ b/src/ui/molecules/ToggleComponent.test.tsx @@ -0,0 +1,118 @@ +import React from 'react'; +import { cleanup, render, RenderResult } from '@testing-library/react'; +import ToggleComponent from './ToggleComponent'; + +describe('ToggleComponent', (): void => { + afterEach(cleanup); + + it('should render correctly', (): void => { + expect( + (): RenderResult => + render( + , + ), + ).not.toThrow(); + }); + + it('should render correctly with all props', (): void => { + expect( + (): RenderResult => + render( + , + ), + ).not.toThrow(); + }); + + it('should render question title correctly', (): void => { + const questionTitle = 'Question title'; + const { getByText } = render( + , + ); + expect(getByText(questionTitle)).toBeInTheDocument(); + }); + + it('should be empty in the primary select field', (): void => { + const { container } = render( + , + ); + + expect(container.querySelector('.select-field__placeholder')).toBeInTheDocument(); + }); + + it('should be empty in the secondary select field', (): void => { + const { container } = render( + , + ); + + expect(container.querySelector('.select-field__placeholder')).toBeInTheDocument(); + }); + + it('should have a value in the primary select dropdown field', (): void => { + const { container } = render( + , + ); + + expect(container.querySelector('#selectField').textContent).toContain('Argentina'); + }); + + it('should have a value in the secondary select dropdown field', (): void => { + const { container } = render( + , + ); + + expect(container.querySelector('#selectFieldTwo').textContent).toContain('Canada'); + }); +}); diff --git a/src/ui/molecules/ToggleComponent.tsx b/src/ui/molecules/ToggleComponent.tsx new file mode 100644 index 00000000..88dbe8f3 --- /dev/null +++ b/src/ui/molecules/ToggleComponent.tsx @@ -0,0 +1,40 @@ +import React, { ReactNode } from 'react'; +import { ContentToggle, SelectField } from '../atoms'; + +export interface Value { + label: string; + value: string; +} + +interface Props { + id: string; + selectId: string; + children?: ReactNode; + labelText: string; + openText: string; + collapsedText: string; + questionTitle: string; + defaultValue?: Value; + values?: Value[]; +} + +const ToggleComponent = ({ + id, + selectId, + collapsedText, + openText, + questionTitle, + labelText, + defaultValue, + values, +}: Props): JSX.Element => { + return ( +
+

{questionTitle}

+ + +
+ ); +}; + +export default ToggleComponent; diff --git a/src/ui/molecules/index.ts b/src/ui/molecules/index.ts index 29cc4231..9c31468f 100644 --- a/src/ui/molecules/index.ts +++ b/src/ui/molecules/index.ts @@ -15,4 +15,5 @@ export { default as SearchField } from './SearchField'; export { default as SelectedPeopleList } from './SelectedPeopleList'; export { default as SelectedOption } from './SelectedOption'; export { default as Toggle } from './Toggle'; +export { default as ToggleComponent } from './ToggleComponent'; export { default as UploadProgress } from './UploadProgress'; diff --git a/src/ui/stories/molecules/ToggleComponent.stories.tsx b/src/ui/stories/molecules/ToggleComponent.stories.tsx new file mode 100644 index 00000000..88d79515 --- /dev/null +++ b/src/ui/stories/molecules/ToggleComponent.stories.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { storiesOf } from '@storybook/react'; +import { withKnobs } from '@storybook/addon-knobs'; +import '../../../core/styles/index.scss'; +import centered from '@storybook/addon-centered/react'; +import { ContentToggle, SelectField } from '../../atoms'; + +storiesOf('ui | molecules/Toggle', module) + .addDecorator(withKnobs) + .addDecorator(centered) + .add( + 'ToggleComponent', + (): JSX.Element => { + const collapsedText = '+ Add a second country of residence/affiliation'; + const openText = '- Remove a second country of residence/affiliation'; + const title = 'Your country of residence or professional affiliation'; + const labelText = 'Secondary country of residence/affiliation'; + const options = [ + { label: 'Argentina', value: 'argentina' }, + { label: 'Canada', value: 'canada' }, + { label: 'Denmark', value: 'denmark' }, + { label: 'France', value: 'france' }, + { label: 'Hungary', value: 'hungary' }, + { label: 'Peru', value: 'peru' }, + ]; + return ( +
+

{title}

+ + + + +
+ ); + }, + ); diff --git a/src/ui/styles/ToggleComponent.scss b/src/ui/styles/ToggleComponent.scss new file mode 100644 index 00000000..8237fd6c --- /dev/null +++ b/src/ui/styles/ToggleComponent.scss @@ -0,0 +1,3 @@ +.select-field { + margin-bottom: 1.5rem; +} \ No newline at end of file diff --git a/src/ui/styles/index.scss b/src/ui/styles/index.scss index 9f28f6c2..b9912782 100644 --- a/src/ui/styles/index.scss +++ b/src/ui/styles/index.scss @@ -34,6 +34,7 @@ @import './SelectedPeopleList'; @import './ContentToggle'; @import './Toggle'; +@import './ToggleComponent'; @import './UploadProgress'; @import './RichTextEditor';