-
Notifications
You must be signed in to change notification settings - Fork 949
/
rangeCalendar.spec.tsx
107 lines (85 loc) · 3.16 KB
/
rangeCalendar.spec.tsx
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
import React from 'react';
import {
render,
fireEvent,
RenderAPI,
} from 'react-native-testing-library';
import { ApplicationProvider } from '@kitten/theme';
import {
RangeCalendar,
RangeCalendarProps,
} from './rangeCalendar.component';
import {
mapping,
theme,
} from '../support/tests';
import { CalendarRange } from '@kitten/ui/calendar/type';
jest.useFakeTimers();
const CURRENT_MONTH: number = new Date().getMonth();
interface State {
range: CalendarRange<Date>;
}
type TestAppProps = Omit<RangeCalendarProps<Date>, 'range' | 'onSelect'>;
class TestApplication extends React.Component<TestAppProps, State> {
public state: State = {
range: {
startDate: null,
endDate: null,
},
};
private onSelect = (range: CalendarRange<Date>): void => {
this.setState({ range });
};
public render(): React.ReactNode {
return (
<ApplicationProvider
mapping={mapping}
theme={theme}>
<RangeCalendar
{...this.props}
range={this.state.range}
onSelect={this.onSelect}
/>
</ApplicationProvider>
);
}
}
describe('@range-calendar: component checks', () => {
it('* start range date selected properly', () => {
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
const application: RenderAPI = render(<TestApplication/>);
fireEvent.press(application.getAllByText('11')[0]);
const { range } = application.getByType(RangeCalendar).props;
expect(range.startDate.toString()).toBe(expectedStartDate.toString());
});
it('* range selected works properly', () => {
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
const expectedEndDate: Date = new Date(2019, CURRENT_MONTH, 26);
const application: RenderAPI = render(<TestApplication/>);
fireEvent.press(application.getAllByText('11')[0]);
fireEvent.press(application.getAllByText('26')[0]);
const { range } = application.getByType(RangeCalendar).props;
expect(range.startDate.toString()).toBe(expectedStartDate.toString());
expect(range.endDate.toString()).toBe(expectedEndDate.toString());
});
it('* range re-selected properly 1', () => {
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 19);
const application: RenderAPI = render(<TestApplication/>);
fireEvent.press(application.getAllByText('11')[0]);
fireEvent.press(application.getAllByText('26')[0]);
fireEvent.press(application.getAllByText('19')[0]);
const { range } = application.getByType(RangeCalendar).props;
expect(range.startDate.toString()).toBe(expectedStartDate.toString());
expect(range.endDate).toBeNull();
});
it('* range re-selected properly 2', () => {
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 8);
const application: RenderAPI = render(<TestApplication/>);
fireEvent.press(application.getAllByText('11')[0]);
fireEvent.press(application.getAllByText('26')[0]);
fireEvent.press(application.getAllByText('8')[0]);
const { range } = application.getByType(RangeCalendar).props;
expect(range.startDate.toString()).toBe(expectedStartDate.toString());
expect(range.endDate).toBeNull();
});
});