Skip to content

Commit c84e322

Browse files
feat: Validation for Start time and Stop time fields (#419)
* feat: fixed fields onblur * feat: fixed fields onblur * feat: added new tests
1 parent d2ddc90 commit c84e322

File tree

2 files changed

+39
-0
lines changed
  • src/editors/containers/VideoEditor/components/VideoSettingsModal/components/DurationWidget

2 files changed

+39
-0
lines changed

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/DurationWidget/hooks.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ export const updateDuration = ({
114114
if (newValue > 86399000) {
115115
newValue = 86399000;
116116
}
117+
118+
// stopTime must not be equal to 24:00:00, so when the user types 23:59:59 in the startTime field and stopTime field -
119+
// set the startTime field to 23:59:58.
120+
if (index === 'stopTime' && duration.startTime === 86399000) {
121+
const startTime = 86399000 - 1000;
122+
123+
setUnsavedDuration({
124+
startTime: module.durationStringFromValue(startTime),
125+
stopTime: module.durationStringFromValue(newValue),
126+
});
127+
setDuration({
128+
...duration,
129+
startTime,
130+
stopTime: newValue,
131+
});
132+
133+
return;
134+
}
135+
117136
// stopTime must be at least 1 second, if not zero
118137
if (index === 'stopTime' && newValue > 0 && newValue < 1000) {
119138
newValue = 1000;

src/editors/containers/VideoEditor/components/VideoSettingsModal/components/DurationWidget/hooks.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,26 @@ describe('Video Settings DurationWidget hooks', () => {
258258
});
259259
});
260260
});
261+
describe('if the passed stopTime = startTime', () => {
262+
it('sets the startTime value less than stopTime value', () => {
263+
testMethod({
264+
...props,
265+
duration: { startTime: 86399000, stopTime: 86399000 },
266+
unsavedDuration: { startTime: '23:59:59', stopTime: '23:59:59' },
267+
index: testStopIndex,
268+
inputString: '23:59:59',
269+
});
270+
expect(props.setUnsavedDuration).toHaveBeenCalledWith({
271+
startTime: '23:59:58',
272+
stopTime: '23:59:59',
273+
});
274+
expect(props.setDuration).toHaveBeenCalledWith({
275+
...props.duration,
276+
startTime: 86399000 - 1000,
277+
stopTime: 86399000,
278+
});
279+
});
280+
});
261281
});
262282
describe('onDurationChange', () => {
263283
beforeEach(() => {

0 commit comments

Comments
 (0)