From 488bcfe5a35f15638b08392b5ca1ebb242e7d7a4 Mon Sep 17 00:00:00 2001 From: Emile Netter Date: Wed, 21 Apr 2021 15:53:16 +0200 Subject: [PATCH] feat(lib): add stories + tests --- .../junipero/lib/RadioField/index.stories.js | 115 ++++++++++++++++++ .../junipero/lib/RadioField/index.test.js | 31 +++++ 2 files changed, 146 insertions(+) create mode 100644 packages/junipero/lib/RadioField/index.stories.js create mode 100644 packages/junipero/lib/RadioField/index.test.js diff --git a/packages/junipero/lib/RadioField/index.stories.js b/packages/junipero/lib/RadioField/index.stories.js new file mode 100644 index 000000000..a38039e77 --- /dev/null +++ b/packages/junipero/lib/RadioField/index.stories.js @@ -0,0 +1,115 @@ +import React, { useState } from 'react'; +import { action } from '@storybook/addon-actions'; + +import RadioField from './index'; + +export default { title: 'junipero/RadioField' }; + +export const basic = () => { + const [checked, setChecked] = useState(false); + + const onChange = value => { + setChecked(value.checked); + }; + + return ( + <> + onChange(value)} + label="Enabled"/> + + + + ); +}; + +export const disabled = () => { + return ( + + ); +}; + +export const active = () => { + return ( + + ); +}; + +export const activeDisabled = () => { + return ( + + ); +}; + +export const withDescription = () => { + return ( + + ); +}; + +export const withDescriptionAndUnchecked = () => { + return ( + + ); +}; + +export const withDescriptionButDisabled = () => { + return ( + + ); +}; + +export const withDescriptionChecked = () => { + return ( + + ); +}; + +export const twoRadiosCombined = () => { + const [smart, setSmart] = useState(false); + const [strong, setStrong] = useState(false); + + const onChange = (value, type) => { + }; + + return ( + <> + onChange(value, 'strong')} + checked={strong} + /> + onChange(value, 'smart')} + checked={smart} + /> + + ); +}; diff --git a/packages/junipero/lib/RadioField/index.test.js b/packages/junipero/lib/RadioField/index.test.js new file mode 100644 index 000000000..253b00fb7 --- /dev/null +++ b/packages/junipero/lib/RadioField/index.test.js @@ -0,0 +1,31 @@ +import React, { createRef } from 'react'; +import { mount } from 'enzyme'; +import sinon from 'sinon'; + +import RadioField from './'; + +describe('', () => { + + it('should render', () => { + const component = mount( + + ); + expect(component.find('.junipero.radio').length).toBe(1); + }); + + it('should provide some imperative handles', () => { + const ref = createRef(); + const component = mount(); + expect(ref.current.innerRef.current).toBeDefined(); + expect(component.getDOMNode()).toBe(ref.current.innerRef.current); + }); + + it('should correctly fire onChange event', () => { + const onChange = sinon.spy(); + const component = mount(); + component.find('input').simulate('change', { target: { checked: true } }); + expect(onChange.withArgs(sinon.match({ checked: true })).called) + .toBe(true); + }); + +});