Skip to content

Commit

Permalink
ZKUI-376: Add test for the expiration of previous version
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengYanJin committed Sep 8, 2023
1 parent eaf57c5 commit 38ea551
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/js/mock/managementClientMSWHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const TRANSITION_WORKFLOW_CURRENT_ID =
'0d55a1d7-349c-4e79-932b-b502bcc45a8f';
export const TRANSITION_WORKFLOW_PREVIOUS_ID =
'1e55a1d7-349c-4e79-932b-b502bcc45a8f';
export const EXPIRATION_WORKFLOW_ID = '330f2359-dc93-4abd-97c1-37c8483b1872';
export const TRIGGER_DELAY_DAYS = 15;
export const COLD_LOCATION_NAME = 'europe25-myroom-cold';

Expand Down Expand Up @@ -266,6 +267,18 @@ export const getColdStorageHandlers = (baseUrl: string, instanceId: string) => [
enabled: true,
},
},
{
expiration: {
bucketName: BUCKET_NAME,
enabled: true,
filter: {
objectTags: null,
},
type: 'bucket-workflow-expiration-v1',
workflowId: EXPIRATION_WORKFLOW_ID,
previousVersionTriggerDelayDays: 7,
},
},
]),
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/react/workflow/ExpirationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export function ExpirationForm({ prefix = '' }: Props) {
}) => (
<Toggle
disabled={!isSourceBucketVersionned}
id="previousVersionTriggerDelayDaysToggle"
id="expirePreviousVersions"
placeholder="previousVersionDelayDaysToggle"
toggle={
previousVersionTriggerDelayDays !== null &&
Expand Down
41 changes: 38 additions & 3 deletions src/react/workflow/__tests__/Workflows.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import { setupServer } from 'msw/node';
import {
ACCOUNT_ID,
BUCKET_NAME,
EXPIRATION_WORKFLOW_ID,
getColdStorageHandlers,
TRANSITION_WORKFLOW_CURRENT_ID,
TRANSITION_WORKFLOW_PREVIOUS_ID,
} from '../../../js/mock/managementClientMSWHandlers';

import Workflows from '../Workflows';
import {
mockOffsetSize,
queryClient,
renderWithRouterMatch,
TEST_API_BASE_URL,
} from '../../utils/testUtil';
import { mockBucketListing } from '../../../js/mock/S3ClientMSWHandlers';
import {
mockBucketListing,
mockBucketOperations,
} from '../../../js/mock/S3ClientMSWHandlers';

const INSTANCE_ID = '25050307-cd09-4feb-9c2e-c93e2e844fea';
const TEST_ACCOUNT = 'test-account';
Expand Down Expand Up @@ -50,7 +53,7 @@ jest.setTimeout(30000);
describe('Workflows', () => {
beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
mockOffsetSize(200, 800);
mockOffsetSize(200, 1000);
});
afterEach(() => {
server.resetHandlers();
Expand Down Expand Up @@ -136,4 +139,36 @@ describe('Workflows', () => {
),
).toBeInTheDocument();
});

it('should display the correct expiration form', async () => {
//S
server.use(
mockBucketListing([
{
Name: BUCKET_NAME,
CreationDate: new Date('2021-03-18T12:51:44Z'),
},
]),
mockBucketOperations({
isVersioningEnabled: (bucketName) => bucketName === BUCKET_NAME,
}),
);
renderWithRouterMatch(
<Workflows />,
{
path: '/accounts/:accountName/workflows/:workflowId?',
route: `/accounts/${TEST_ACCOUNT}/workflows/expiration-${EXPIRATION_WORKFLOW_ID}`,
},
{ instances: { selectedId: INSTANCE_ID } },
);
//E
await waitFor(() => screen.getByText(TEST_ACCOUNT));
await waitFor(() => screen.queryAllByText(/expiration/i));
//V
expect(
screen.getByRole('checkbox', {
name: /Expire Previous version of objects/i,
}),
).toBeChecked();
});
});

0 comments on commit 38ea551

Please sign in to comment.