Skip to content

Commit e0f5638

Browse files
daniele-mngtimopollmeier
authored andcommitted
add tests
1 parent b6cd0c9 commit e0f5638

File tree

4 files changed

+80
-138
lines changed

4 files changed

+80
-138
lines changed

src/web/pages/performance/__tests__/startendtimeselection.jsx

Lines changed: 37 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
*/
1818
import {describe, test, expect, testing} from '@gsa/testing';
1919

20-
import Date from 'gmp/models/date';
21-
22-
import {render, fireEvent} from 'web/utils/testing';
20+
import MomentDate from 'gmp/models/date';
21+
import {render, screen, fireEvent} from 'web/utils/testing';
2322

2423
import StartTimeSelection from '../startendtimeselection';
2524

26-
describe('StartTimeSelection tests', () => {
27-
test('should render', () => {
28-
const timezone = 'CET';
29-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
30-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
25+
const timezone = 'CET';
26+
const startDate = MomentDate('2019-01-01T12:00Z').tz(timezone);
27+
const endDate = MomentDate('2019-01-01T13:00Z').tz(timezone);
3128

32-
const handleChange = testing.fn();
29+
const handleChange = testing.fn();
3330

31+
describe('StartTimeSelection tests', () => {
32+
test('should render correct dates', () => {
3433
const {element} = render(
3534
<StartTimeSelection
3635
timezone={timezone}
@@ -40,16 +39,34 @@ describe('StartTimeSelection tests', () => {
4039
/>,
4140
);
4241

43-
expect(element).toBeInTheDocument();
42+
expect(element).toBeVisible();
43+
44+
const checkElementVisibilityAndContent = (
45+
labelText,
46+
buttonName,
47+
buttonContent,
48+
) => {
49+
const label = screen.getByLabelText(labelText);
50+
expect(label).toBeVisible();
51+
52+
const button = screen.getByRole('button', {name: buttonName});
53+
expect(button).toBeVisible();
54+
expect(button).toHaveTextContent(buttonContent);
55+
};
56+
57+
checkElementVisibilityAndContent(
58+
'Start Time',
59+
'Jan 01, 2019, 01:00:00 PM',
60+
'Jan 01, 2019, 01:00:00 PM',
61+
);
62+
checkElementVisibilityAndContent(
63+
'End Time',
64+
'Jan 01, 2019, 02:00:00 PM',
65+
'Jan 01, 2019, 02:00:00 PM',
66+
);
4467
});
4568

4669
test('should display timezone', () => {
47-
const timezone = 'CET';
48-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
49-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
50-
51-
const handleChange = testing.fn();
52-
5370
const {getByTestId} = render(
5471
<StartTimeSelection
5572
timezone={timezone}
@@ -63,109 +80,8 @@ describe('StartTimeSelection tests', () => {
6380

6481
expect(elem).toHaveTextContent(timezone);
6582
});
66-
67-
test('should allow to change start time hour', () => {
68-
const timezone = 'CET';
69-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
70-
const newStartDate = Date('2019-01-01T01:00Z').tz(timezone);
71-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
72-
73-
const handleChange = testing.fn();
74-
75-
const {getByName, getByTestId} = render(
76-
<StartTimeSelection
77-
timezone={timezone}
78-
startDate={startDate}
79-
endDate={endDate}
80-
onChanged={handleChange}
81-
/>,
82-
);
83-
84-
const input = getByName('startHour');
85-
fireEvent.change(input, {target: {value: '2'}});
86-
87-
const button = getByTestId('update-button');
88-
fireEvent.click(button);
89-
90-
// eslint-disable-next-line prefer-destructuring
91-
const args = handleChange.mock.calls[0][0];
92-
93-
expect(handleChange).toHaveBeenCalledTimes(1);
94-
expect(newStartDate.isSame(args.startDate)).toEqual(true);
95-
expect(endDate.isSame(args.endDate)).toEqual(true);
96-
});
97-
98-
test('should allow to change start time minute', () => {
99-
const timezone = 'CET';
100-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
101-
const newStartDate = Date('2019-01-01T12:10Z').tz(timezone);
102-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
103-
104-
const handleChange = testing.fn();
105-
106-
const {getByName, getByTestId} = render(
107-
<StartTimeSelection
108-
timezone={timezone}
109-
startDate={startDate}
110-
endDate={endDate}
111-
onChanged={handleChange}
112-
/>,
113-
);
114-
115-
const input = getByName('startMinute');
116-
fireEvent.change(input, {target: {value: '10'}});
117-
118-
const button = getByTestId('update-button');
119-
fireEvent.click(button);
120-
121-
// eslint-disable-next-line prefer-destructuring
122-
const args = handleChange.mock.calls[0][0];
123-
124-
expect(handleChange).toHaveBeenCalledTimes(1);
125-
expect(newStartDate.isSame(args.startDate)).toEqual(true);
126-
expect(endDate.isSame(args.endDate)).toEqual(true);
127-
});
128-
129-
test('should allow to change end time hour', () => {
130-
const timezone = 'CET';
131-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
132-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
133-
const newEndDate = Date('2019-01-01T14:00Z').tz(timezone);
134-
135-
const handleChange = testing.fn();
136-
137-
const {getByName, getByTestId} = render(
138-
<StartTimeSelection
139-
timezone={timezone}
140-
startDate={startDate}
141-
endDate={endDate}
142-
onChanged={handleChange}
143-
/>,
144-
);
145-
146-
const input = getByName('endHour');
147-
fireEvent.change(input, {target: {value: '15'}});
148-
149-
const button = getByTestId('update-button');
150-
fireEvent.click(button);
151-
152-
// eslint-disable-next-line prefer-destructuring
153-
const args = handleChange.mock.calls[0][0];
154-
155-
expect(handleChange).toHaveBeenCalledTimes(1);
156-
expect(startDate.isSame(args.startDate)).toEqual(true);
157-
expect(newEndDate.isSame(args.endDate)).toEqual(true);
158-
});
159-
160-
test('should allow to change end time minute', () => {
161-
const timezone = 'CET';
162-
const startDate = Date('2019-01-01T12:00Z').tz(timezone);
163-
const endDate = Date('2019-01-01T13:00Z').tz(timezone);
164-
const newEndDate = Date('2019-01-01T13:15Z').tz(timezone);
165-
166-
const handleChange = testing.fn();
167-
168-
const {getByName, getByTestId} = render(
83+
test('Update button click event', () => {
84+
const {getByTestId} = render(
16985
<StartTimeSelection
17086
timezone={timezone}
17187
startDate={startDate}
@@ -174,17 +90,9 @@ describe('StartTimeSelection tests', () => {
17490
/>,
17591
);
17692

177-
const input = getByName('endMinute');
178-
fireEvent.change(input, {target: {value: '15'}});
179-
180-
const button = getByTestId('update-button');
181-
fireEvent.click(button);
182-
183-
// eslint-disable-next-line prefer-destructuring
184-
const args = handleChange.mock.calls[0][0];
93+
const updateButton = getByTestId('update-button');
94+
fireEvent.click(updateButton);
18595

18696
expect(handleChange).toHaveBeenCalledTimes(1);
187-
expect(startDate.isSame(args.startDate)).toEqual(true);
188-
expect(newEndDate.isSame(args.endDate)).toEqual(true);
18997
});
19098
});

src/web/pages/schedules/__tests__/dialog.jsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,20 @@ import {describe, test, expect, testing} from '@gsa/testing';
1919

2020
import Schedule from 'gmp/models/schedule';
2121

22-
import {render, fireEvent} from 'web/utils/testing';
22+
import {render, fireEvent, screen} from 'web/utils/testing';
23+
24+
const checkElementVisibilityAndContent = (
25+
labelText,
26+
buttonName,
27+
buttonContent,
28+
) => {
29+
const label = screen.getByLabelText(labelText);
30+
expect(label).toBeVisible();
31+
32+
const button = screen.getByRole('button', {name: buttonName});
33+
expect(button).toBeVisible();
34+
expect(button).toHaveTextContent(buttonContent);
35+
};
2336

2437
import {
2538
changeInputValue,
@@ -75,8 +88,8 @@ const {
7588
} = recurrence;
7689

7790
describe('ScheduleDialog component tests', () => {
78-
test('should render with default values', () => {
79-
const {baseElement, getByName} = render(
91+
test.only('should render with default values', () => {
92+
const {baseElement} = render(
8093
<ScheduleDialog
8194
id={scheduleId}
8295
title={`Edit Schedule ${scheduleName}`}
@@ -106,12 +119,16 @@ describe('ScheduleDialog component tests', () => {
106119
const defaultTimezone = selects[0];
107120
expect(defaultTimezone).toHaveValue('Coordinated Universal Time/UTC');
108121

109-
expect(baseElement).toHaveTextContent('02/08/2021');
110-
expect(getByName('startHour')).toHaveValue('15');
111-
expect(getByName('startMinute')).toHaveValue('0');
112-
113-
expect(getByName('endHour')).toHaveValue('19');
114-
expect(getByName('endMinute')).toHaveValue('45');
122+
checkElementVisibilityAndContent(
123+
'First Run',
124+
'Feb 08, 2021, 04:00:00 PM',
125+
'Feb 08, 2021, 04:00:00 PM',
126+
);
127+
checkElementVisibilityAndContent(
128+
'End Run',
129+
'Feb 08, 2021, 08:45:00 PM',
130+
'Feb 08, 2021, 08:45:00 PM',
131+
);
115132

116133
expect(baseElement).toHaveTextContent('5 hours');
117134

src/web/wizard/__tests__/advancedtaskwizard.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ describe('AdvancedTaskWizard component tests', () => {
116116
const radioInputs = getRadioInputs();
117117
const radioTitles = getRadioTitles();
118118

119+
const selectedDate = 'Jan 01, 2020, 01:10:00 PM';
120+
const datePickerLabel = screen.getByLabelText('Start Date');
121+
const startDateButton = screen.getByRole('button', {name: selectedDate});
122+
123+
expect(startDateButton).toBeVisible();
124+
expect(datePickerLabel).toBeVisible();
125+
expect(startDateButton).toHaveTextContent(selectedDate);
126+
119127
expect(formGroups[0]).toHaveTextContent('Task Name');
120128

121129
expect(formGroups[1]).toHaveTextContent('Scan Config');

src/web/wizard/__tests__/modifytaskwizard.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ describe('ModifyTaskWizard component tests', () => {
8686
const radioInputs = getRadioInputs();
8787
const radioTitles = getRadioTitles();
8888

89+
const selectedDate = 'Jan 01, 2020, 01:10:00 PM';
90+
const datePickerLabel = screen.getByLabelText('Start Date');
91+
const startDateButton = screen.getByRole('button', {name: selectedDate});
92+
93+
expect(startDateButton).toBeVisible();
94+
expect(datePickerLabel).toBeVisible();
95+
expect(startDateButton).toHaveTextContent(selectedDate);
96+
8997
expect(baseElement).toHaveTextContent('Setting a start time');
9098
expect(baseElement).toHaveTextContent('Setting an email Address');
9199

@@ -101,6 +109,7 @@ describe('ModifyTaskWizard component tests', () => {
101109
expect(radioTitles[1]).toHaveTextContent('Create Schedule');
102110

103111
expect(formGroups[2]).toHaveTextContent('Email report to');
112+
expect(startDateButton).toBeVisible();
104113
});
105114

106115
test('should not render schedule without permission', () => {

0 commit comments

Comments
 (0)