alessandro trinca tornidor commited on
Commit
ef61044
·
1 Parent(s): aa2c02d

test: finish refactoring the test cases handling also mobile cases

Browse files
static/playwright.config.ts CHANGED
@@ -49,7 +49,6 @@ export default defineConfig({
49
  // { name: 'setup_classic_lite.koboldai.net', testMatch: 'setup-classic-lite.koboldai.net.ts' },
50
  {
51
  name: 'chromium',
52
- grep: /test-classic-desktop/,
53
  use: {
54
  ...devices['Desktop Chrome'],
55
  viewport: { width: 1600, height: 1200 },
@@ -57,7 +56,6 @@ export default defineConfig({
57
  },
58
  {
59
  name: 'firefox',
60
- grep: /test-classic-desktop/,
61
  use: {
62
  ...devices['Desktop Firefox'],
63
  viewport: { width: 1600, height: 1200 },
@@ -65,75 +63,74 @@ export default defineConfig({
65
  },
66
  {
67
  name: 'webkit',
68
- grep: /test-classic-desktop/,
69
  use: {
70
  ...devices['Desktop Safari'],
71
  viewport: { width: 1600, height: 1200 },
72
  },
73
  },
74
  {
75
- name: 'responsive',
76
- grep: /test-classic-responsive/,
77
  use: {
78
  ...devices['Desktop Chrome'],
 
 
 
 
 
 
 
 
79
  }
80
  },
81
 
82
- // Test against mobile viewports.
83
  {
84
  name: 'MobileChrome',
85
- grep: /test-classic-mobile-pixel/,
86
  use: { ...devices['Pixel 7'] },
87
  },
 
 
 
 
88
  {
89
  name: 'MobileSafari',
90
- grep: /test-classic-mobile-iphone/,
91
  use: { ...devices['iPhone 13'] },
92
  },
93
  {
94
- name: 'MobileSafari',
95
- grep: /test-classic-landscape-mobile-iphone/,
96
  use: { ...devices['iPhone 13 landscape'] },
97
  },
98
 
99
  {
100
  name: 'iPad (gen 7)',
101
- grep: /test-classic-ipad-seven/,
102
  use: { ...devices['iPad (gen 7)'] }
103
  },
104
  {
105
  name: 'iPad (gen 7) landscape',
106
- grep: /test-classic-landscape-ipad-seven/,
107
  use: { ...devices['iPad (gen 7) landscape'] }
108
  },
109
  {
110
  name: 'iPad (gen 11)',
111
- grep: /test-classic-ipad-eleven/,
112
  use: { ...devices['iPad (gen 11)'] }
113
  },
114
  {
115
  name: 'iPad (gen 11) landscape',
116
- grep: /test-classic-landscape-ipad-eleven/,
117
  use: { ...devices['iPad (gen 11) landscape'] }
118
  },
119
  {
120
  name: 'iPad Mini',
121
- grep: /test-classic-ipad-mini/,
122
  use: { ...devices['iPad Mini'] }
123
  },
124
  {
125
  name: 'iPad Mini landscape',
126
- grep: /test-classic-landscape-ipad-mini/,
127
  use: { ...devices['iPad Mini landscape'] }
128
  },
129
  {
130
  name: 'iPad Pro 11',
131
- grep: /test-classic-ipad-pro/,
132
  use: { ...devices['iPad Pro 11'] }
133
  },
134
  {
135
  name: 'iPad Pro 11 landscape',
136
- grep: /test-classic-landscape-ipad-pro/,
137
  use: { ...devices['iPad Pro 11 landscape'] }
138
  }
139
  /*
 
49
  // { name: 'setup_classic_lite.koboldai.net', testMatch: 'setup-classic-lite.koboldai.net.ts' },
50
  {
51
  name: 'chromium',
 
52
  use: {
53
  ...devices['Desktop Chrome'],
54
  viewport: { width: 1600, height: 1200 },
 
56
  },
57
  {
58
  name: 'firefox',
 
59
  use: {
60
  ...devices['Desktop Firefox'],
61
  viewport: { width: 1600, height: 1200 },
 
63
  },
64
  {
65
  name: 'webkit',
 
66
  use: {
67
  ...devices['Desktop Safari'],
68
  viewport: { width: 1600, height: 1200 },
69
  },
70
  },
71
  {
72
+ name: 'responsivePortrait',
 
73
  use: {
74
  ...devices['Desktop Chrome'],
75
+ viewport: { width: 600, height: 1260 },
76
+ }
77
+ },
78
+ {
79
+ name: 'responsiveLandscape',
80
+ use: {
81
+ ...devices['Desktop Chrome'],
82
+ viewport: { width: 2000, height: 600 },
83
  }
84
  },
85
 
86
+ // Test against mobile viewports.
87
  {
88
  name: 'MobileChrome',
 
89
  use: { ...devices['Pixel 7'] },
90
  },
91
+ {
92
+ name: 'MobileChromeLandscape',
93
+ use: { ...devices['Pixel 7 landscape'] },
94
+ },
95
  {
96
  name: 'MobileSafari',
 
97
  use: { ...devices['iPhone 13'] },
98
  },
99
  {
100
+ name: 'MobileSafariLandscape',
 
101
  use: { ...devices['iPhone 13 landscape'] },
102
  },
103
 
104
  {
105
  name: 'iPad (gen 7)',
 
106
  use: { ...devices['iPad (gen 7)'] }
107
  },
108
  {
109
  name: 'iPad (gen 7) landscape',
 
110
  use: { ...devices['iPad (gen 7) landscape'] }
111
  },
112
  {
113
  name: 'iPad (gen 11)',
 
114
  use: { ...devices['iPad (gen 11)'] }
115
  },
116
  {
117
  name: 'iPad (gen 11) landscape',
 
118
  use: { ...devices['iPad (gen 11) landscape'] }
119
  },
120
  {
121
  name: 'iPad Mini',
 
122
  use: { ...devices['iPad Mini'] }
123
  },
124
  {
125
  name: 'iPad Mini landscape',
 
126
  use: { ...devices['iPad Mini landscape'] }
127
  },
128
  {
129
  name: 'iPad Pro 11',
 
130
  use: { ...devices['iPad Pro 11'] }
131
  },
132
  {
133
  name: 'iPad Pro 11 landscape',
 
134
  use: { ...devices['iPad Pro 11 landscape'] }
135
  }
136
  /*
static/tests/{test-classic-desktop-0-lite.koboldai.net.spec.ts → test-classic-0-lite.koboldai.net.spec.ts} RENAMED
@@ -11,12 +11,16 @@ const expectedStringArray = [
11
  "Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache.",
12
  `"Shouldn'ta lost me temper," he said ruefully, "but it didn't work anyway. Meant ter turn him into a pig, but I suppose he was so much like a pig anyway there wasn't much left ter do."`
13
  ]
 
 
 
 
14
 
15
  test('test My Ghost Writer, desktop: navigate between the list/tables containing the stemming; check for sentences sorrounding the clicked words/0', async ({ page }: { page: Page }, workerInfo: TestInfo) => {
16
  const projectName = await initTest(page, workerInfo, testStoryJsonTxt)
17
  await fillInputFieldWithString(page, '');
18
  await page.waitForTimeout(200)
19
-
20
  await expect(page.getByLabel('wordsearch_candidates_count')).toMatchAriaSnapshot(`- text: /2\\d\\d\\d\\d result\\(s\\) found/`);
21
  const wordsearch_results = page.getByLabel("wordsearch_results")
22
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-0-${projectName}.txt` });
@@ -26,7 +30,7 @@ test('test My Ghost Writer, desktop: navigate between the list/tables containing
26
  await page.waitForTimeout(200)
27
  await expect(page.getByLabel('wordsearch_results')).toMatchAriaSnapshot(`- text: /40\\d results/`);
28
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-1-${projectName}.txt` });
29
-
30
  console.log("end!")
31
  await page.close()
32
  })
@@ -35,21 +39,33 @@ test('test My Ghost Writer, desktop: navigate between the list/tables containing
35
  const projectName = await initTest(page, workerInfo, testStoryJsonTxt)
36
  await fillInputFieldWithString(page, '');
37
  await page.waitForTimeout(200)
38
- await expect(page.getByLabel('wordsearch_results')).not.toMatchAriaSnapshot(`- text: /40\\d results/`);
39
- await page.getByLabel('id-div-candidate-1-nth').click();
40
- await page.waitForTimeout(200)
41
- ///
42
- await scrollToBottomById(page, "gametext")
43
- await scrollToTopById(page, "wordsearch_results")
44
- const id0 = 'id-div-1-range-0-nth'
45
- let clickedElement = page.getByLabel(id0)
46
- await expect(clickedElement).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-2-${projectName}.txt` });
47
- await expect(clickedElement).not.toHaveClass("background-border-clicked")
48
- await clickedElement.click();
49
- await page.waitForTimeout(200)
50
- await expect(clickedElement).toHaveClass("background-border-clicked")
51
- console.log(`clicked on id ${id0}, check for the expected string...`)
52
- await expectVisibleTextWithWalker(page, "gametext", expectedStringArray[0])
 
 
 
 
 
 
 
 
 
 
 
 
53
  console.log("end!")
54
  await page.close()
55
  })
@@ -88,14 +104,11 @@ test('test My Ghost Writer, desktop: sort by frequency and alphabetically', asyn
88
  await page.locator('#wordsearch_sort').selectOption('1');
89
  await page.getByRole('button', { name: 'id-perform-wordsearch' }).click();
90
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-4-${projectName}.txt` });
91
-
92
- await page.locator('#wordsearch_sort').selectOption('0');
93
- await page.getByRole('button', { name: 'id-perform-wordsearch' }).click();
94
- await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-5-${projectName}.txt` });
95
 
 
96
  await page.getByRole('button', { name: 'id-perform-wordsearch' }).click();
97
  await expect(page.getByLabel('wordsearch_candidates_count')).toMatchAriaSnapshot(`- text: /2\\d\\d\\d\\d result\\(s\\) found/`);
98
- await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-6-${projectName}.txt` });
99
 
100
  console.log("end!")
101
  await page.close()
 
11
  "Mr. Dursley was the director of a firm called Grunnings, which made drills. He was a big, beefy man with hardly any neck, although he did have a very large mustache.",
12
  `"Shouldn'ta lost me temper," he said ruefully, "but it didn't work anyway. Meant ter turn him into a pig, but I suppose he was so much like a pig anyway there wasn't much left ter do."`
13
  ]
14
+ const editState = [
15
+ { state: "read-only", expectedFirstAriaSnapshot: `- text: /40\\d results/` },
16
+ { state: "editable", expectedFirstAriaSnapshot: `- text: /40\\d results/` }
17
+ ]
18
 
19
  test('test My Ghost Writer, desktop: navigate between the list/tables containing the stemming; check for sentences sorrounding the clicked words/0', async ({ page }: { page: Page }, workerInfo: TestInfo) => {
20
  const projectName = await initTest(page, workerInfo, testStoryJsonTxt)
21
  await fillInputFieldWithString(page, '');
22
  await page.waitForTimeout(200)
23
+
24
  await expect(page.getByLabel('wordsearch_candidates_count')).toMatchAriaSnapshot(`- text: /2\\d\\d\\d\\d result\\(s\\) found/`);
25
  const wordsearch_results = page.getByLabel("wordsearch_results")
26
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-0-${projectName}.txt` });
 
30
  await page.waitForTimeout(200)
31
  await expect(page.getByLabel('wordsearch_results')).toMatchAriaSnapshot(`- text: /40\\d results/`);
32
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-1-${projectName}.txt` });
33
+
34
  console.log("end!")
35
  await page.close()
36
  })
 
39
  const projectName = await initTest(page, workerInfo, testStoryJsonTxt)
40
  await fillInputFieldWithString(page, '');
41
  await page.waitForTimeout(200)
42
+ for (let { state, expectedFirstAriaSnapshot } of Object.values(editState)) {
43
+ console.log(state, expectedFirstAriaSnapshot)
44
+ if (state === "editable") {
45
+ const toggleEditing = page.getByRole('checkbox', { name: 'Allow Editing' })
46
+ await toggleEditing.click()
47
+ await page.waitForTimeout(300)
48
+ await expect(toggleEditing).toBeChecked()
49
+ }
50
+
51
+ await expect(page.getByLabel('wordsearch_results')).not.toMatchAriaSnapshot(expectedFirstAriaSnapshot);
52
+ await page.getByLabel('id-div-candidate-1-nth').click();
53
+ await page.waitForTimeout(200)
54
+ await expect(page.getByLabel('wordsearch_results')).toMatchAriaSnapshot(expectedFirstAriaSnapshot);
55
+ ///
56
+ await scrollToBottomById(page, "gametext")
57
+ await scrollToTopById(page, "wordsearch_results")
58
+ const id0 = 'id-div-1-range-0-nth'
59
+ let clickedElement = page.getByLabel(id0)
60
+ await expect(clickedElement).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-2-${projectName}-${state}.txt` });
61
+ await expect(clickedElement).not.toHaveClass("background-border-clicked")
62
+ await clickedElement.click();
63
+ await page.waitForTimeout(200)
64
+ await expect(clickedElement).toHaveClass("background-border-clicked")
65
+ console.log(`clicked on id ${id0}, check for the expected string...`)
66
+ await expectVisibleTextWithWalker(page, "gametext", expectedStringArray[0])
67
+ console.log(`${projectName}, state ${state} done.`)
68
+ }
69
  console.log("end!")
70
  await page.close()
71
  })
 
104
  await page.locator('#wordsearch_sort').selectOption('1');
105
  await page.getByRole('button', { name: 'id-perform-wordsearch' }).click();
106
  await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-4-${projectName}.txt` });
 
 
 
 
107
 
108
+ await page.locator('#wordsearch_sort').selectOption('0');
109
  await page.getByRole('button', { name: 'id-perform-wordsearch' }).click();
110
  await expect(page.getByLabel('wordsearch_candidates_count')).toMatchAriaSnapshot(`- text: /2\\d\\d\\d\\d result\\(s\\) found/`);
111
+ await expect(wordsearch_results).toMatchAriaSnapshot({ name: `test-classic-desktop-0-wordsearch_results-5-${projectName}.txt` });
112
 
113
  console.log("end!")
114
  await page.close()
static/tests/{test-classic-desktop-1-lite.koboldai.net.spec.ts → test-classic-1-lite.koboldai.net.spec.ts} RENAMED
File without changes
static/tests/test-helper.ts CHANGED
@@ -346,9 +346,22 @@ export async function initTest(page: Page, workerInfo: TestInfo, filepath: strin
346
  // 2. Activate the required UI mode (e.g., switch to classic or advanced UI)
347
  await page.getByRole('button', { name: 'Set UI' }).click();
348
 
 
 
 
 
 
 
 
349
  // 3. Upload a saved JSON story file to provide long text content for analysis
350
  await uploadFileWithPageAndFilepath(page, filepath)
351
  // activate wordsearch
 
 
 
 
 
 
352
  await page.getByRole('link', { name: 'Settings' }).click();
353
  await page.getByRole('checkbox', { name: 'wordsearch_toggle' }).check();
354
  await page.getByRole('button', { name: 'OK' }).click();
 
346
  // 2. Activate the required UI mode (e.g., switch to classic or advanced UI)
347
  await page.getByRole('button', { name: 'Set UI' }).click();
348
 
349
+ const mobileButtonGlobalMenu = page.getByRole('button', { name: 'id-mobile-main-menu-options' })
350
+ if (await mobileButtonGlobalMenu.isVisible({timeout: 500})) {
351
+ await mobileButtonGlobalMenu.click();
352
+ await page.waitForTimeout(200)
353
+ console.log("#found mobile button for global menu, open it to prepare json story upload!")
354
+ }
355
+
356
  // 3. Upload a saved JSON story file to provide long text content for analysis
357
  await uploadFileWithPageAndFilepath(page, filepath)
358
  // activate wordsearch
359
+
360
+ if (await mobileButtonGlobalMenu.isVisible({timeout: 500})) {
361
+ await mobileButtonGlobalMenu.click();
362
+ await page.waitForTimeout(200)
363
+ console.log("#found mobile button for global menu, open it to toggle word search!")
364
+ }
365
  await page.getByRole('link', { name: 'Settings' }).click();
366
  await page.getByRole('checkbox', { name: 'wordsearch_toggle' }).check();
367
  await page.getByRole('button', { name: 'OK' }).click();