11import * as React from 'react' ;
22import { fireEvent , render , screen } from '@testing-library/react' ;
3- import { faker } from '@faker-js/faker' ;
43import fakeRestDataProvider from 'ra-data-fakerest' ;
54
65import {
@@ -23,15 +22,15 @@ describe('<PrevNextButtons />', () => {
2322
2423 it ( 'should render the current record position according to the clicked item in the list' , async ( ) => {
2524 render ( < Basic /> ) ;
26- const tr = await screen . findByText ( 'Deja ' ) ;
25+ const tr = await screen . findByText ( 'first_name_3 ' ) ;
2726 fireEvent . click ( tr ) ;
2827 await screen . findByRole ( 'navigation' ) ;
2928 expect ( screen . getByText ( '4 / 900' ) ) . toBeDefined ( ) ;
3029 } ) ;
3130
3231 it ( 'should render previous button as disabled if there is no previous record' , async ( ) => {
3332 render ( < Basic /> ) ;
34- const tr = await screen . findByText ( 'Maurine ' ) ;
33+ const tr = await screen . findByText ( 'first_name_0 ' ) ;
3534 fireEvent . click ( tr ) ;
3635 await screen . findByRole ( 'navigation' ) ;
3736 const previousButton = screen . getByLabelText ( 'Go to previous page' ) ;
@@ -43,7 +42,7 @@ describe('<PrevNextButtons />', () => {
4342 render ( < Basic /> ) ;
4443 const lastPage = await screen . findByText ( '90' ) ;
4544 fireEvent . click ( lastPage ) ;
46- const tr = await screen . findByText ( 'Maxwell ' ) ;
45+ const tr = await screen . findByText ( 'first_name_899 ' ) ;
4746 fireEvent . click ( tr ) ;
4847 await screen . findByRole ( 'navigation' ) ;
4948 const nextButton = screen . getByLabelText ( 'Go to next page' ) ;
@@ -54,16 +53,17 @@ describe('<PrevNextButtons />', () => {
5453 it ( 'should render a total based on query filter' , async ( ) => {
5554 render ( < WithQueryFilter /> ) ;
5655 const input = await screen . findByLabelText ( 'Search' ) ;
57- fireEvent . change ( input , { target : { value : 'east' } } ) ;
58- const item = await screen . findByText ( '217' ) ;
56+ fireEvent . change ( input , { target : { value : 'city_0' } } ) ;
57+ await screen . findByText ( '1-10 of 50' ) ;
58+ const item = await screen . findByText ( 'first_name_9' ) ;
5959 fireEvent . click ( item ) ;
6060 await screen . findByRole ( 'navigation' ) ;
61- await screen . findByText ( '10 / 57 ' ) ;
61+ await screen . findByText ( '10 / 50 ' ) ;
6262 } ) ;
6363
6464 it ( 'should link to the edit view by default' , async ( ) => {
6565 render ( < Basic /> ) ;
66- const row = await screen . findByText ( 'Deja ' ) ;
66+ const row = await screen . findByText ( 'first_name_0 ' ) ;
6767 fireEvent . click ( row ) ;
6868 fireEvent . click ( await screen . findByLabelText ( 'Edit' ) ) ;
6969 const next = await screen . findByLabelText ( 'Go to next page' ) ;
@@ -90,7 +90,7 @@ describe('<PrevNextButtons />', () => {
9090 describe ( 'linkType' , ( ) => {
9191 it ( 'should link to the show view when linkType is show' , async ( ) => {
9292 render ( < Basic /> ) ;
93- const row = await screen . findByText ( 'Deja ' ) ;
93+ const row = await screen . findByText ( 'first_name_0 ' ) ;
9494 fireEvent . click ( row ) ;
9595 const next = await screen . findByLabelText ( 'Go to next page' ) ;
9696 fireEvent . click ( next ) ;
@@ -102,10 +102,10 @@ describe('<PrevNextButtons />', () => {
102102 describe ( 'filter' , ( ) => {
103103 it ( 'should render a total based on filter' , async ( ) => {
104104 render ( < WithFilter /> ) ;
105- const item = await screen . findByText ( '822 ' ) ;
105+ const item = await screen . findByText ( 'first_name_5 ' ) ;
106106 fireEvent . click ( item ) ;
107107 await screen . findByRole ( 'navigation' ) ;
108- expect ( screen . getByText ( '1 / 5 ' ) ) . toBeDefined ( ) ;
108+ expect ( screen . getByText ( '5 / 50 ' ) ) . toBeDefined ( ) ;
109109 } ) ;
110110 } ) ;
111111
@@ -119,19 +119,16 @@ describe('<PrevNextButtons />', () => {
119119 it ( 'should limit the number of items fetched from the data provider' , async ( ) => {
120120 const data = {
121121 customers : Array . from ( Array ( 900 ) . keys ( ) ) . map ( id => {
122- const first_name = faker . person . firstName ( ) ;
123- const last_name = faker . person . lastName ( ) ;
124- const email = faker . internet . email ( {
125- firstName : first_name ,
126- lastName : last_name ,
127- } ) ;
122+ const first_name = `first_name_${ id } ` ;
123+ const last_name = `last_name_${ id } ` ;
124+ const email = `first_name_${ id } .last_name_${ id } @example.com` ;
128125
129126 return {
130127 id,
131128 first_name,
132129 last_name,
133130 email,
134- city : faker . location . city ( ) ,
131+ city : `city_ ${ id } ` ,
135132 } ;
136133 } ) ,
137134 } ;
@@ -154,49 +151,49 @@ describe('<PrevNextButtons />', () => {
154151 describe ( 'pagination' , ( ) => {
155152 it ( 'should compute the index correctly when opening first record of page 2' , async ( ) => {
156153 render ( < Basic /> ) ;
157- await screen . findByText ( 'Deja ' ) ;
154+ await screen . findByText ( 'first_name_1 ' ) ;
158155 fireEvent . click ( await screen . findByLabelText ( 'Go to page 2' ) ) ;
159- const tr = await screen . findByText ( 'Hamill ' ) ;
156+ const tr = await screen . findByText ( 'first_name_10 ' ) ;
160157 fireEvent . click ( tr ) ;
161158 await screen . findByText ( '11 / 900' ) ;
162159 } ) ;
163160 it ( 'should compute the index correctly when opening second record of page 2' , async ( ) => {
164161 render ( < Basic /> ) ;
165- await screen . findByText ( 'Deja ' ) ;
162+ await screen . findByText ( 'first_name_1 ' ) ;
166163 fireEvent . click ( await screen . findByLabelText ( 'Go to page 2' ) ) ;
167- const tr = await screen . findByText ( 'Kub ' ) ;
164+ const tr = await screen . findByText ( 'first_name_11 ' ) ;
168165 fireEvent . click ( tr ) ;
169166 await screen . findByText ( '12 / 900' ) ;
170167 } ) ;
171168 it ( 'should compute the index correctly when opening last record of page 2' , async ( ) => {
172169 render ( < Basic /> ) ;
173- await screen . findByText ( 'Deja ' ) ;
170+ await screen . findByText ( 'first_name_1 ' ) ;
174171 fireEvent . click ( await screen . findByLabelText ( 'Go to page 2' ) ) ;
175- const tr = await screen . findByText ( 'Langworth ' ) ;
172+ const tr = await screen . findByText ( 'first_name_19 ' ) ;
176173 fireEvent . click ( tr ) ;
177174 await screen . findByText ( '20 / 900' ) ;
178175 } ) ;
179176 it ( 'should compute the index correctly when opening first record of page 3' , async ( ) => {
180177 render ( < Basic /> ) ;
181- await screen . findByText ( 'Deja ' ) ;
178+ await screen . findByText ( 'first_name_1 ' ) ;
182179 fireEvent . click ( await screen . findByLabelText ( 'Go to page 3' ) ) ;
183- const tr = await screen . findByText ( 'Spinka ' ) ;
180+ const tr = await screen . findByText ( 'first_name_20 ' ) ;
184181 fireEvent . click ( tr ) ;
185182 await screen . findByText ( '21 / 900' ) ;
186183 } ) ;
187184 it ( 'should compute the index correctly when opening second record of page 3' , async ( ) => {
188185 render ( < Basic /> ) ;
189- await screen . findByText ( 'Deja ' ) ;
186+ await screen . findByText ( 'first_name_5 ' ) ;
190187 fireEvent . click ( await screen . findByLabelText ( 'Go to page 3' ) ) ;
191- const tr = await screen . findByText ( 'Lowe ' ) ;
188+ const tr = await screen . findByText ( 'first_name_21 ' ) ;
192189 fireEvent . click ( tr ) ;
193190 await screen . findByText ( '22 / 900' ) ;
194191 } ) ;
195192 it ( 'should compute the index correctly when opening last record of page 3' , async ( ) => {
196193 render ( < Basic /> ) ;
197- await screen . findByText ( 'Deja ' ) ;
194+ await screen . findByText ( 'first_name_5 ' ) ;
198195 fireEvent . click ( await screen . findByLabelText ( 'Go to page 3' ) ) ;
199- const tr = await screen . findByText ( 'Grimes ' ) ;
196+ const tr = await screen . findByText ( 'first_name_29 ' ) ;
200197 fireEvent . click ( tr ) ;
201198 await screen . findByText ( '30 / 900' ) ;
202199 } ) ;
0 commit comments