-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-refactoring.spec.js
95 lines (85 loc) · 2.58 KB
/
index-refactoring.spec.js
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
import {
getDateByLanguage,
useDateInput,
} from './index-refactoring';
const dates = {
de: '11.08.1984',
deShort: '1.2.3456',
deShortFilled: '01.02.3456',
};
/* test('getDateByLanguage without date String should throw an error', () => {
expect(getDateByLanguage).toThrow(Error);
expect(getDateByLanguage).toThrow('dateString is Required');
}); */
/* test('getDateByLanguage with unsupported language should throw an error', () => {
expect(getDateByLanguage(dates.de, 'Blubb')).toThrow(Error);
expect(getDateByLanguage(dates.de, 'Blubb')).toBe('is not a supported Language');
}); */
test('getDateByLanguage should get Date Input Object', () => {
expect(getDateByLanguage(dates.de)).toEqual(
expect.objectContaining({
day: '11',
month: '08',
year: '1984',
})
);
expect(getDateByLanguage(dates.deShort)).toEqual(
expect.objectContaining({
day: '01',
month: '02',
year: '3456',
})
);
});
test('input validation should be correctly initialized', () => {
const {
inputValidation,
} = useDateInput();
expect(inputValidation.dayIsValid).toBe(false);
expect(inputValidation.monthValid).toBe(false);
expect(inputValidation.yearIsValid).toBe(false);
});
test('complete date in correct format should be validated', () => {
const {
handleInput,
inputValidation,
} = useDateInput();
expect(handleInput(dates.de)).toBe(dates.de);
});
test('input should works', () => {
const {
handleInput,
inputValidation,
} = useDateInput();
expect(handleInput('1')).toBe('1');
expect(handleInput('11')).toBe('11.');
expect(handleInput('11.')).toBe('11.');
expect(handleInput('11.0')).toBe('11.0');
expect(handleInput('11.08')).toBe('11.08.');
expect(handleInput('11.08.')).toBe('11.08.');
expect(handleInput('11.08.1')).toBe('11.08.1');
expect(handleInput('11.08.19')).toBe('11.08.19');
expect(handleInput('11.08.198')).toBe('11.08.198');
expect(handleInput('11.08.1984')).toBe('11.08.1984');
});
test('input without zero should set delimiter automatically', () => {
const {
handleInput,
} = useDateInput();
expect(handleInput('1.')).toBe('01.');
expect(handleInput('01.11')).toBe('01.11.');
});
test('input with zero should set delimiter automatically', () => {
const {
handleInput,
} = useDateInput();
expect(handleInput('01')).toBe('01.');
expect(handleInput('01.02')).toBe('01.02.');
});
test('complete dates should be work', () => {
const {
handleInput,
} = useDateInput();
expect(handleInput(dates.deShort)).toBe(dates.deShortFilled);
expect(handleInput(dates.de)).toBe(dates.de);
});