Skip to content

Commit

Permalink
feat: Validation for Start time and Stop time fields (#419)
Browse files Browse the repository at this point in the history
* feat: fixed fields onblur

* feat: fixed fields onblur

* feat: added new tests
  • Loading branch information
vladislavkeblysh authored Jun 18, 2024
1 parent d2ddc90 commit c84e322
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ export const updateDuration = ({
if (newValue > 86399000) {
newValue = 86399000;
}

// stopTime must not be equal to 24:00:00, so when the user types 23:59:59 in the startTime field and stopTime field -
// set the startTime field to 23:59:58.
if (index === 'stopTime' && duration.startTime === 86399000) {
const startTime = 86399000 - 1000;

setUnsavedDuration({
startTime: module.durationStringFromValue(startTime),
stopTime: module.durationStringFromValue(newValue),
});
setDuration({
...duration,
startTime,
stopTime: newValue,
});

return;
}

// stopTime must be at least 1 second, if not zero
if (index === 'stopTime' && newValue > 0 && newValue < 1000) {
newValue = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ describe('Video Settings DurationWidget hooks', () => {
});
});
});
describe('if the passed stopTime = startTime', () => {
it('sets the startTime value less than stopTime value', () => {
testMethod({
...props,
duration: { startTime: 86399000, stopTime: 86399000 },
unsavedDuration: { startTime: '23:59:59', stopTime: '23:59:59' },
index: testStopIndex,
inputString: '23:59:59',
});
expect(props.setUnsavedDuration).toHaveBeenCalledWith({
startTime: '23:59:58',
stopTime: '23:59:59',
});
expect(props.setDuration).toHaveBeenCalledWith({
...props.duration,
startTime: 86399000 - 1000,
stopTime: 86399000,
});
});
});
});
describe('onDurationChange', () => {
beforeEach(() => {
Expand Down

0 comments on commit c84e322

Please sign in to comment.