1
- import { test } from "@chromatic-com/playwright"
1
+ import { expect , takeSnapshot , test } from "@chromatic-com/playwright"
2
+ import { Page } from "@playwright/test"
3
+
4
+ import { breakpointAsNumber } from "@/lib/utils/screen"
5
+
6
+ import { DEFAULT_LOCALE } from "@/lib/constants"
2
7
3
8
import { testData } from "./fixtures/testData"
4
9
import { HomePage } from "./pages/HomePage"
10
+ import { waitForPageReady } from "./utils/testHelpers"
5
11
6
12
test . describe ( "Global" , ( ) => {
7
13
test . describe ( "Error Handling" , ( ) => {
@@ -26,6 +32,83 @@ test.describe("Global", () => {
26
32
} )
27
33
28
34
test . describe ( "Internationalization" , ( ) => {
29
- // TODO: Add internationalization tests. Part of #15663
35
+ let homePage : HomePage
36
+
37
+ test . beforeEach ( async ( { page } ) => {
38
+ homePage = new HomePage ( page )
39
+ await homePage . goto ( )
40
+ await waitForPageReady ( page )
41
+ } )
42
+
43
+ async function switchToChinese ( page : Page , homePage : HomePage ) {
44
+ await homePage . switchToLanguage ( "zh" , / ^ 简 体 中 文 C h i n e s e / i)
45
+ await expect ( page ) . toHaveURL ( / \/ z h ( \/ | $ ) / )
46
+ await expect (
47
+ page . getByRole ( "heading" , { level : 1 , name : / 以 太 坊 / i } )
48
+ ) . toBeVisible ( )
49
+ }
50
+
51
+ test ( "switches to Chinese (desktop)" , async ( { page } ) => {
52
+ const isMobile = await homePage . isMobileViewport ( )
53
+ test . skip ( isMobile , "This test is for desktop viewports only" )
54
+
55
+ await expect ( page ) . toHaveURL ( `/${ DEFAULT_LOCALE } /` )
56
+ await homePage . openLanguagePickerDesktop ( )
57
+ await switchToChinese ( page , homePage )
58
+ } )
59
+
60
+ test ( "switches to Chinese (mobile)" , async ( { page } ) => {
61
+ await page . setViewportSize ( { width : breakpointAsNumber . sm , height : 800 } )
62
+ const isMobile = await homePage . isMobileViewport ( )
63
+ test . skip ( ! isMobile , "This test is for mobile viewports only" )
64
+
65
+ await expect ( page ) . toHaveURL ( `/${ DEFAULT_LOCALE } /` )
66
+ await homePage . openLanguagePickerMobile ( )
67
+ await switchToChinese ( page , homePage )
68
+ } )
69
+ } )
70
+
71
+ test . describe ( "RTL Support" , ( ) => {
72
+ let homePage : HomePage
73
+
74
+ test . beforeEach ( async ( { page } ) => {
75
+ homePage = new HomePage ( page )
76
+ } )
77
+
78
+ async function switchToArabic ( page : Page , homePage : HomePage ) {
79
+ await homePage . switchToLanguage ( "ar" , / ^ ا ل ع ر ب ي ة A r a b i c / i)
80
+ await expect ( page ) . toHaveURL ( / \/ a r ( \/ | $ ) / )
81
+ await expect (
82
+ page . getByRole ( "heading" , { level : 1 , name : / إ ي ث ر ي و م / i } )
83
+ ) . toBeVisible ( )
84
+ }
85
+
86
+ test ( "home page RTL visual snapshot" , async ( { page } , testInfo ) => {
87
+ await page . goto ( "/ar" )
88
+ await waitForPageReady ( page )
89
+ await takeSnapshot ( page , "home-arabic-rtl" , testInfo )
90
+ } )
91
+
92
+ test ( "nav flips logo and search button when switching to RTL via language picker" , async ( {
93
+ page,
94
+ } ) => {
95
+ await homePage . goto ( )
96
+ await waitForPageReady ( page )
97
+
98
+ await expect ( page ) . toHaveURL ( `/${ DEFAULT_LOCALE } /` )
99
+
100
+ await homePage . openLanguagePickerDesktop ( )
101
+ await switchToArabic ( page , homePage )
102
+
103
+ await expect ( page ) . toHaveURL ( / \/ a r ( \/ | $ ) / )
104
+
105
+ const logo = page . getByTestId ( "nav-logo" )
106
+ const searchBtn = page . getByTestId ( "search-input-button" )
107
+ const logoBox = await logo . boundingBox ( )
108
+ const searchBox = await searchBtn . boundingBox ( )
109
+ expect ( logoBox ) . not . toBeNull ( )
110
+ expect ( searchBox ) . not . toBeNull ( )
111
+ expect ( logoBox ! . x ) . toBeGreaterThan ( searchBox ! . x )
112
+ } )
30
113
} )
31
114
} )
0 commit comments