Skip to content
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

Revert "fix(cdk/testing): sending incorrect keyCode for comma (#27472)" #27485

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/cdk/testing/testbed/fake-events/type-in-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {getNoKeysSpecifiedError, ModifierKeys} from '@angular/cdk/testing';
import {COMMA, PERIOD} from '@angular/cdk/keycodes';
import {PERIOD} from '@angular/cdk/keycodes';
import {dispatchFakeEvent, dispatchKeyboardEvent} from './dispatch-events';
import {triggerFocus} from './element-focus';

Expand All @@ -22,11 +22,6 @@ const incrementalInputTypes = new Set([
'url',
]);

/** Characters whose key code doesn't match their character code. */
const KEYCODE_MISMATCHES: Record<string, number> = {
',': COMMA,
};

/**
* Checks whether the given Element is a text input element.
* @docs-private
Expand Down Expand Up @@ -83,12 +78,7 @@ export function typeInElement(element: HTMLElement, ...modifiersAndKeys: any[])
const keys: {keyCode?: number; key?: string}[] = rest
.map(k =>
typeof k === 'string'
? k.split('').map(c => ({
keyCode: KEYCODE_MISMATCHES.hasOwnProperty(c)
? KEYCODE_MISMATCHES[c]
: c.toUpperCase().charCodeAt(0),
key: c,
}))
? k.split('').map(c => ({keyCode: c.toUpperCase().charCodeAt(0), key: c}))
: [k],
)
.reduce((arr, k) => arr.concat(k), []);
Expand Down
6 changes: 0 additions & 6 deletions src/cdk/testing/tests/cross-environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,6 @@ export function crossEnvironmentSpecs(
expect(await specialKey.text()).toBe('enter');
});

it('should send comma key', async () => {
const specialKey = await harness.specaialKey();
await harness.sendComma();
expect(await specialKey.text()).toBe(',');
});

it('should send alt+j key', async () => {
const specialKey = await harness.specaialKey();
await harness.sendAltJ();
Expand Down
4 changes: 0 additions & 4 deletions src/cdk/testing/tests/harnesses/main-component-harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ export class MainComponentHarness extends ComponentHarness {
return (await this.input()).sendKeys({alt: true}, 'j');
}

async sendComma(): Promise<void> {
return (await this.input()).sendKeys(',');
}

async getTaskStateResult(): Promise<string> {
await (await this.taskStateTestTrigger()).click();
// Wait for async tasks to complete since the click caused a
Expand Down
5 changes: 1 addition & 4 deletions src/cdk/testing/tests/test-main-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {COMMA, ENTER} from '@angular/cdk/keycodes';
import {ENTER} from '@angular/cdk/keycodes';
import {_supportsShadowDom} from '@angular/cdk/platform';
import {FormControl} from '@angular/forms';
import {
Expand Down Expand Up @@ -91,9 +91,6 @@ export class TestMainComponent implements OnDestroy {
if (event.key === 'j' && event.altKey) {
this.specialKey = 'alt-j';
}
if (event.keyCode === COMMA && event.key === ',') {
this.specialKey = ',';
}
}

onClick(event: MouseEvent) {
Expand Down
1 change: 0 additions & 1 deletion src/material/chips/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ng_test_library(
srcs = glob(["**/*.spec.ts"]),
deps = [
":testing",
"//src/cdk/keycodes",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/chips",
Expand Down
17 changes: 1 addition & 16 deletions src/material/chips/testing/chip-input-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {HarnessLoader} from '@angular/cdk/testing';
import {COMMA} from '@angular/cdk/keycodes';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {Component} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
Expand Down Expand Up @@ -70,24 +69,12 @@ describe('MatChipInputHarness', () => {
await harness.blur();
expect(await harness.isFocused()).toBe(false);
});

it('should be able to trigger a separator key', async () => {
const input = await loader.getHarness(MatChipInputHarness);
await input.setValue('Hello');
await input.sendSeparatorKey(',');
expect(fixture.componentInstance.add).toHaveBeenCalled();
});
});

@Component({
template: `
<mat-chip-grid #grid1>
<input
[matChipInputFor]="grid1"
[required]="required"
placeholder="Placeholder"
(matChipInputTokenEnd)="add()"
[matChipInputSeparatorKeyCodes]="separatorKeyCodes"/>
<input [matChipInputFor]="grid1" [required]="required" placeholder="Placeholder" />
</mat-chip-grid>
<mat-chip-grid #grid2>
Expand All @@ -97,6 +84,4 @@ describe('MatChipInputHarness', () => {
})
class ChipInputHarnessTest {
required = false;
add = jasmine.createSpy('add spy');
separatorKeyCodes = [COMMA];
}
Loading