-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemulate-arrow-after-selections.shared-spec.ts
110 lines (93 loc) · 3.43 KB
/
emulate-arrow-after-selections.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { TestElement } from '@angular/cdk/testing';
import { AppDemoFormHarness, AppHarness } from './app.harness';
import { AsyncEmulateKey, SharedSpecContext } from './shared-spec-context.model';
import { assertInitialSelectionRange, expectSelectionRange } from './expect.function';
export function testEmulateArrowAfterSelection(
context: SharedSpecContext,
) {
let app: AppHarness;
let emulateKey: AsyncEmulateKey;
let demoForm: AppDemoFormHarness;
beforeEach(async () => {
app = context.app;
emulateKey = context.emulateKey;
demoForm = await app.getDemoFrom();
});
describe('right in input', () => {
let textInput: TestElement;
beforeEach(async () => {
textInput = await demoForm.getControl('first input');
await textInput.focus();
});
describe('that contains text', () => {
beforeEach(async () => {
await textInput.sendKeys('12345');
await assertInitialSelectionRange(textInput, 5, 5);
});
describe('with selection forward', () => {
describe('from middle to the end', () => {
beforeEach(async () => {
await emulateKey.arrow.left();
await emulateKey.shiftArrow.right();
await assertInitialSelectionRange(textInput, 4, 5, 'forward');
});
it('should only remove selection', async () => {
await emulateKey.arrow.right();
await expectSelectionRange(textInput, 5, 5, /forward|none/);
});
});
describe('from middle to middle', () => {
beforeEach(async () => {
await emulateKey.arrow.up();
await emulateKey.arrow.right();
await emulateKey.shiftArrow.right();
await assertInitialSelectionRange(textInput, 1, 2, 'forward');
});
it('should remove selection', async () => {
await emulateKey.arrow.right();
await expectSelectionRange(textInput, 2, 2, /forward|none/);
});
});
});
});
});
describe('left in input', () => {
let textInput: TestElement;
beforeEach(async () => {
textInput = await demoForm.getControl('first input');
await textInput.focus();
});
describe('that contains text', () => {
beforeEach(async () => {
await textInput.sendKeys('12345');
await assertInitialSelectionRange(textInput, 5, 5);
});
describe('with selection forward', () => {
describe('from middle to the end', () => {
beforeEach(async () => {
await emulateKey.arrow.up();
await emulateKey.arrow.right();
await emulateKey.shiftArrow.down();
await assertInitialSelectionRange(textInput, 1, 5, 'forward');
});
it('should only remove selection', async () => {
await emulateKey.arrow.left();
await expectSelectionRange(textInput, 1, 1, /forward|none/);
});
});
describe('from middle to middle', () => {
beforeEach(async () => {
await emulateKey.arrow.up();
await emulateKey.arrow.right();
await emulateKey.shiftArrow.right();
await assertInitialSelectionRange(textInput, 1, 2, 'forward');
});
it('should remove selection', async () => {
await emulateKey.arrow.left();
await expectSelectionRange(textInput, 1, 1, /forward|none/);
});
});
});
});
});
}