import * as React from 'react'; import { Toolbar } from 'src/components/Toolbar/Toolbar'; import { toggleButtonBehavior } from '@fluentui/accessibility'; import { isConformant, getRenderedAttribute } from 'test/specs/commonTests'; import { mountWithProvider, findIntrinsicElement } from 'test/utils'; import { BoldIcon, ItalicIcon } from '@fluentui/react-icons-northstar'; type BaseComponentProps = { color?: string } & React.HTMLAttributes; const boldButtonId = 'item1'; const italicButtonId = 'item2'; const BaseComponent: React.FC = props => { const [bold, setBold] = React.useState(false); const [italic, setItalic] = React.useState(true); const getItems = () => [ { accessibility: toggleButtonBehavior, active: bold, icon: , title: 'Toggle bold', onClick: () => setBold(!bold), id: boldButtonId, key: 'toolbar-item-1', }, { accessibility: toggleButtonBehavior, active: italic, icon: , title: 'Toggle italic', onClick: () => setItalic(!italic), id: italicButtonId, key: 'toolbar-item-2', }, ]; return ; }; describe('Toolbar', () => { isConformant(Toolbar, { constructorName: 'Toolbar' }); isConformant(Toolbar, { constructorName: 'Toolbar', requiredProps: { overflow: true }, }); describe('aria-pressed is changing accordingly to state', () => { it('renders children', () => { const wrapper = mountWithProvider(); const boldToolbarButton = findIntrinsicElement(wrapper, `#${boldButtonId}`); const italicToolbarButton = findIntrinsicElement(wrapper, `#${italicButtonId}`); expect(getRenderedAttribute(boldToolbarButton, 'aria-pressed', '')).toBe('false'); expect(getRenderedAttribute(italicToolbarButton, 'aria-pressed', '')).toBe('true'); boldToolbarButton.simulate('click'); italicToolbarButton.simulate('click'); expect(getRenderedAttribute(boldToolbarButton, 'aria-pressed', '')).toBe('true'); expect(getRenderedAttribute(italicToolbarButton, 'aria-pressed', '')).toBe('false'); }); }); });