-
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 0909c60
Showing
5 changed files
with
153 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
|
||
import {render} from '../../../../test-utils/utils'; | ||
import {Button} from '../../Button'; | ||
import {Text} from '../Text'; | ||
|
||
describe('Text', () => { | ||
describe('should return expected html', () => { | ||
test('if no props passed', () => { | ||
const {container} = render(<Text>Hello World!</Text>); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('if qa attr passed and variant changed', () => { | ||
const {container} = render( | ||
<Text qa="test" variant={'caption-1'}> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('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('if passed props what converted to classNames and styles', () => { | ||
const {container} = render( | ||
<Text | ||
style={{width: 200}} | ||
ellipsisLines={2} | ||
ellipsis={true} | ||
whiteSpace="break-spaces" | ||
wordBreak="break-word" | ||
> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
test('with another component substitution', () => { | ||
const {container} = render( | ||
<Text as={Button} size={'m'} view="action"> | ||
Hello World! | ||
</Text>, | ||
); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
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,59 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Text should return expected html if html attributes passed and changed default html tag and with typed ref 1`] = ` | ||
<div> | ||
<label | ||
class="g-text g-text_variant_body-1" | ||
for="some-id" | ||
> | ||
Hello World! | ||
</label> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected html if no props passed 1`] = ` | ||
<div> | ||
<span | ||
class="g-text g-text_variant_body-1" | ||
> | ||
Hello World! | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected html if passed props what converted to classNames and styles 1`] = ` | ||
<div> | ||
<span | ||
class="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 html if qa attr passed and variant changed 1`] = ` | ||
<div> | ||
<span | ||
class="g-text g-text_variant_caption-1" | ||
data-qa="test" | ||
> | ||
Hello World! | ||
</span> | ||
</div> | ||
`; | ||
|
||
exports[`Text should return expected html with another component substitution 1`] = ` | ||
<div> | ||
<button | ||
class="g-button g-button_view_action g-button_size_m g-button_pin_round-round g-text g-text_variant_body-1" | ||
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