Skip to content

Commit 73119d3

Browse files
authored
test(components): update calendar tests
1 parent 67a8f8f commit 73119d3

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

Diff for: src/components/ui/calendar/calendar.spec.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jest.useFakeTimers();
2222
const now: Date = new Date();
2323
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
2424

25-
const CURRENT_MONTH: number = now.getMonth();
26-
2725
interface State {
2826
date: Date;
2927
}
@@ -63,8 +61,8 @@ class TestApplication extends React.Component<TestAppProps, State> {
6361
describe('@calendar: component checks', () => {
6462

6563
it('* date changes', () => {
66-
const expectedDate: Date = new Date(2019, CURRENT_MONTH, 5);
67-
const application: RenderAPI = render(<TestApplication/>);
64+
const expectedDate: Date = new Date(now.getFullYear(), now.getMonth(), 5);
65+
const application: RenderAPI = render(<TestApplication date={expectedDate}/>);
6866

6967
fireEvent.press(application.getAllByText('5')[0]);
7068
const { date } = application.getByType(Calendar).props;

Diff for: src/components/ui/calendar/rangeCalendar.spec.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import {
3-
render,
43
fireEvent,
4+
render,
55
RenderAPI,
66
} from 'react-native-testing-library';
77
import { ApplicationProvider } from '@kitten/theme';
@@ -17,7 +17,8 @@ import { CalendarRange } from '@kitten/ui/calendar/type';
1717

1818
jest.useFakeTimers();
1919

20-
const CURRENT_MONTH: number = new Date().getMonth();
20+
const now: Date = new Date();
21+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
2122

2223
interface State {
2324
range: CalendarRange<Date>;
@@ -56,7 +57,7 @@ class TestApplication extends React.Component<TestAppProps, State> {
5657
describe('@range-calendar: component checks', () => {
5758

5859
it('* start range date selected properly', () => {
59-
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
60+
const expectedStartDate: Date = new Date(now.getFullYear(), now.getMonth(), 11);
6061
const application: RenderAPI = render(<TestApplication/>);
6162

6263
fireEvent.press(application.getAllByText('11')[0]);
@@ -66,8 +67,8 @@ describe('@range-calendar: component checks', () => {
6667
});
6768

6869
it('* range selected works properly', () => {
69-
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 11);
70-
const expectedEndDate: Date = new Date(2019, CURRENT_MONTH, 26);
70+
const expectedStartDate: Date = new Date(now.getFullYear(), now.getMonth(), 11);
71+
const expectedEndDate: Date = new Date(now.getFullYear(), now.getMonth(), 26);
7172
const application: RenderAPI = render(<TestApplication/>);
7273

7374
fireEvent.press(application.getAllByText('11')[0]);
@@ -79,7 +80,7 @@ describe('@range-calendar: component checks', () => {
7980
});
8081

8182
it('* range re-selected properly 1', () => {
82-
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 19);
83+
const expectedStartDate: Date = new Date(now.getFullYear(), now.getMonth(), 19);
8384
const application: RenderAPI = render(<TestApplication/>);
8485

8586
fireEvent.press(application.getAllByText('11')[0]);
@@ -92,7 +93,7 @@ describe('@range-calendar: component checks', () => {
9293
});
9394

9495
it('* range re-selected properly 2', () => {
95-
const expectedStartDate: Date = new Date(2019, CURRENT_MONTH, 8);
96+
const expectedStartDate: Date = new Date(now.getFullYear(), now.getMonth(), 8);
9697
const application: RenderAPI = render(<TestApplication/>);
9798

9899
fireEvent.press(application.getAllByText('11')[0]);

0 commit comments

Comments
 (0)