-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugFix: When the feature flag is enabled and sx prop is passed in use…
…, Box (#5068) * When the feature flag is enabled and sx prop is passed in use, Box * Create plenty-books-agree.md * Adding tests * Add as button back
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@primer/react": patch | ||
--- | ||
|
||
fix for `toggleStyledComponent` utility, When the feature flag is enabled and sx prop is passed in use, Box |
49 changes: 49 additions & 0 deletions
49
packages/react/src/internal/utils/__tests__/toggleStyledComponent.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,49 @@ | ||
import React from 'react' | ||
import {render} from '@testing-library/react' | ||
import {FeatureFlags} from '../../../FeatureFlags' | ||
import {toggleStyledComponent} from '../toggleStyledComponent' | ||
import styled from 'styled-components' | ||
|
||
describe('toggleStyledComponent', () => { | ||
test('renders the `as` prop when flag is enabled', () => { | ||
const TestComponent = toggleStyledComponent('testFeatureFlag', () => <div />) | ||
const {container} = render( | ||
<FeatureFlags flags={{testFeatureFlag: true}}> | ||
<TestComponent as="button" /> | ||
</FeatureFlags>, | ||
) | ||
expect(container.firstChild).toBeInstanceOf(HTMLButtonElement) | ||
}) | ||
|
||
test('renders a div as fallback when flag is enabled and no `as` prop is provided', () => { | ||
const TestComponent = toggleStyledComponent('testFeatureFlag', () => <div />) | ||
const {container} = render( | ||
<FeatureFlags flags={{testFeatureFlag: true}}> | ||
<TestComponent /> | ||
</FeatureFlags>, | ||
) | ||
expect(container.firstChild).toBeInstanceOf(HTMLDivElement) | ||
}) | ||
|
||
test('renders Box with `as` if `sx` is provided and flag is enabled', () => { | ||
const TestComponent = toggleStyledComponent('testFeatureFlag', () => styled.div``) | ||
const {container} = render( | ||
<FeatureFlags flags={{testFeatureFlag: true}}> | ||
<TestComponent as="button" sx={{color: 'red'}} /> | ||
</FeatureFlags>, | ||
) | ||
|
||
expect(container.firstChild).toBeInstanceOf(HTMLButtonElement) | ||
expect(container.firstChild).toHaveStyle('color: red') | ||
}) | ||
|
||
test('renders styled component when flag is disabled', () => { | ||
const StyledComponent = toggleStyledComponent('testFeatureFlag', styled.div.attrs({['data-styled']: true})``) | ||
const {container} = render( | ||
<FeatureFlags flags={{testFeatureFlag: false}}> | ||
<StyledComponent /> | ||
</FeatureFlags>, | ||
) | ||
expect(container.firstChild).toHaveAttribute('data-styled') | ||
}) | ||
}) |
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