From 50776da0e9e7acca7114c87f6eb5a771a0954f2e Mon Sep 17 00:00:00 2001 From: Istvan Ujj-Meszaros Date: Sun, 25 Jun 2023 04:02:37 +0200 Subject: [PATCH] Some tweaks --- __tests__/basicOperations.test.ts | 2 +- __tests__/helpers/touchspinHelpers.ts | 18 +++++++++--------- __tests__/html/index-bs4.html | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/__tests__/basicOperations.test.ts b/__tests__/basicOperations.test.ts index 82e9d4f..ad7e977 100644 --- a/__tests__/basicOperations.test.ts +++ b/__tests__/basicOperations.test.ts @@ -150,7 +150,7 @@ describe('Core functionality', () => { }); it('Should not round the decimals when forcestepdivisibility is disabled', async () => { - const selector: string = '#testinput_no_forcestepdivisibility'; + const selector: string = '#testinput_decimals_no_forcestepdivisibility'; // The initial value of 50 should be corrected to 51 by the browser as step = 3 expect(await touchspinHelpers.readInputValue(page, selector)).toBe('1200.22'); diff --git a/__tests__/helpers/touchspinHelpers.ts b/__tests__/helpers/touchspinHelpers.ts index 4720f45..eea6af3 100644 --- a/__tests__/helpers/touchspinHelpers.ts +++ b/__tests__/helpers/touchspinHelpers.ts @@ -1,4 +1,4 @@ -import {Page} from 'puppeteer'; +import {ElementHandle, NodeFor, Page} from 'puppeteer'; async function waitForTimeout(ms: number): Promise { return new Promise(r => setTimeout(r, ms)); @@ -21,7 +21,7 @@ async function setInputAttr(page: Page, selector: string, attributeName: 'disabl } async function checkTouchspinUpIsDisabled(page: Page, selector: string): Promise { - const input = await page.$(selector + ' + .input-group-btn > .bootstrap-touchspin-up'); + const input: ElementHandle | null = await page.$(selector + ' + .input-group-btn > .bootstrap-touchspin-up')!; return await input!.evaluate((el) => { return (el as HTMLInputElement).hasAttribute('disabled'); @@ -29,40 +29,40 @@ async function checkTouchspinUpIsDisabled(page: Page, selector: string): Promise } async function touchspinClickUp(page: Page, input_selector: string): Promise { - await page.evaluate((selector) => { + await page.evaluate((selector): void => { document.querySelector(selector)!.dispatchEvent(new Event('mousedown')); }, input_selector + ' + .input-group-btn > .bootstrap-touchspin-up'); // Delay to allow the value to change. await new Promise(r => setTimeout(r, 200)); - await page.evaluate((selector) => { + await page.evaluate((selector: string): void => { document.querySelector(selector)!.dispatchEvent(new Event('mouseup')); }, input_selector + ' + .input-group-btn > .bootstrap-touchspin-up'); } async function changeEventCounter(page: Page): Promise { // Get the event log content - const eventLogContent = await page.$eval('#events_log', el => el.textContent); + const eventLogContent: string = await page.$eval('#events_log', el => el.textContent!); // Count the number of 'change' events return (eventLogContent?.match(/change\[/g) ?? []).length; } async function countChangeWithValue(page: Page, expectedValue: string): Promise { - const expectedText = '#input_callbacks: change[' + expectedValue + ']'; + const expectedText: string = '#input_callbacks: change[' + expectedValue + ']'; return await page.evaluate((text) => { return Array.from(document.querySelectorAll('#events_log')) - .filter(element => element.textContent!.includes(text)).length; + .filter((element: Element) => element.textContent!.includes(text)).length; }, expectedText); } async function countEvent(page: Page, selector: string, event: string): Promise { // Get the event log content - const eventLogContent = await page.$eval('#events_log', el => el.textContent); + const eventLogContent: string = await page.$eval('#events_log', el => el.textContent!); // Count the number of 'change' events with the expected value - const searchString = selector + ': ' + event; + const searchString: string = selector + ': ' + event; return (eventLogContent ? eventLogContent.split(searchString).length - 1 : 0); } diff --git a/__tests__/html/index-bs4.html b/__tests__/html/index-bs4.html index 574fe8a..3884968 100644 --- a/__tests__/html/index-bs4.html +++ b/__tests__/html/index-bs4.html @@ -57,11 +57,11 @@
- - + +