1- import { mount } from 'enzyme' ;
21import React from 'react' ;
2+ import { render , screen , within , cleanup } from '@testing-library/react' ;
33import FeatureBasedEnrollmentCard from './FeatureBasedEnrollmentCard' ;
44import {
55 fbeDurationConfigEnabled ,
@@ -9,77 +9,79 @@ import {
99} from './data/test/featureBasedEnrollment' ;
1010
1111describe ( 'Feature Based Enrollment Card Component' , ( ) => {
12- let wrapper ;
12+ afterEach ( cleanup ) ;
1313
14- afterEach ( ( ) => {
15- wrapper . unmount ( ) ;
16- } ) ;
14+ describe ( 'Gating Config Enabled' , ( ) => {
15+ const title = 'Gating Config Enabled' ;
16+
17+ it ( 'Gating Config Enabled' , ( ) => {
18+ render ( < FeatureBasedEnrollmentCard title = "Gating Config Enabled" fbeData = { fbeGatingConfigEnabled } /> ) ;
1719
18- describe ( 'Gating config' , ( ) => {
19- const title = 'Gating Config' ;
20+ expect ( screen . getByText ( 'Gating Config Enabled' ) ) . toBeInTheDocument ( ) ;
2021
21- it ( 'Gating config enabled' , ( ) => {
22- wrapper = mount ( < FeatureBasedEnrollmentCard title = { title } fbeData = { fbeGatingConfigEnabled } /> ) ;
23- const header = wrapper . find ( '.card-title' ) ;
24- const dataTable = wrapper . find ( 'table.fbe-table tr' ) ;
25- const dateRow = dataTable . at ( 0 ) ;
26- const reasonRow = dataTable . at ( 1 ) ;
22+ const rows = screen . getAllByRole ( 'row' ) ;
23+ const dateRow = within ( rows [ 0 ] ) ;
24+ const reasonRow = within ( rows [ 1 ] ) ;
2725
28- expect ( header . text ( ) ) . toEqual ( 'Gating Config Enabled' ) ;
29- expect ( dateRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Enabled As Of' ) ;
30- expect ( dateRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Jan 1, 2020 12:00 AM' ) ;
26+ expect ( dateRow . getByText ( 'Enabled As Of' ) ) . toBeInTheDocument ( ) ;
27+ expect ( dateRow . getByText ( 'Jan 1, 2020 12:00 AM' ) ) . toBeInTheDocument ( ) ;
3128
32- expect ( reasonRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Reason' ) ;
33- expect ( reasonRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Site' ) ;
29+ expect ( reasonRow . getByText ( 'Reason' ) ) . toBeInTheDocument ( ) ;
30+ expect ( reasonRow . getByText ( 'Site' ) ) . toBeInTheDocument ( ) ;
3431 } ) ;
3532
36- it ( 'Gating config disabled' , ( ) => {
37- wrapper = mount ( < FeatureBasedEnrollmentCard title = { title } fbeData = { fbeGatingConfigDisabled } /> ) ;
38- const header = wrapper . find ( '.card-title' ) ;
39- const dataTable = wrapper . find ( 'table.fbe-table tr' ) ;
40- const dateRow = dataTable . at ( 0 ) ;
41- const reasonRow = dataTable . at ( 1 ) ;
33+ it ( "Gating config disabled" , ( ) => {
34+ render ( < FeatureBasedEnrollmentCard title = "Gating config disabled" fbeData = { fbeGatingConfigDisabled } /> ) ;
35+
36+ expect ( screen . getByText ( "Gating config disabled" ) ) . toBeInTheDocument ( ) ;
4237
43- expect ( header . text ( ) ) . toEqual ( 'Gating Config Disabled ') ;
44- expect ( dateRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Enabled As Of' ) ;
45- expect ( dateRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'N/A' ) ;
38+ const rows = screen . getAllByRole ( 'row ') ;
39+ const dateRow = within ( rows [ 0 ] ) ;
40+ const reasonRow = within ( rows [ 1 ] ) ;
4641
47- expect ( reasonRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Reason' ) ;
48- expect ( reasonRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( '' ) ;
42+ expect ( dateRow . getByText ( 'Enabled As Of' ) ) . toBeInTheDocument ( ) ;
43+ expect ( dateRow . getByText ( 'N/A' ) ) . toBeInTheDocument ( ) ;
44+
45+ expect ( reasonRow . getByText ( 'Reason' ) ) . toBeInTheDocument ( ) ;
46+ expect ( reasonRow . queryByText ( 'Site' ) ) . not . toBeInTheDocument ( ) ;
4947 } ) ;
5048 } ) ;
5149
52- describe ( 'Duration config ' , ( ) => {
53- const title = 'Duration Config' ;
50+ describe ( 'Duration Config Enabled ' , ( ) => {
51+ const title = 'Duration Config Enabled ' ;
5452
5553 it ( 'Duration config enabled' , ( ) => {
56- wrapper = mount ( < FeatureBasedEnrollmentCard title = { title } fbeData = { fbeDurationConfigEnabled } /> ) ;
57- const header = wrapper . find ( '.card-title' ) ;
58- const dataTable = wrapper . find ( 'table.fbe-table tr' ) ;
59- const dateRow = dataTable . at ( 0 ) ;
60- const reasonRow = dataTable . at ( 1 ) ;
61-
62- expect ( header . text ( ) ) . toEqual ( 'Duration Config Enabled' ) ;
63- expect ( dateRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Enabled As Of' ) ;
64- expect ( dateRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Feb 1, 2020 12:00 AM' ) ;
65-
66- expect ( reasonRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Reason' ) ;
67- expect ( reasonRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Site Config' ) ;
54+ render ( < FeatureBasedEnrollmentCard title = "Duration Config Enabled" fbeData = { fbeDurationConfigEnabled } /> ) ;
55+
56+ expect ( screen . getByText ( 'Duration Config Enabled' ) ) . toBeInTheDocument ( ) ;
57+
58+ const rows = screen . getAllByRole ( 'row' ) ;
59+ const dateRow = within ( rows [ 0 ] ) ;
60+ const reasonRow = within ( rows [ 1 ] ) ;
61+
62+ expect ( dateRow . getByText ( 'Enabled As Of' ) ) . toBeInTheDocument ( ) ;
63+ expect ( dateRow . getByText ( 'Feb 1, 2020 12:00 AM' ) ) . toBeInTheDocument ( ) ;
64+
65+ expect ( reasonRow . getByText ( 'Reason' ) ) . toBeInTheDocument ( ) ;
66+ expect ( reasonRow . getByText ( 'Site Config' ) ) . toBeInTheDocument ( ) ;
6867 } ) ;
6968
70- it ( 'Duration config disabled' , ( ) => {
71- wrapper = mount ( < FeatureBasedEnrollmentCard title = { title } fbeData = { fbeDurationConfigDisabled } /> ) ;
72- const header = wrapper . find ( '.card-title' ) ;
73- const dataTable = wrapper . find ( 'table.fbe-table tr' ) ;
74- const dateRow = dataTable . at ( 0 ) ;
75- const reasonRow = dataTable . at ( 1 ) ;
69+
70+
71+ it ( 'Duration Config Disabled' , ( ) => {
72+ render ( < FeatureBasedEnrollmentCard title = "Duration Config Disabled" fbeData = { fbeDurationConfigDisabled } /> ) ;
73+
74+ expect ( screen . getByText ( 'Duration Config Disabled' ) ) . toBeInTheDocument ( ) ;
75+
76+ const rows = screen . getAllByRole ( 'row' ) ;
77+ const dateRow = within ( rows [ 0 ] ) ;
78+ const reasonRow = within ( rows [ 1 ] ) ;
7679
77- expect ( header . text ( ) ) . toEqual ( 'Duration Config Disabled' ) ;
78- expect ( dateRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Enabled As Of' ) ;
79- expect ( dateRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( 'N/A' ) ;
80+ expect ( dateRow . getByText ( 'Enabled As Of' ) ) . toBeInTheDocument ( ) ;
81+ expect ( dateRow . getByText ( 'N/A' ) ) . toBeInTheDocument ( ) ;
8082
81- expect ( reasonRow . find ( 'th' ) . at ( 0 ) . text ( ) ) . toEqual ( 'Reason' ) ;
82- expect ( reasonRow . find ( 'td' ) . at ( 0 ) . text ( ) ) . toEqual ( '' ) ;
83+ expect ( reasonRow . getByText ( 'Reason' ) ) . toBeInTheDocument ( ) ;
84+ expect ( reasonRow . queryByText ( 'Site Config' ) ) . not . toBeInTheDocument ( ) ;
8385 } ) ;
8486 } ) ;
85- } ) ;
87+ } ) ;
0 commit comments