-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Mouseover Pre-popup Causing Typing Error - PR#7 from glenn2223
### Fixed - The mouse being over the popup when it's rendered no longer selects that value whilst typing ### Changes - Added CI based testing for every PR
- Loading branch information
Showing
4 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
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,20 @@ | ||
name: Tests | ||
on: | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
# ALLOW MANUAL RUNS | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
- run: npm ci | ||
- run: npm test | ||
- run: npm run prepublishOnly |
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
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
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,88 @@ | ||
import { Autocomplete, AutocompleteStatus } from '../src/index'; | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe('Mouseover Tests', () => { | ||
let inputEL: HTMLInputElement, autocomplete: Autocomplete; | ||
|
||
describe('Test environment:-', () => { | ||
it('has added element', () => { | ||
inputEL = document.createElement('input'); | ||
|
||
inputEL.classList.add('test'); | ||
inputEL = document.body.insertAdjacentElement( | ||
'beforeend', | ||
inputEL, | ||
) as HTMLInputElement; | ||
|
||
expect(inputEL).not.toBeNull(); | ||
}); | ||
|
||
it('has created autocomplete', () => { | ||
autocomplete = new Autocomplete('.test', { | ||
source: [ | ||
{ label: 'First label', value: 'First Value' }, | ||
{ label: 'Second label', value: 'Second Value' }, | ||
{ label: 'Third label', value: 'Third Value' }, | ||
{ label: 'Final label', value: 'Final Value' }, | ||
], | ||
onOpen: (e, data) => { | ||
data.ul.style.width = `${ | ||
(e.target as HTMLInputElement).width | ||
}px`; | ||
}, | ||
}); | ||
|
||
expect(autocomplete).not.toBeNull(); | ||
}); | ||
|
||
it('has initial state of "stopped"', () => | ||
expect(autocomplete.status).toBe(AutocompleteStatus.Stopped)); | ||
|
||
it('"start" should not throw', () => | ||
expect(autocomplete.start).not.toThrow()); | ||
|
||
it('now has "started" state', () => | ||
expect(autocomplete.status).toBe(AutocompleteStatus.Started)); | ||
}); | ||
|
||
describe('Mouse over', () => { | ||
beforeEach(() => { | ||
inputEL.dispatchEvent(new Event('focusout')); | ||
jest.advanceTimersByTime(251); | ||
}); | ||
|
||
it('popping up under mouse should not change input', () => { | ||
inputEL.value = 'Test Value'; | ||
inputEL.dispatchEvent(new Event('change')); | ||
|
||
const ul = | ||
(document.getElementById( | ||
inputEL.dataset.acId ?? '', | ||
) as HTMLUListElement | null) ?? document.createElement('ul'); | ||
|
||
ul.children[0].dispatchEvent(new Event('mouseover')); | ||
|
||
jest.advanceTimersByTime(1); | ||
|
||
const point: [number, number] | undefined = | ||
//@ts-ignore | ||
autocomplete._stateData[inputEL.dataset.acId].focusPoint; | ||
|
||
expect(point).toBeDefined(); | ||
}); | ||
|
||
it('no initial mouseover should clear the focusPoint', () => { | ||
inputEL.value = 'Test Value'; | ||
inputEL.dispatchEvent(new Event('change')); | ||
|
||
jest.advanceTimersByTime(334); | ||
|
||
const point: [number, number] | undefined = | ||
//@ts-ignore | ||
autocomplete._stateData[inputEL.dataset.acId].focusPoint; | ||
|
||
expect(point).toBeUndefined(); | ||
}); | ||
}); | ||
}); |