-
Notifications
You must be signed in to change notification settings - Fork 31
feat: Layout related logical CSS props #3267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| import { theme } from '@codecademy/gamut-styles'; | ||
| import { setupRtl } from '@codecademy/gamut-tests'; | ||
| import { MockGamutProvider, setupRtl } from '@codecademy/gamut-tests'; | ||
| import { matchers } from '@emotion/jest'; | ||
| import { render } from '@testing-library/react'; | ||
|
|
||
| import { List } from '../List'; | ||
| import { List, ListProps } from '../List'; | ||
| import { ListCol } from '../ListCol'; | ||
| import { ListRow } from '../ListRow'; | ||
|
|
||
|
|
@@ -131,28 +132,60 @@ describe('List', () => { | |
| expect(view.queryByText('Surprise!')).toBeNull(); | ||
| }); | ||
|
|
||
| describe('wrapperWidth prop', () => { | ||
| it('applies wrapperWidth to the table container when provided', () => { | ||
| const { view } = renderView({ wrapperWidth: '500px' }); | ||
|
|
||
| const tableContainer = view.container.querySelector( | ||
| '[data-testid="scrollable-list-el"]' | ||
| describe.each([ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm a big fan of this pattern!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably won't need it with visual testing 🤞 |
||
| { | ||
| useLogicalProperties: true, | ||
| widthProp: 'inlineSize', | ||
| maxWidthProp: 'maxInlineSize', | ||
| }, | ||
| { | ||
| useLogicalProperties: false, | ||
| widthProp: 'width', | ||
| maxWidthProp: 'maxWidth', | ||
| }, | ||
| ])( | ||
| 'wrapperWidth prop (useLogicalProperties: $useLogicalProperties)', | ||
| ({ useLogicalProperties, widthProp, maxWidthProp }) => { | ||
| const defaultChildren = ( | ||
| <ListRow data-testid="row-el"> | ||
| <ListCol>Hello</ListCol> | ||
| </ListRow> | ||
| ); | ||
| expect(tableContainer).toHaveStyle({ maxWidth: '500px', width: '500px' }); | ||
| }); | ||
|
|
||
| it('uses inherit width when wrapperWidth is not provided', () => { | ||
| const { view } = renderView(); | ||
| const renderWithLogicalProps = (overrides?: Partial<ListProps>) => | ||
| render( | ||
| <MockGamutProvider useLogicalProperties={useLogicalProperties}> | ||
| <List id="list-el" {...overrides}> | ||
| {overrides?.children ?? defaultChildren} | ||
| </List> | ||
| </MockGamutProvider> | ||
| ); | ||
|
|
||
| it('applies wrapperWidth to the table container when provided', () => { | ||
| const view = renderWithLogicalProps({ wrapperWidth: '500px' }); | ||
|
|
||
| const tableContainer = view.container.querySelector( | ||
| '[data-testid="scrollable-list-el"]' | ||
| ); | ||
| expect(tableContainer).toHaveStyle({ | ||
| [maxWidthProp]: '500px', | ||
| [widthProp]: '500px', | ||
| }); | ||
| }); | ||
|
|
||
| it('uses inherit width when wrapperWidth is not provided', () => { | ||
| const view = renderWithLogicalProps(); | ||
|
|
||
| const tableContainer = view.container.querySelector( | ||
| '[data-testid="scrollable-list-el"]' | ||
| ); | ||
| expect(tableContainer).toHaveStyle({ | ||
| maxWidth: '100%', | ||
| width: 'inherit', | ||
| const tableContainer = view.container.querySelector( | ||
| '[data-testid="scrollable-list-el"]' | ||
| ); | ||
| expect(tableContainer).toHaveStyle({ | ||
| [maxWidthProp]: '100%', | ||
| [widthProp]: 'inherit', | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| ); | ||
|
|
||
| it('applies container query styles by default', () => { | ||
| const { view } = renderView(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason for the boolean if we aren't testing both props
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... nice catch —
in fixing this issue, turns out that the test was still failing (locally) but not showing up in GH for some reason.
Will update soon!