-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor(web): Collapse API prop changed
- prop `hideOnCollapse`` changed to `isDisposable` - Solves DS-832
- Loading branch information
1 parent
eefd2c9
commit 914210f
Showing
8 changed files
with
210 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/web-react/src/components/Collapse/__tests__/Collapse.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import React, { useState } from 'react'; | ||
import { classNamePrefixProviderTest } from '../../../../tests/providerTests/classNamePrefixProviderTest'; | ||
import { restPropsTest } from '../../../../tests/providerTests/restPropsTest'; | ||
import { stylePropsTest } from '../../../../tests/providerTests/stylePropsTest'; | ||
import { Button } from '../../Button'; | ||
import Collapse from '../Collapse'; | ||
|
||
describe('UncontrolledCollapse', () => { | ||
classNamePrefixProviderTest(Collapse, 'Collapse'); | ||
|
||
stylePropsTest(Collapse); | ||
|
||
restPropsTest(Collapse, 'div'); | ||
|
||
it('should render text children', () => { | ||
render( | ||
<Collapse id="collapse" isOpen data-testId="test"> | ||
Hello World | ||
</Collapse>, | ||
); | ||
|
||
const element = screen.getByTestId('test'); | ||
expect(element).toHaveTextContent('Hello World'); | ||
expect(element).toHaveClass('is-open'); | ||
}); | ||
|
||
it('should open collapse', () => { | ||
const RenderCollapse = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Button type="button" data-testId="test-button" onClick={() => setIsOpen(!isOpen)}> | ||
Toggle Collapse | ||
</Button> | ||
<Collapse id="collapse" isOpen={isOpen} data-testId="test"> | ||
Hello World | ||
</Collapse> | ||
</> | ||
); | ||
}; | ||
|
||
render(<RenderCollapse />); | ||
|
||
const toggleButton = screen.getByTestId('test-button'); | ||
const collapseElement = screen.getByTestId('test'); | ||
|
||
expect(collapseElement).not.toHaveClass('is-open'); | ||
|
||
fireEvent.click(toggleButton); | ||
|
||
expect(collapseElement).toHaveClass('is-open'); | ||
}); | ||
|
||
it('should have correct html element', () => { | ||
render( | ||
<Collapse id="collapse" elementType="section" isOpen data-testId="test"> | ||
Hello World | ||
</Collapse>, | ||
); | ||
|
||
const element = screen.getByTestId('test'); | ||
|
||
expect(element.tagName).toBe('SECTION'); | ||
}); | ||
|
||
// @TODO: Missing tests for props - collapsibleToBreakpoint, transitionDuration | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 20 additions & 7 deletions
27
packages/web-react/src/components/Collapse/demo/CollapseUncontrolled.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
// Because there is no `dist` directory during the CI run | ||
/* eslint-disable import/no-extraneous-dependencies, import/extensions, import/no-unresolved */ | ||
import { StoryFn } from '@storybook/react'; | ||
import React from 'react'; | ||
import { Button } from '../../Button'; | ||
import UncontrolledCollapse from '../UncontrolledCollapse'; | ||
import { CollapseTrigger, content } from './Collapse'; | ||
|
||
const Story: StoryFn<typeof UncontrolledCollapse> = () => { | ||
const UncontrolledCollapseDemo = () => { | ||
const content = ( | ||
<p> | ||
Condimentum odio, pulvinar et sollicitudin accumsan ac hendrerit vestibulum commodo, molestie laoreet dui sit | ||
amet. Molestie consectetur, sed ac felis scelerisque lectus accumsan purus id dolor sed vitae, praesent aliquam | ||
dolor quis ornare. Nulla sit amet, rhoncus at quis odio et iaculis lacinia suscipit vivamus sodales, nunc id | ||
condimentum felis. Consectetur nec commodo, praesent et elit magna purus molestie cursus molestie, libero ut | ||
venenatis erat id et nisi. Quam posuere, aliquam quam leo vitae tellus semper eget nunc, ultricies adipiscing sit | ||
amet accumsan. Lorem rutrum, porttitor ante mauris suspendisse ultricies consequat purus, congue a commodo magna | ||
et. | ||
</p> | ||
); | ||
|
||
return ( | ||
<div> | ||
{content} | ||
<UncontrolledCollapse id="uncontrolled-collapse-id" renderTrigger={CollapseTrigger}> | ||
<UncontrolledCollapse | ||
id="uncontrolled-collapse-id" | ||
renderTrigger={(props) => <Button {...props}>… more</Button>} | ||
isDisposable | ||
> | ||
{content} | ||
</UncontrolledCollapse> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Story; | ||
export default UncontrolledCollapseDemo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters