1- import { render , screen , fireEvent , waitFor } from '@testing-library/react'
1+ import { render , screen , waitFor } from '@testing-library/react'
22import { CSSTable } from '../CSSTable'
3+ import userEvent from '@testing-library/user-event'
34
45jest . mock ( '@patternfly/react-tokens/dist/esm/componentIndex' , ( ) => ( {
56 test : {
@@ -24,114 +25,114 @@ jest.mock('@patternfly/react-tokens/dist/esm/componentIndex', () => ({
2425 'pf-v6-empty' : { } ,
2526} ) )
2627
27- describe ( '<CSSTable />' , ( ) => {
28- it ( 'renders without crashing' , ( ) => {
29- render ( < CSSTable cssPrefix = "pf-v6-test" /> )
30- expect (
31- screen . getByRole ( 'grid' , {
32- name : / C S S V a r i a b l e s p r e f i x e d w i t h p f - v 6 - t e s t / i,
33- } ) ,
34- ) . toBeInTheDocument ( )
35- } )
28+ it ( 'renders without crashing' , ( ) => {
29+ render ( < CSSTable cssPrefix = "pf-v6-test" /> )
30+ expect (
31+ screen . getByRole ( 'grid' , {
32+ name : / C S S V a r i a b l e s p r e f i x e d w i t h p f - v 6 - t e s t / i,
33+ } ) ,
34+ ) . toBeInTheDocument ( )
35+ } )
3636
37- it ( 'renders the correct table headers when hideSelectorColumn is false (default)' , ( ) => {
38- render ( < CSSTable cssPrefix = "pf-v6-test" /> )
39- expect ( screen . getByText ( 'Selector' ) ) . toBeInTheDocument ( )
40- expect ( screen . getByText ( 'Variable' ) ) . toBeInTheDocument ( )
41- expect ( screen . getByText ( 'Value' ) ) . toBeInTheDocument ( )
42- } )
37+ it ( 'renders the correct table headers when hideSelectorColumn is false (default)' , ( ) => {
38+ render ( < CSSTable cssPrefix = "pf-v6-test" /> )
39+ expect ( screen . getByText ( 'Selector' ) ) . toBeInTheDocument ( )
40+ expect ( screen . getByText ( 'Variable' ) ) . toBeInTheDocument ( )
41+ expect ( screen . getByText ( 'Value' ) ) . toBeInTheDocument ( )
42+ } )
4343
44- it ( 'renders the correct table headers when hideSelectorColumn is true' , ( ) => {
45- render ( < CSSTable cssPrefix = "pf-v6-test" hideSelectorColumn /> )
46- expect ( screen . queryByText ( 'Selector' ) ) . not . toBeInTheDocument ( )
47- expect ( screen . getByText ( 'Variable' ) ) . toBeInTheDocument ( )
48- expect ( screen . getByText ( 'Value' ) ) . toBeInTheDocument ( )
49- } )
44+ it ( 'renders the correct table headers when hideSelectorColumn is true' , ( ) => {
45+ render ( < CSSTable cssPrefix = "pf-v6-test" hideSelectorColumn /> )
46+ expect ( screen . queryByText ( 'Selector' ) ) . not . toBeInTheDocument ( )
47+ expect ( screen . getByText ( 'Variable' ) ) . toBeInTheDocument ( )
48+ expect ( screen . getByText ( 'Value' ) ) . toBeInTheDocument ( )
49+ } )
5050
51- it ( 'renders the correct data rows' , ( ) => {
52- render ( < CSSTable cssPrefix = "pf-v6-test" /> )
53- expect (
54- screen . getByRole ( 'row' , {
55- name : '.test-selector test-property test-value' ,
56- } ) ,
57- ) . toBeInTheDocument ( )
58- expect (
59- screen . getByRole ( 'row' , {
60- name : '.test-selector another-property (In light theme) #123456' ,
61- } ) ,
62- ) . toBeInTheDocument ( )
63- expect (
64- screen . getByRole ( 'row' , {
65- name : 'Details .another-selector list-property list-item-1' ,
66- } ) ,
67- ) . toBeInTheDocument ( )
68- } )
51+ it ( 'renders the correct data rows' , ( ) => {
52+ render ( < CSSTable cssPrefix = "pf-v6-test" /> )
53+ expect (
54+ screen . getByRole ( 'row' , {
55+ name : '.test-selector test-property test-value' ,
56+ } ) ,
57+ ) . toBeInTheDocument ( )
58+ expect (
59+ screen . getByRole ( 'row' , {
60+ name : '.test-selector another-property (In light theme) #123456' ,
61+ } ) ,
62+ ) . toBeInTheDocument ( )
63+ expect (
64+ screen . getByRole ( 'row' , {
65+ name : 'Details .another-selector list-property list-item-1' ,
66+ } ) ,
67+ ) . toBeInTheDocument ( )
68+ } )
6969
70- it ( 'renders the "Prefixed with" header when autoLinkHeader is true' , ( ) => {
71- render ( < CSSTable cssPrefix = "pf-v6-test" autoLinkHeader /> )
72- expect (
73- screen . getByRole ( 'heading' , {
74- name : / P r e f i x e d w i t h ' p f - v 6 - t e s t ' / i,
75- level : 3 ,
76- } ) ,
77- ) . toBeInTheDocument ( )
78- } )
70+ it ( 'renders the "Prefixed with" header when autoLinkHeader is true' , ( ) => {
71+ render ( < CSSTable cssPrefix = "pf-v6-test" autoLinkHeader /> )
72+ expect (
73+ screen . getByRole ( 'heading' , {
74+ name : / P r e f i x e d w i t h ' p f - v 6 - t e s t ' / i,
75+ level : 3 ,
76+ } ) ,
77+ ) . toBeInTheDocument ( )
78+ } )
7979
80- it ( 'does not render the "Prefixed with" header when autoLinkHeader is false (default)' , ( ) => {
81- render ( < CSSTable cssPrefix = "pf-v6-test" /> )
82- expect (
83- screen . queryByRole ( 'heading' , {
84- name : / P r e f i x e d w i t h ' p f - v 6 - t e s t ' / i,
85- level : 3 ,
86- } ) ,
87- ) . not . toBeInTheDocument ( )
88- } )
80+ it ( 'does not render the "Prefixed with" header when autoLinkHeader is false (default)' , ( ) => {
81+ render ( < CSSTable cssPrefix = "pf-v6-test" /> )
82+ expect (
83+ screen . queryByRole ( 'heading' , {
84+ name : / P r e f i x e d w i t h ' p f - v 6 - t e s t ' / i,
85+ level : 3 ,
86+ } ) ,
87+ ) . not . toBeInTheDocument ( )
88+ } )
8989
90- it ( 'filters rows based on search input' , async ( ) => {
91- render ( < CSSTable cssPrefix = "pf-v6-test" debounceLength = { 0 } /> )
92- const searchInput = screen . getByPlaceholderText ( 'Filter CSS Variables' )
90+ it ( 'filters rows based on search input' , async ( ) => {
91+ render ( < CSSTable cssPrefix = "pf-v6-test" debounceLength = { 0 } /> )
92+ const searchInput = screen . getByPlaceholderText ( 'Filter CSS Variables' )
9393
94- expect (
95- screen . getByRole ( 'row' , {
96- name : '.test-selector test-property test-value' ,
97- } ) ,
98- ) . toBeInTheDocument ( )
99- expect (
100- screen . getByRole ( 'row' , {
101- name : 'Details .another-selector list-property list-item-1' ,
102- } ) ,
103- ) . toBeInTheDocument ( )
104- fireEvent . change ( searchInput , { target : { value : 'test' } } )
105- await waitFor ( ( ) => {
106- // row doesn't seem to work here for whatever reason
107- expect ( screen . getAllByText ( '.test-selector' ) ) . toHaveLength ( 2 )
108- expect ( screen . getByText ( 'test-property' ) ) . toBeInTheDocument ( )
109- expect ( screen . queryByText ( '.another-selector' ) ) . not . toBeInTheDocument ( )
110- expect ( screen . queryByText ( 'list-property' ) ) . not . toBeInTheDocument ( )
111- } )
94+ expect (
95+ screen . getByRole ( 'row' , {
96+ name : '.test-selector test-property test-value' ,
97+ } ) ,
98+ ) . toBeInTheDocument ( )
99+ expect (
100+ screen . getByRole ( 'row' , {
101+ name : 'Details .another-selector list-property list-item-1' ,
102+ } ) ,
103+ ) . toBeInTheDocument ( )
112104
113- fireEvent . change ( searchInput , { target : { value : 'list' } } )
114- await waitFor ( ( ) => {
115- expect ( screen . queryByText ( '.test-selector' ) ) . not . toBeInTheDocument ( )
116- expect ( screen . queryByText ( ' test-property ') ) . not . toBeInTheDocument ( )
117- expect ( screen . getByText ( '.another-selector ' ) ) . toBeInTheDocument ( )
118- expect ( screen . getAllByText ( 'list-property ') ) . toHaveLength ( 2 )
119- } )
105+ await userEvent . type ( searchInput , 'test' )
106+ await waitFor ( ( ) => {
107+ // row doesn't seem to work here for whatever reason
108+ expect ( screen . getAllByText ( '. test-selector ') ) . toHaveLength ( 2 )
109+ expect ( screen . getByText ( 'test-property ' ) ) . toBeInTheDocument ( )
110+ expect ( screen . queryByText ( '.another-selector ') ) . not . toBeInTheDocument ( )
111+ expect ( screen . queryByText ( 'list-property' ) ) . not . toBeInTheDocument ( )
120112 } )
121113
122- it ( 'handles the case where the cssPrefix does not exist in tokensModule' , ( ) => {
123- render ( < CSSTable cssPrefix = "pf-v6-nonexistent" /> )
124- expect ( screen . queryByRole ( 'grid' ) ) . toBeInTheDocument ( ) // Table should still render, but be empty
114+ await userEvent . clear ( searchInput )
115+ await userEvent . type ( searchInput , 'list' )
116+ await waitFor ( ( ) => {
125117 expect ( screen . queryByText ( '.test-selector' ) ) . not . toBeInTheDocument ( )
118+ expect ( screen . queryByText ( 'test-property' ) ) . not . toBeInTheDocument ( )
119+ expect ( screen . getByText ( '.another-selector' ) ) . toBeInTheDocument ( )
120+ expect ( screen . getAllByText ( 'list-property' ) ) . toHaveLength ( 2 )
126121 } )
122+ } )
127123
128- it ( 'renders correctly when hideSelectorColumn is true and there are rows' , ( ) => {
129- render ( < CSSTable cssPrefix = "pf-v6-test" hideSelectorColumn /> )
130- expect ( screen . queryByText ( '.test-selector' ) ) . not . toBeInTheDocument ( )
131- expect (
132- screen . getByRole ( 'row' , {
133- name : 'test-property' ,
134- } ) ,
135- ) . toBeInTheDocument ( )
136- } )
124+ it ( 'handles the case where the cssPrefix does not exist in tokensModule' , ( ) => {
125+ render ( < CSSTable cssPrefix = "pf-v6-nonexistent" /> )
126+ expect ( screen . queryByRole ( 'grid' ) ) . toBeInTheDocument ( ) // Table should still render, but be empty
127+ expect ( screen . queryByText ( '.test-selector' ) ) . not . toBeInTheDocument ( )
128+ } )
129+
130+ it ( 'renders correctly when hideSelectorColumn is true and there are rows' , ( ) => {
131+ render ( < CSSTable cssPrefix = "pf-v6-test" hideSelectorColumn /> )
132+ expect ( screen . queryByText ( '.test-selector' ) ) . not . toBeInTheDocument ( )
133+ expect (
134+ screen . getByRole ( 'row' , {
135+ name : 'test-property' ,
136+ } ) ,
137+ ) . toBeInTheDocument ( )
137138} )
0 commit comments