Skip to content

Commit 3110fff

Browse files
committed
Revert "fix(cdk/testing): sending incorrect keyCode for comma (#27472)" (#27485)
This reverts commit 8250a0d. (cherry picked from commit 4d9bbe4)
1 parent 05573ae commit 3110fff

File tree

6 files changed

+4
-43
lines changed

6 files changed

+4
-43
lines changed

src/cdk/testing/testbed/fake-events/type-in-element.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

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

@@ -22,11 +22,6 @@ const incrementalInputTypes = new Set([
2222
'url',
2323
]);
2424

25-
/** Characters whose key code doesn't match their character code. */
26-
const KEYCODE_MISMATCHES: Record<string, number> = {
27-
',': COMMA,
28-
};
29-
3025
/**
3126
* Checks whether the given Element is a text input element.
3227
* @docs-private
@@ -83,12 +78,7 @@ export function typeInElement(element: HTMLElement, ...modifiersAndKeys: any[])
8378
const keys: {keyCode?: number; key?: string}[] = rest
8479
.map(k =>
8580
typeof k === 'string'
86-
? k.split('').map(c => ({
87-
keyCode: KEYCODE_MISMATCHES.hasOwnProperty(c)
88-
? KEYCODE_MISMATCHES[c]
89-
: c.toUpperCase().charCodeAt(0),
90-
key: c,
91-
}))
81+
? k.split('').map(c => ({keyCode: c.toUpperCase().charCodeAt(0), key: c}))
9282
: [k],
9383
)
9484
.reduce((arr, k) => arr.concat(k), []);

src/cdk/testing/tests/cross-environment.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,6 @@ export function crossEnvironmentSpecs(
209209
expect(await specialKey.text()).toBe('enter');
210210
});
211211

212-
it('should send comma key', async () => {
213-
const specialKey = await harness.specaialKey();
214-
await harness.sendComma();
215-
expect(await specialKey.text()).toBe(',');
216-
});
217-
218212
it('should send alt+j key', async () => {
219213
const specialKey = await harness.specaialKey();
220214
await harness.sendAltJ();

src/cdk/testing/tests/harnesses/main-component-harness.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ export class MainComponentHarness extends ComponentHarness {
152152
return (await this.input()).sendKeys({alt: true}, 'j');
153153
}
154154

155-
async sendComma(): Promise<void> {
156-
return (await this.input()).sendKeys(',');
157-
}
158-
159155
async getTaskStateResult(): Promise<string> {
160156
await (await this.taskStateTestTrigger()).click();
161157
// Wait for async tasks to complete since the click caused a

src/cdk/testing/tests/test-main-component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {COMMA, ENTER} from '@angular/cdk/keycodes';
9+
import {ENTER} from '@angular/cdk/keycodes';
1010
import {_supportsShadowDom} from '@angular/cdk/platform';
1111
import {FormControl} from '@angular/forms';
1212
import {
@@ -91,9 +91,6 @@ export class TestMainComponent implements OnDestroy {
9191
if (event.key === 'j' && event.altKey) {
9292
this.specialKey = 'alt-j';
9393
}
94-
if (event.keyCode === COMMA && event.key === ',') {
95-
this.specialKey = ',';
96-
}
9794
}
9895

9996
onClick(event: MouseEvent) {

src/material/chips/testing/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ng_test_library(
1919
srcs = glob(["**/*.spec.ts"]),
2020
deps = [
2121
":testing",
22-
"//src/cdk/keycodes",
2322
"//src/cdk/testing",
2423
"//src/cdk/testing/testbed",
2524
"//src/material/chips",

src/material/chips/testing/chip-input-harness.spec.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {HarnessLoader} from '@angular/cdk/testing';
2-
import {COMMA} from '@angular/cdk/keycodes';
32
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
43
import {Component} from '@angular/core';
54
import {ComponentFixture, TestBed} from '@angular/core/testing';
@@ -70,24 +69,12 @@ describe('MatChipInputHarness', () => {
7069
await harness.blur();
7170
expect(await harness.isFocused()).toBe(false);
7271
});
73-
74-
it('should be able to trigger a separator key', async () => {
75-
const input = await loader.getHarness(MatChipInputHarness);
76-
await input.setValue('Hello');
77-
await input.sendSeparatorKey(',');
78-
expect(fixture.componentInstance.add).toHaveBeenCalled();
79-
});
8072
});
8173

8274
@Component({
8375
template: `
8476
<mat-chip-grid #grid1>
85-
<input
86-
[matChipInputFor]="grid1"
87-
[required]="required"
88-
placeholder="Placeholder"
89-
(matChipInputTokenEnd)="add()"
90-
[matChipInputSeparatorKeyCodes]="separatorKeyCodes"/>
77+
<input [matChipInputFor]="grid1" [required]="required" placeholder="Placeholder" />
9178
</mat-chip-grid>
9279
9380
<mat-chip-grid #grid2>
@@ -97,6 +84,4 @@ describe('MatChipInputHarness', () => {
9784
})
9885
class ChipInputHarnessTest {
9986
required = false;
100-
add = jasmine.createSpy('add spy');
101-
separatorKeyCodes = [COMMA];
10287
}

0 commit comments

Comments
 (0)