1
1
import * as React from 'react' ;
2
- import { fireEvent , render , screen , waitFor } from '@testing-library/react' ;
3
- import { Basic } from './LocalesMenuButton.stories' ;
2
+ import {
3
+ fireEvent ,
4
+ render ,
5
+ screen ,
6
+ waitFor ,
7
+ within ,
8
+ } from '@testing-library/react' ;
9
+ import { Basic , FullApp } from './LocalesMenuButton.stories' ;
4
10
5
11
describe ( 'LocalesMenuButton' , ( ) => {
6
12
it ( 'should allow to change language' , async ( ) => {
@@ -16,5 +22,30 @@ describe('LocalesMenuButton', () => {
16
22
await waitFor ( ( ) => {
17
23
expect ( screen . queryByText ( 'Tableau de bord' ) ) . not . toBeNull ( ) ;
18
24
} ) ;
25
+
26
+ fireEvent . click ( screen . getAllByText ( 'Français' ) [ 0 ] ) ;
27
+ fireEvent . click ( screen . getByText ( 'English' ) ) ;
28
+ await waitFor ( ( ) => {
29
+ expect ( screen . queryByText ( 'Dashboard' ) ) . not . toBeNull ( ) ;
30
+ } ) ;
31
+ } ) ;
32
+
33
+ it ( 'should not make the title disappear' , async ( ) => {
34
+ const { container } = render ( < FullApp /> ) ;
35
+
36
+ await screen . findByText ( 'War and Peace' ) ;
37
+ let title = container . querySelector (
38
+ '#react-admin-title'
39
+ ) as HTMLElement ;
40
+ expect ( within ( title ) . queryByText ( 'Books' ) ) . not . toBeNull ( ) ;
41
+
42
+ fireEvent . click ( screen . getAllByText ( 'English' ) [ 0 ] ) ;
43
+ expect ( screen . queryAllByText ( 'English' ) . length ) . toEqual ( 2 ) ;
44
+ expect ( screen . queryByText ( 'Français' ) ) . not . toBeNull ( ) ;
45
+ fireEvent . click ( screen . getByText ( 'Français' ) ) ;
46
+
47
+ await screen . findAllByText ( 'Livres' ) ;
48
+ title = container . querySelector ( '#react-admin-title' ) as HTMLElement ;
49
+ expect ( within ( title ) . queryByText ( 'Livres' ) ) . not . toBeNull ( ) ;
19
50
} ) ;
20
51
} ) ;
0 commit comments