From 77e3ce343a50ffae041728203f32ee867fb715e4 Mon Sep 17 00:00:00 2001 From: Bernard Date: Thu, 29 Oct 2020 12:23:31 -0500 Subject: [PATCH] [WNMGDS-676] Update help drawer toggle to be a button (#860) * Update helpdrawer toggle to be transparent button, allow extra props * Update tests and snaps, move display block to CSS * update snapshot * update html example with button Co-authored-by: Scott Weber --- .../HelpDrawer/help-drawer.example.html | 6 +-- .../HelpDrawer/HelpDrawerToggle.jsx | 34 +++++++------- .../HelpDrawer/HelpDrawerToggle.test.jsx | 44 +++++++++++-------- .../HelpDrawerToggle.test.jsx.snap | 25 ++++++----- .../src/styles/components/_HelpDrawer.scss | 6 +++ 5 files changed, 67 insertions(+), 48 deletions(-) diff --git a/packages/design-system-docs/src/pages/components/HelpDrawer/help-drawer.example.html b/packages/design-system-docs/src/pages/components/HelpDrawer/help-drawer.example.html index b4103a01fc..58bd87ba91 100644 --- a/packages/design-system-docs/src/pages/components/HelpDrawer/help-drawer.example.html +++ b/packages/design-system-docs/src/pages/components/HelpDrawer/help-drawer.example.html @@ -10,9 +10,9 @@ labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

- - Toggle the help drawer. - +
since a
may be invalid depending where this link is nested - - (this.buttonRef = el)} - onClick={() => this.props.showDrawer()} - > - {this.props.children} - - + ); } } -/* eslint-disable react/no-unused-prop-types */ HelpDrawerToggle.propTypes = { /** * Whether or not the Help Drawer controlled by this toggle is open or closed. diff --git a/packages/design-system/src/components/HelpDrawer/HelpDrawerToggle.test.jsx b/packages/design-system/src/components/HelpDrawer/HelpDrawerToggle.test.jsx index eae2a04555..e451169660 100644 --- a/packages/design-system/src/components/HelpDrawer/HelpDrawerToggle.test.jsx +++ b/packages/design-system/src/components/HelpDrawer/HelpDrawerToggle.test.jsx @@ -1,12 +1,11 @@ import HelpDrawerToggle from './HelpDrawerToggle.jsx'; import React from 'react'; -import renderer from 'react-test-renderer'; import { shallow } from 'enzyme'; const defaultProps = { helpDrawerOpen: false, - inline: true, - showDrawer: () => {}, + inline: false, + showDrawer: jest.fn(), }; function renderHelpDrawerToggle(props) { @@ -20,23 +19,32 @@ function renderHelpDrawerToggle(props) { } describe('HelpDrawerToggle', () => { - it('calls props.showDrawer on link click', () => { - const showDrawer = jest.fn(); - const { wrapper } = renderHelpDrawerToggle({ showDrawer }); - const link = wrapper.find('a'); - link.simulate('click'); - expect(showDrawer).toHaveBeenCalled(); + beforeEach(() => { + defaultProps.showDrawer.mockClear(); }); - it('renders a snapshot', () => { - const tree = renderer - .create( - -

link content

-
- ) - .toJSON(); + it('renders a button', () => { + const { wrapper } = renderHelpDrawerToggle(); + expect(wrapper).toMatchSnapshot(); + }); + + it('calls props.showDrawer on toggle click', () => { + const { wrapper } = renderHelpDrawerToggle(); + const toggle = wrapper.find('Button'); + toggle.simulate('click'); + expect(defaultProps.showDrawer).toHaveBeenCalled(); + }); + + it('applies display utility through inline props', () => { + const { wrapper } = renderHelpDrawerToggle({ inline: true }); + const toggle = wrapper.find('Button'); + expect(toggle.hasClass('ds-u-display--inline')).toBe(true); + }); - expect(tree).toMatchSnapshot(); + it('passes through extra props', () => { + const ariaLabel = 'test'; + const { wrapper } = renderHelpDrawerToggle({ ariaLabel }); + const toggle = wrapper.find('Button'); + expect(toggle.props().ariaLabel).toBe(ariaLabel); }); }); diff --git a/packages/design-system/src/components/HelpDrawer/__snapshots__/HelpDrawerToggle.test.jsx.snap b/packages/design-system/src/components/HelpDrawer/__snapshots__/HelpDrawerToggle.test.jsx.snap index 0ef5f9bf42..dc7c35784c 100644 --- a/packages/design-system/src/components/HelpDrawer/__snapshots__/HelpDrawerToggle.test.jsx.snap +++ b/packages/design-system/src/components/HelpDrawer/__snapshots__/HelpDrawerToggle.test.jsx.snap @@ -1,16 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`HelpDrawerToggle renders a snapshot 1`] = ` - - -

- link content -

-
-
+

+ content +

+ `; diff --git a/packages/design-system/src/styles/components/_HelpDrawer.scss b/packages/design-system/src/styles/components/_HelpDrawer.scss index 73d541da6f..516e606c45 100644 --- a/packages/design-system/src/styles/components/_HelpDrawer.scss +++ b/packages/design-system/src/styles/components/_HelpDrawer.scss @@ -34,6 +34,12 @@ } } +.ds-c-help-drawer__toggle { + display: block; + font-weight: $font-normal; + padding: 0; +} + .ds-c-help-drawer__close-button { flex-shrink: 0; }