Skip to content

Commit

Permalink
Wizard: snapshot date in wizard should now be RFC3339
Browse files Browse the repository at this point in the history
  • Loading branch information
xbhouse committed Oct 24, 2024
1 parent 493649f commit e5ee679
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export const ContentList = ({
case useLatest:
return 'Use latest';
case !!snapshotDate:
return `State as of ${snapshotDate}`;
return `State as of ${yyyyMMddFormat(new Date(snapshotDate))}`;
default:
return '';
}
Expand Down
4 changes: 3 additions & 1 deletion src/Components/CreateImageWizard/steps/Snapshot/Snapshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function Snapshot() {
<DatePicker
id="snapshot-date-picker"
name="pick-snapshot-date"
value={snapshotDate}
value={
snapshotDate ? yyyyMMddFormat(new Date(snapshotDate)) : ''
}
required
requiredDateOptions={{ isRequired: true }}
placeholder="YYYY-MM-DD"
Expand Down
4 changes: 2 additions & 2 deletions src/Utilities/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ export const parseYYYYMMDDToDate = (val: string) =>
val ? new Date(`${val}T00:00:00`) : new Date('');

export const yyyyMMddFormat = (date: Date) =>
`${date.getFullYear()}-${(date.getMonth() + 1)
`${date.getUTCFullYear()}-${(date.getUTCMonth() + 1)
.toString()
.padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
.padStart(2, '0')}-${date.getUTCDate().toString().padStart(2, '0')}`;

export const toMonthAndYear = (dateString: string) => {
const options: Intl.DateTimeFormatOptions = {
Expand Down
8 changes: 7 additions & 1 deletion src/store/wizardSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,13 @@ export const wizardSlice = createSlice({
state.snapshotting.useLatest = action.payload;
},
changeSnapshotDate: (state, action: PayloadAction<string>) => {
state.snapshotting.snapshotDate = action.payload;
const yyyyMMDDRegex = /^\d{4}-\d{2}-\d{2}$/;
const date = new Date(action.payload);
if (action.payload === '') {
state.snapshotting.snapshotDate = action.payload;
} else if (yyyyMMDDRegex.test(action.payload) && !isNaN(date.getTime())) {
state.snapshotting.snapshotDate = date.toISOString();
}
},
changeCustomRepositories: (
state,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ const clickContentDropdown = async () => {
const getSnapshotMethodElement = async () =>
await screen.findByRole('button', { name: /Snapshot method/i });

const clickReset = async () => {
const user = userEvent.setup();
const resetButton = await screen.findByRole('button', {
name: /Reset/i,
});
await waitFor(async () => user.click(resetButton));
};

describe('repository snapshot tab - ', () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down Expand Up @@ -145,7 +153,8 @@ 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 @@ -196,6 +205,24 @@ describe('repository snapshot tab - ', () => {
expect(bulkSelectCheckbox.closest('div')).toHaveClass('pf-m-disabled');
});

test('button Reset works to empty the snapshot date', async () => {
await renderCreateMode();
await goToSnapshotStep();
await selectUseSnapshot();
await updateDatePickerWithValue('2024-04-22');
// Check the Next button is enabled
const nextBtn = await screen.findByRole('button', { name: /Next/i });
await waitFor(() => {
expect(nextBtn).toHaveAttribute('aria-disabled', 'false');
});
// Check the Next button is disabled after resetting the date
await clickReset();
await waitFor(() => {
expect(nextBtn).toHaveAttribute('aria-disabled', 'true');
});
await screen.findByText(/Date cannot be blank/i);
});

test('select using bulk select works ', async () => {
await renderCreateMode();
await goToSnapshotStep();
Expand All @@ -216,7 +243,8 @@ 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 +265,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 e5ee679

Please sign in to comment.