-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a62bc7
commit 1e4b54a
Showing
12 changed files
with
201 additions
and
205 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
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
44 changes: 5 additions & 39 deletions
44
packages/ods/src/components/input/src/controller/ods-input.ts
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 |
---|---|---|
@@ -1,54 +1,20 @@ | ||
// import { EventEmitter } from "@stencil/core"; | ||
|
||
// function handleClear(eventEmitter: EventEmitter<void>, isDisabled: boolean): undefined | void { | ||
// if (isDisabled) { | ||
// return; | ||
// } | ||
// eventEmitter.emit(); | ||
// return undefined; | ||
// } | ||
|
||
async function handleKeySpace(event: KeyboardEvent, isDisabled: boolean, callback: () => Promise<void>): Promise<void> { | ||
event?.preventDefault?.(); | ||
event.preventDefault(); | ||
if(event.key === ' ' && !isDisabled) { | ||
await callback(); | ||
} | ||
} | ||
|
||
// function handleOnInput(eventEmitter: EventEmitter<{ value?: string | number}>, isDisabled: boolean, internals: ElementInternals, inputEl?: HTMLInputElement): { value?: string | number, error: boolean } { | ||
// if (isDisabled) { | ||
// return; | ||
// } | ||
// inputEl?.value && internals.setFormValue(inputEl.value.toString()); | ||
// eventEmitter.emit({ value: inputEl?.value }); | ||
// return { value: inputEl?.value, error: !inputEl?.validity.valid ?? false } | ||
// } | ||
|
||
// function handleReset(eventEmitter: EventEmitter<void>, isDisabled: boolean, defaultValue?: string | number): string | number | undefined { | ||
// if (isDisabled) { | ||
// return; | ||
// } | ||
// eventEmitter.emit(); | ||
// return defaultValue ?? undefined; | ||
// } | ||
|
||
// function handleToggleMask(eventEmitter: EventEmitter<void>, isDisabled: boolean, masked?: boolean): boolean { | ||
// if (isDisabled) { | ||
// return; | ||
// } | ||
// eventEmitter.emit(); | ||
// return !masked; | ||
// } | ||
function setFormValue(internals: ElementInternals, value?: number | string): void { | ||
internals?.setFormValue?.(value?.toString() ?? ''); | ||
} | ||
|
||
function isPassword(isMasked?: boolean): boolean { | ||
return isMasked !== undefined; | ||
} | ||
|
||
export { | ||
// handleClear, | ||
handleKeySpace, | ||
// handleOnInput, | ||
// handleToggleMask, | ||
// handleReset, | ||
isPassword, | ||
setFormValue, | ||
}; |
114 changes: 114 additions & 0 deletions
114
packages/ods/src/components/input/tests/behaviour/ods-input.e2e.ts
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,114 @@ | ||
import type { E2EElement, E2EPage } from '@stencil/core/testing'; | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('ods-input accessibility', () => { | ||
let el: E2EElement; | ||
let page: E2EPage; | ||
let part: E2EElement; | ||
|
||
async function setup(content: string): Promise<void> { | ||
page = await newE2EPage(); | ||
|
||
await page.setContent(content); | ||
await page.evaluate(() => document.body.style.setProperty('margin', '0px')); | ||
|
||
el = await page.find('ods-input'); | ||
part = await page.find('ods-input >>> [part="input"]'); | ||
await page.waitForChanges(); | ||
} | ||
|
||
beforeEach(jest.clearAllMocks); | ||
|
||
describe('method:clear', () => { | ||
it('should receive odsClear event', async() => { | ||
await setup('<ods-input value="value"></ods-input>'); | ||
const odsClearSpy = await page.spyOnEvent('odsClear'); | ||
await el.callMethod('clear'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('value')).toBeNull(); | ||
expect(odsClearSpy).toHaveReceivedEventTimes(1); | ||
}); | ||
|
||
it('should do nothing because of disabled', async() => { | ||
const value = 'value'; | ||
await setup(`<ods-input is-disabled value="${value}"></ods-input>`); | ||
const odsClearSpy = await page.spyOnEvent('odsClear'); | ||
await el.callMethod('clear'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('value')).toBe(value); | ||
expect(odsClearSpy).not.toHaveReceivedEvent(); | ||
}); | ||
}); | ||
|
||
describe('method:reset', () => { | ||
it('should receive odsReset event', async() => { | ||
const defaultValue = 'defaultValue'; | ||
await setup(`<ods-input value="value" default-value="${defaultValue}"></ods-input>`); | ||
const odsResetSpy = await page.spyOnEvent('odsReset'); | ||
await el.callMethod('reset'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('value')).toBe(defaultValue); | ||
expect(odsResetSpy).toHaveReceivedEventTimes(1); | ||
}); | ||
|
||
it('should do nothing because of disabled', async() => { | ||
const value = 'value'; | ||
await setup(`<ods-input is-disabled value="${value}" default-value="defaultValue"></ods-input>`); | ||
const odsResetSpy = await page.spyOnEvent('odsReset'); | ||
await el.callMethod('reset'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('value')).toBe(value); | ||
expect(odsResetSpy).not.toHaveReceivedEvent(); | ||
}); | ||
}); | ||
|
||
describe('method:toggleMask', () => { | ||
it('should toggle mask', async() => { | ||
await setup('<ods-input is-masked></ods-input>'); | ||
const odsToggleMaskSpy = await page.spyOnEvent('odsToggleMask'); | ||
await el.callMethod('toggleMask'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('isMasked')).toBe(false); | ||
|
||
await el.callMethod('toggleMask'); | ||
await page.waitForChanges(); | ||
expect(await el.getProperty('isMasked')).toBe(true); | ||
expect(odsToggleMaskSpy).toHaveReceivedEventTimes(2); | ||
}); | ||
|
||
it('should do nothing because of disabled', async() => { | ||
await setup('<ods-input is-masked is-disabled></ods-input>'); | ||
const odsToggleMaskSpy = await page.spyOnEvent('odsToggleMask'); | ||
await el.callMethod('toggleMask'); | ||
await page.waitForChanges(); | ||
|
||
expect(await el.getProperty('isMasked')).toBe(true); | ||
expect(odsToggleMaskSpy).not.toHaveReceivedEvent(); | ||
}); | ||
}); | ||
|
||
describe('event:odsValueChange', () => { | ||
it('should receive odsValueChange event', async() => { | ||
const typeValue = 'some text'; | ||
await setup('<ods-input></ods-input>'); | ||
const odsValueChangeSpy = await page.spyOnEvent('odsValueChange'); | ||
|
||
await part.type(typeValue); | ||
await page.waitForChanges(); | ||
|
||
expect(await el.getProperty('value')).toBe(typeValue); | ||
expect(odsValueChangeSpy).toHaveReceivedEventTimes(typeValue.length); | ||
}); | ||
|
||
it('should do nothing because of disabled', async() => { | ||
await setup('<ods-input is-disabled></ods-input>'); | ||
const odsValueChangeSpy = await page.spyOnEvent('odsValueChange'); | ||
|
||
await part.type('some text'); | ||
await page.waitForChanges(); | ||
|
||
expect(await el.getProperty('value')).toBe(undefined); | ||
expect(odsValueChangeSpy).not.toHaveReceivedEvent(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.