Skip to content

Commit 7c597dc

Browse files
committed
Test empty input behaviour
1 parent 0357fb5 commit 7c597dc

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

src/App.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,78 @@ describe('App', () => {
193193
fireEvent.click(startButton);
194194
expect(play).toHaveBeenCalledTimes(2);
195195
});
196+
197+
it.each`
198+
case | workMinutesValue | workSecondsValue | breakMinutesValue | breakSecondsValue
199+
${'work input empty'} | ${'0'} | ${'0'} | ${'1'} | ${'1'}
200+
${'break input empty'} | ${'1'} | ${'1'} | ${'0'} | ${'0'}
201+
`(
202+
'should not run when $case',
203+
({
204+
workMinutesValue,
205+
workSecondsValue,
206+
breakMinutesValue,
207+
breakSecondsValue,
208+
}) => {
209+
const {
210+
breakIntervalMinuteInput,
211+
breakIntervalSecondInput,
212+
prepTime,
213+
roundInput,
214+
startButton,
215+
workIntervalMinuteInput,
216+
workIntervalSecondInput,
217+
getByTestId,
218+
getByText,
219+
} = renderApp();
220+
221+
expect(roundInput).toBeTruthy();
222+
expect(workIntervalMinuteInput).toBeTruthy();
223+
expect(workIntervalSecondInput).toBeTruthy();
224+
expect(breakIntervalMinuteInput).toBeTruthy();
225+
expect(breakIntervalSecondInput).toBeTruthy();
226+
expect(startButton).toBeTruthy();
227+
228+
const roundsValue = '2';
229+
230+
fireEvent.change(roundInput, { target: { value: roundsValue } });
231+
fireEvent.blur(roundInput);
232+
233+
fireEvent.change(workIntervalMinuteInput, {
234+
target: { value: workMinutesValue },
235+
});
236+
fireEvent.change(workIntervalSecondInput, {
237+
target: { value: workSecondsValue },
238+
});
239+
240+
fireEvent.change(breakIntervalMinuteInput, {
241+
target: { value: breakMinutesValue },
242+
});
243+
fireEvent.change(breakIntervalSecondInput, {
244+
target: { value: breakSecondsValue },
245+
});
246+
247+
const advanceDateNowBy = makeAdvanceDateNowBy(startDate);
248+
249+
fireEvent.click(startButton);
250+
251+
const timeLeftSeconds = getByTestId('time-left-seconds');
252+
const round = getByTestId('round');
253+
const status = getByTestId('status');
254+
255+
expect(round.textContent).toBe('0/2');
256+
expect(status.textContent).toBe('PREP');
257+
258+
// count down from 00:05 and stop after two seconds
259+
expectCountDownFrom({
260+
minutes: 0,
261+
seconds: prepTime,
262+
advanceDateNowBy,
263+
timeLeftMinutes: { value: '00' },
264+
timeLeftSeconds,
265+
});
266+
267+
expect(getByText('Start')).toBeTruthy();
268+
}
269+
);
196270
});

src/utils/test-utils/renderApp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
33
import App from '../../App';
44

55
export const renderApp = () => {
6-
const { getByTestId } = render(<App />);
6+
const { getByTestId, getByText } = render(<App />);
77

88
const roundInput = getByTestId('rounds-input');
99
const workIntervalMinuteInput = getByTestId('work-interval-input-minutes');
@@ -22,5 +22,6 @@ export const renderApp = () => {
2222
startButton,
2323
prepTime,
2424
getByTestId,
25+
getByText,
2526
};
2627
};

0 commit comments

Comments
 (0)