Skip to content

Commit

Permalink
Some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
istvan-ujjmeszaros committed Jun 25, 2023
1 parent 7649f73 commit 50776da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion __tests__/basicOperations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
18 changes: 9 additions & 9 deletions __tests__/helpers/touchspinHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Page} from 'puppeteer';
import {ElementHandle, NodeFor, Page} from 'puppeteer';

async function waitForTimeout(ms: number): Promise<void> {
return new Promise(r => setTimeout(r, ms));
Expand All @@ -21,48 +21,48 @@ async function setInputAttr(page: Page, selector: string, attributeName: 'disabl
}

async function checkTouchspinUpIsDisabled(page: Page, selector: string): Promise<boolean> {
const input = await page.$(selector + ' + .input-group-btn > .bootstrap-touchspin-up');
const input: ElementHandle<Element> | null = await page.$(selector + ' + .input-group-btn > .bootstrap-touchspin-up')!;

return await input!.evaluate((el) => {
return (el as HTMLInputElement).hasAttribute('disabled');
});
}

async function touchspinClickUp(page: Page, input_selector: string): Promise<void> {
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<number> {
// 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<number> {
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<number> {
// 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);
}

Expand Down
6 changes: 3 additions & 3 deletions __tests__/html/index-bs4.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
</div>

<div class="wrapper">
<label for="testinput_no_forcestepdivisibility">#testinput_no_forcestepdivisibility:</label>
<input id="testinput_no_forcestepdivisibility" type="number" value="1200.22" name="testinput_no_forcestepdivisibility">
<label for="testinput_decimals_no_forcestepdivisibility">#testinput_decimals_no_forcestepdivisibility:</label>
<input id="testinput_decimals_no_forcestepdivisibility" type="number" value="1200.22" name="testinput_decimals_no_forcestepdivisibility">

<script>
$("#testinput_no_forcestepdivisibility").TouchSpin({
$("#testinput_decimals_no_forcestepdivisibility").TouchSpin({
min: 1200.22,
max: null,
step: 100,
Expand Down

0 comments on commit 50776da

Please sign in to comment.