-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(cdk/testing): Add support to send keys to conenteditable elements in testbed environment. #19107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cdk/testing): Add support to send keys to conenteditable elements in testbed environment. #19107
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,33 @@ import { | |
import {MainComponentHarness} from './harnesses/main-component-harness'; | ||
import {SubComponentHarness, SubComponentSpecialHarness} from './harnesses/sub-component-harness'; | ||
|
||
/** Environments for the tests. */ | ||
export const enum TestEnvironment { | ||
TEST_BED, | ||
PROTRACTOR, | ||
} | ||
|
||
/** | ||
* Tests that should behave equal in testbed and protractor environment. | ||
* | ||
* To reduce code duplication and ensure tests will act equal | ||
* with TestbedHarnessEnvironment and ProtractorHarnessEnvironment, this set of tests is | ||
* executed in unit tests and tests. | ||
* | ||
* @param environment in which environment the tests are running | ||
* @param getHarnessLoaderFromEnvironment env specific closure to get HarnessLoader | ||
* @param getMainComponentHarnessFromEnvironment env specific closure to get MainComponentHarness | ||
* @param getActiveElementId env specific closure to get active element | ||
* | ||
* @docs-private | ||
*/ | ||
export function crossEnvironmentSpecs( | ||
environment: TestEnvironment, | ||
getHarnessLoaderFromEnvironment: () => HarnessLoader, | ||
getMainComponentHarnessFromEnvironment: () => Promise<MainComponentHarness>, | ||
// Maybe we should introduce HarnessLoader.getActiveElement(): TestElement | ||
// then this 3rd parameter could get removed. | ||
getActiveElementId: () => Promise<string | null>, | ||
getActiveElementId: () => Promise<string | null>, | ||
) { | ||
describe('HarnessLoader', () => { | ||
let loader: HarnessLoader; | ||
|
@@ -305,11 +313,14 @@ export function crossEnvironmentSpecs( | |
|
||
it('should be able to clear', async () => { | ||
const input = await harness.input(); | ||
const inputEvent = await harness.inputEvent(); | ||
await input.sendKeys('Yi'); | ||
expect(await input.getProperty('value')).toBe('Yi'); | ||
expect(await inputEvent.text()).toBe('Count: 2'); | ||
|
||
await input.clear(); | ||
expect(await input.getProperty('value')).toBe(''); | ||
expect(await inputEvent.text()).toBe('Count: 3'); | ||
}); | ||
|
||
it('should be able to click', async () => { | ||
|
@@ -355,6 +366,68 @@ export function crossEnvironmentSpecs( | |
expect(await getActiveElementId()).toBe(await input.getAttribute('id')); | ||
}); | ||
|
||
it('should be able to send key to a contenteditable', async () => { | ||
const editable = await harness.editable(); | ||
const editableInputEvent = await harness.editableInputEvent(); | ||
|
||
await editable.sendKeys('Yi'); | ||
|
||
expect(await editable.text()).toBe('Yi'); | ||
expect(await editableInputEvent.text()).toBe('Count: 2'); | ||
|
||
await editable.clear(); | ||
|
||
expect(await editable.text()).toBe(''); | ||
expect(await editableInputEvent.text()).toBe('Count: 3'); | ||
}); | ||
|
||
it('should be able to send key to a child of a contenteditable', async () => { | ||
const editable = await harness.editableP(); | ||
|
||
await editable.sendKeys('Yi'); | ||
|
||
expect(await editable.text()).toBe('Yi'); | ||
}); | ||
|
||
it('should not update not contenteditable div on send key', async () => { | ||
const notEditable = await harness.notEditable(); | ||
const notEditableInputEvent = await harness.notEditableInputEvent(); | ||
|
||
await expectAsyncError(notEditable.sendKeys('Yi')); | ||
|
||
expect(await notEditable.text()).toBe(''); | ||
expect(await notEditableInputEvent.text()).toBe('Count: 0'); | ||
|
||
await expectAsyncError(notEditable.clear()); | ||
}); | ||
|
||
it('should send key based on designMode', async () => { | ||
const notEditable = await harness.notEditable(); | ||
const inheritEditable = await harness.inheritEditable(); | ||
|
||
await expectAsyncError(notEditable.sendKeys('Yi')); | ||
expect(await notEditable.text()).toBe(''); | ||
|
||
await expectAsyncError(inheritEditable.sendKeys('Yi')); | ||
expect(await inheritEditable.text()).toBe(''); | ||
|
||
await (await harness.designModeOnButton()).click(); | ||
|
||
await expectAsyncError(notEditable.sendKeys('Yi')); | ||
expect(await notEditable.text()).toBe(''); | ||
|
||
await inheritEditable.sendKeys('Yi'); | ||
// The following expectation is failing on Protractor environment | ||
// In protractor environment, the text is empty. | ||
if (environment == TestEnvironment.TEST_BED) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to figure out why this is failing, not just disable the test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I understand that. Just wondering if you have any idea why this may be happening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to at least understand what's happening first. If we know why its happening I might be ok with submitting it as is (with a comment explaining). Does the example work if you run it and manually interact? I'm not sure why its happening, but here are some guesses:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I am new here. How can I run the e2e test (as opposed to test) to interact with it to see what's happening? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to run the end to end tests with |
||
expect(await inheritEditable.text()).toBe('Yi'); | ||
} else { | ||
expect(await inheritEditable.text()).toBe(''); | ||
} | ||
|
||
await (await harness.designModeOffButton()).click(); | ||
}); | ||
|
||
it('should be able to retrieve dimensions', async () => { | ||
const dimensions = await (await harness.title()).getDimensions(); | ||
expect(dimensions).toEqual(jasmine.objectContaining({height: 100, width: 200})); | ||
|
@@ -576,3 +649,9 @@ export async function checkIsHarness<T extends ComponentHarness>( | |
await finalCheck(result as T); | ||
} | ||
} | ||
|
||
async function expectAsyncError(promise: Promise<unknown>) { | ||
let error = false; | ||
await promise.catch(() => { error = true; }); | ||
expect(error).toBe(true); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.