Skip to content

Commit

Permalink
validate date format, fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xbhouse committed Oct 23, 2024
1 parent 3b57ae4 commit f7fee66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/store/wizardSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,12 @@ export const wizardSlice = createSlice({
state.snapshotting.useLatest = action.payload;
},
changeSnapshotDate: (state, action: PayloadAction<string>) => {
const yyyyMMDDRegex = /^\d{4}-\d{2}-\d{2}$/;
const date = new Date(action.payload)
if (action.payload === '') {
state.snapshotting.snapshotDate = action.payload;
} else {
state.snapshotting.snapshotDate = new Date(
action.payload
).toISOString();
} else if (yyyyMMDDRegex.test(action.payload) && !isNaN(date.getTime())) {
state.snapshotting.snapshotDate = date.toISOString();
}
},
changeCustomRepositories: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('repository snapshot tab - ', () => {

// Check the date was passed correctly to the blueprint
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
blueprintRequest.image_requests[0].snapshot_date = '2024-04-22';
blueprintRequest.image_requests[0].snapshot_date = '2024-04-22T00:00:00.000Z';

const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('repository snapshot tab - ', () => {

// Check the date was passed correctly to the blueprint
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
blueprintRequest.image_requests[0].snapshot_date = '2024-04-22';
blueprintRequest.image_requests[0].snapshot_date = '2024-04-22T00:00:00.000Z';

const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
Expand All @@ -237,7 +237,7 @@ describe('repository snapshot tab - ', () => {
await clickNext();
await goToReviewStep();
await clickRevisitButton();
await screen.findByRole('heading', { name: /Custom repositories/ });
await screen.findByRole('heading', { name: /Custom repositories/i });
});
});

Expand Down

0 comments on commit f7fee66

Please sign in to comment.