alessandro trinca tornidor commited on
Commit
e9fbce5
·
1 Parent(s): be2d172

test: fix the test-classic-4-lite.koboldai.net.spec.ts

Browse files
static/tests/test-classic-4-lite.koboldai.net.spec.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
  ensureThesaurusPanelClosed,
5
  ensureThesaurusPanelOpen,
6
  fillInputFieldWithString,
 
7
  initTest
8
  } from './test-helper';
9
 
@@ -51,13 +52,8 @@ test(`test My Ghost Writer: backend request - word with no synonyms, then add a
51
  await page.getByRole('button', { name: 'thesaurus-custom-button-internal0' }).click();
52
  // try to submit immediately, we'll get an error because we didn't filled the forms
53
  console.log("#")
54
- await page.getByRole('button', { name: 'thesaurus-custom-submit' }).click();
55
- page.once('dialog', dialog1 => {
56
- const msg1 = dialog1.message()
57
- // expect(msg1).toContain("Please enter a word.")
58
- console.error(`Dialog message: '${msg1}'`); // Dialog message: Please enter a word.
59
- dialog1.dismiss().catch(() => {});
60
- });
61
  await page.waitForTimeout(200)
62
 
63
  await page.getByRole('button', { name: 'thesaurus-custom-cancel' }).click(); // close the thesaurus custom form
@@ -84,17 +80,8 @@ test(`test My Ghost Writer: backend request - word with no synonyms, then add a
84
  await expect(page.getByLabel('thesaurus-custom-form-content')).toMatchAriaSnapshot({ name: `test-classic-4-0-wordsearch_results-2-${projectName}-${state}.txt` });
85
  await page.getByRole('textbox', { name: 'thesaurus-custom-related-words-2nth' }).click();
86
  await page.getByRole('textbox', { name: 'thesaurus-custom-related-words-2nth' }).fill('joyful,happyness,content');
87
- // handle second dialog message
88
- page.once('dialog', dialog2 => {
89
- const msg2 = dialog2.message()
90
- // expect(msg2).toContain("Thesaurus entry added successfully!")
91
- console.error(`Dialog message: '${msg2}'`); // Dialog message: Thesaurus entry added successfully!
92
- dialog2.dismiss().catch(() => {});
93
- });
94
- await page.waitForTimeout(200)
95
 
96
- // submit the form content
97
- await page.getByRole('button', { name: 'thesaurus-custom-submit' }).click();
98
  await page.waitForTimeout(200)
99
 
100
  await ensureThesaurusPanelClosed(page);
 
4
  ensureThesaurusPanelClosed,
5
  ensureThesaurusPanelOpen,
6
  fillInputFieldWithString,
7
+ handleDialogWithExpectedMessage,
8
  initTest
9
  } from './test-helper';
10
 
 
52
  await page.getByRole('button', { name: 'thesaurus-custom-button-internal0' }).click();
53
  // try to submit immediately, we'll get an error because we didn't filled the forms
54
  console.log("#")
55
+ const thesaurusCustomSubmitBtn = page.getByRole('button', { name: 'thesaurus-custom-submit' })
56
+ await handleDialogWithExpectedMessage({page, locator: thesaurusCustomSubmitBtn, expectedText: "Please enter a word."})
 
 
 
 
 
57
  await page.waitForTimeout(200)
58
 
59
  await page.getByRole('button', { name: 'thesaurus-custom-cancel' }).click(); // close the thesaurus custom form
 
80
  await expect(page.getByLabel('thesaurus-custom-form-content')).toMatchAriaSnapshot({ name: `test-classic-4-0-wordsearch_results-2-${projectName}-${state}.txt` });
81
  await page.getByRole('textbox', { name: 'thesaurus-custom-related-words-2nth' }).click();
82
  await page.getByRole('textbox', { name: 'thesaurus-custom-related-words-2nth' }).fill('joyful,happyness,content');
 
 
 
 
 
 
 
 
83
 
84
+ await handleDialogWithExpectedMessage({page, locator: thesaurusCustomSubmitBtn, expectedText: "Thesaurus entry added successfully!"})
 
85
  await page.waitForTimeout(200)
86
 
87
  await ensureThesaurusPanelClosed(page);
static/tests/test-helper.ts CHANGED
@@ -1,6 +1,6 @@
1
  import fs from 'node:fs'
2
  import * as crypto from "node:crypto";
3
- import { Locator, Page, TestInfo, expect } from '@playwright/test';
4
 
5
  interface CellObject {
6
  table: number
@@ -481,4 +481,30 @@ export async function deleteCustomSynonym(word: string) {
481
  // Re-throw the error if you want calling functions to handle it.
482
  throw error;
483
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
  }
 
1
  import fs from 'node:fs'
2
  import * as crypto from "node:crypto";
3
+ import { Dialog, Locator, Page, TestInfo, expect } from '@playwright/test';
4
 
5
  interface CellObject {
6
  table: number
 
481
  // Re-throw the error if you want calling functions to handle it.
482
  throw error;
483
  }
484
+ }
485
+ export async function handleDialogWithExpectedMessage({page, locator, expectedText}: {page: Page, locator: Locator, expectedText: string}) {
486
+ // Set up the dialog handler before clicking
487
+ const dialogPromise = page.waitForEvent('dialog', { timeout: 200 });
488
+
489
+ // Trigger the action that should show the dialog
490
+ try {
491
+ await locator.click({timeout: 100});
492
+ } catch(err0) {
493
+ console.error(`handleDialogWithExpectedMessage::error on dismissing dialog:'${err0}'`)
494
+ }
495
+ // Wait for and handle the dialog
496
+ const dialog = await dialogPromise;
497
+ const message = dialog.message();
498
+
499
+ console.log(`Dialog message: "${message}"`);
500
+
501
+ // Assert the message content
502
+ expect(message).toContain(expectedText);
503
+
504
+ // Dismiss the dialog
505
+ dialog.dismiss().catch((err1) => {console.error(`handleDialogWithExpectedMessage::error on dismissing dialog:'${err1}'`)});
506
+
507
+ // Wait a bit to ensure the dialog is fully dismissed
508
+ await page.waitForTimeout(100);
509
+
510
  }