-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemulate-delete.shared-spec.ts
83 lines (63 loc) · 2.42 KB
/
emulate-delete.shared-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { TestElement } from '@angular/cdk/testing';
import { AppHarness, AppDemoFormHarness } from './app.harness';
import { assertInitialSelectionRange, assertInitialValue, describeDoNothingInInputThatPreventsDefaults } from './expect.function';
import { AsyncEmulateKey, SharedSpecContext } from './shared-spec-context.model';
export function testEmulateDelete(
context: SharedSpecContext,
) {
let demoForm: AppDemoFormHarness;
let emulateKey: AsyncEmulateKey;
let textInput: TestElement;
beforeEach(async () => {
const app = context.app;
emulateKey = context.emulateKey;
demoForm = await app.getDemoFrom();
textInput = await demoForm.getControl('first input');
await textInput.focus();
});
describe('in empty input', () => {
beforeEach(async () => {
await assertInitialValue(textInput, '');
});
it('should do nothing', async () => {
await emulateKey.delete();
expect(await textInput.getProperty('value')).toBe('');
});
});
describe('in input with text', () => {
beforeEach(() => context.setValue('12345'));
describe('with cursor at the end', () => {
beforeEach(() => context.setCursor(5));
it('should do nothing', async () => {
await emulateKey.delete();
expect(await textInput.getProperty('value')).toBe('12345');
});
});
describe('with cursor at start', () => {
/* istanbul ignore if */
if (process.env.bug_cannotSelectPos0) {
pending(process.env.bug_cannotSelectPos0);
}
beforeEach(() => context.setCursor(0));
it('should delete first character', async () => {
await emulateKey.delete();
expect(await textInput.getProperty('value')).toBe('2345');
});
});
describe('with cursor somewhere in the middle', () => {
beforeEach(() => context.setCursor(3));
it('should delete character after cursor', async () => {
await emulateKey.delete();
expect(await textInput.getProperty('value')).toBe('1235');
});
});
describe('with selection somewhere in the middle', () => {
beforeEach(() => context.setSelectionRange(2, 4, 'backward'));
it('should delete selected characters', async () => {
await emulateKey.delete();
expect(await textInput.getProperty('value')).toBe('125');
});
});
});
describeDoNothingInInputThatPreventsDefaults(context, () => demoForm, () => emulateKey.delete());
}