-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Text): allow pass thml attributes durind Box inheritance
- Loading branch information
1 parent
fcd2ff3
commit 3abfe9e
Showing
6 changed files
with
175 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
|
||
import {render} from '../../../../test-utils/utils'; | ||
import {Button} from '../../Button'; | ||
import {Text} from '../Text'; | ||
|
||
describe('Text', () => { | ||
test('should return expected jsx if no props passed', () => { | ||
const {container} = render(<Text>Hello World!</Text>); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('should return expected jsx if qa attr passed and variant changed', () => { | ||
const {container} = render( | ||
<Text qa="test" variant={'caption-1'}> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('should return expected jsx if html attributes passed and changed default html tag and with typed ref', () => { | ||
const ComponentWithRef = () => { | ||
const ref = React.useRef<HTMLLabelElement>(null); | ||
|
||
return ( | ||
<Text as="label" htmlFor="some-id" ref={ref}> | ||
Hello World! | ||
</Text> | ||
); | ||
}; | ||
|
||
const {container} = render(<ComponentWithRef />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('should return expected jsx if passed props what converted to classNames and styles', () => { | ||
const {container} = render( | ||
<Text | ||
width={200} | ||
ellipsisLines={2} | ||
ellipsis={true} | ||
whiteSpace="break-spaces" | ||
wordBreak="break-word" | ||
> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('should return expected jsx with another component substitution', () => { | ||
const {container} = render( | ||
<Text as={Button} size={'m'} width={100} spacing={{mr: 2}}> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
src/components/Text/__tests__/__snapshots__/Text.test.tsx.snap
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,60 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Text should return expected jsx if html attributes passed and changed default html tag and with typed ref 1`] = ` | ||
<div> | ||
<label | ||
class="g-box g-text g-text_variant_body-1" | ||
for="some-id" | ||
> | ||
Hello World! | ||
</label> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected jsx if no props passed 1`] = ` | ||
<div> | ||
<span | ||
class="g-box g-text g-text_variant_body-1" | ||
> | ||
Hello World! | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected jsx if passed props what converted to classNames and styles 1`] = ` | ||
<div> | ||
<span | ||
class="g-box g-text g-text_variant_body-1 g-text_ellipsis g-text_ws_break-spaces g-text_wb_break-word g-text_ellipsis-lines" | ||
style="width: 200px;" | ||
> | ||
Hello World! | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected jsx if qa attr passed and variant changed 1`] = ` | ||
<div> | ||
<span | ||
class="g-box g-text g-text_variant_caption-1" | ||
data-qa="test" | ||
> | ||
Hello World! | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected jsx with another component substitution 1`] = ` | ||
<div> | ||
<button | ||
class="g-button g-button_view_normal g-button_size_m g-button_pin_round-round g-box g-s__mr_2 g-text g-text_variant_body-1" | ||
style="width: 100px;" | ||
type="button" | ||
> | ||
<span | ||
class="g-button__text" | ||
> | ||
Hello World! | ||
</span> | ||
</button> | ||
</div> | ||
`; |
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