-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
assertions.ts
44 lines (40 loc) · 1.32 KB
/
assertions.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
import { expect } from 'chai';
import { SinonSpy } from 'sinon';
import { cleanText } from 'test/utils/pickers';
export const expectFieldValueV7 = (
fieldSectionsContainer: HTMLDivElement,
expectedValue: string,
specialCase?: 'singleDigit' | 'RTL',
) => {
const value = cleanText(fieldSectionsContainer.textContent ?? '', specialCase);
return expect(value).to.equal(expectedValue);
};
export const expectFieldValueV6 = (
input: HTMLInputElement,
expectedValue: string,
specialCase?: 'singleDigit' | 'RTL',
) => {
const value = cleanText(input.value, specialCase);
return expect(value).to.equal(expectedValue);
};
export const expectFieldPlaceholderV6 = (
input: HTMLInputElement,
placeholder: string,
specialCase?: 'singleDigit' | 'RTL',
) => {
const cleanPlaceholder = cleanText(input.placeholder, specialCase);
return expect(cleanPlaceholder).to.equal(placeholder);
};
export function expectPickerChangeHandlerValue(
type: 'date' | 'date-time' | 'time' | 'date-range' | 'date-time-range',
spyCallback: SinonSpy,
expectedValue: any,
) {
if (['date-range', 'date-time-range'].includes(type)) {
spyCallback.lastCall.firstArg.forEach((value, index) => {
expect(value).to.deep.equal(expectedValue[index]);
});
} else {
expect(spyCallback.lastCall.firstArg).to.deep.equal(expectedValue);
}
}