-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 test(
<ThemePaletteSecondarySetting>
): Cover input debouncing.
- Loading branch information
1 parent
b366d2f
commit 91f5502
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
imports/ui/settings/ThemePaletteSecondarySetting.tests.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
|
||
import {assert} from 'chai'; | ||
|
||
import {range} from '@iterable-iterator/range'; | ||
import {map} from '@iterable-iterator/map'; | ||
import {list} from '@iterable-iterator/list'; | ||
|
||
import {faker} from '@faker-js/faker'; | ||
|
||
import createUserWithPassword from '../../api/user/createUserWithPassword'; | ||
import loginWithPassword from '../../api/user/loginWithPassword'; | ||
import {client, randomPassword, randomUserId} from '../../_test/fixtures'; | ||
import {render} from '../../_test/react'; | ||
|
||
import { | ||
TIMEOUT_INPUT_DEBOUNCE, | ||
TIMEOUT_REACTIVITY_DEBOUNCE, | ||
} from '../constants'; | ||
import sleep from '../../lib/async/sleep'; | ||
|
||
import ThemePaletteSecondarySetting from './ThemePaletteSecondarySetting'; | ||
|
||
client(__filename, () => { | ||
it('should debounce user input', async () => { | ||
const {setupUser} = await import('../../../test/app/client/fixtures'); | ||
const username = randomUserId(); | ||
const password = randomPassword(); | ||
await createUserWithPassword(username, password); | ||
await loginWithPassword(username, password); | ||
|
||
const {findByRole} = render(<ThemePaletteSecondarySetting />); | ||
|
||
const button = await findByRole('button', { | ||
name: 'Secondary color for theme', | ||
}); | ||
const {user} = setupUser(); | ||
|
||
await user.click(button); | ||
const hex = await findByRole('textbox', {name: 'hex'}); | ||
|
||
const n = 10; | ||
const validInputs = list( | ||
map(() => faker.color.rgb().toUpperCase(), range(n)), | ||
); | ||
|
||
// NOTE: Trigger a sequence of updates. | ||
for (const validInput of validInputs) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await sleep(5); | ||
// eslint-disable-next-line no-await-in-loop | ||
await user.clear(hex); | ||
// eslint-disable-next-line no-await-in-loop | ||
await user.paste(validInput); | ||
} | ||
|
||
assert.strictEqual(button.textContent?.toUpperCase(), validInputs.at(-1)); | ||
|
||
await sleep(TIMEOUT_INPUT_DEBOUNCE + TIMEOUT_REACTIVITY_DEBOUNCE * 2); | ||
|
||
assert.strictEqual(button.textContent?.toUpperCase(), validInputs.at(-1)); | ||
}).timeout(10_000); | ||
}); |