Skip to content

Commit

Permalink
MNT Update jest tests for archive text
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 8, 2023
1 parent fa0fef2 commit 5113f5d
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 128 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/lang/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"AssetAdmin.BACK_DESCRIPTION": "Navigate up a level",
"AssetAdmin.BULK_ACTIONS_CONFIRM": "Are you sure you want to %s these files?",
"AssetAdmin.BULK_ACTIONS_ARCHIVE": "Archive",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM": "You're about to archive %s file(s) which may be used in your site's content. Carefully check the file usage on the files before archiving the folder.",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM": "You're about to archive %s file(s) which may be used in your site's content. Carefully check the file usage on the files before archiving the file(s).",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FAIL_02": "%s folders/files were successfully archived, but %s files were not able to be archived.",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDER_CONFIRM": "Are you sure you want to archive this folder?",
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDERS_CONFIRM": "Are you sure you want to archive these folders?",
Expand All @@ -17,7 +17,7 @@
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDER": "These folders contain files which are currently in use, you must move or delete their contents before you can delete the folder.",
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDER_CONFIRM": "Are you sure you want to delete this folder?",
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDERS_CONFIRM": "Are you sure you want to delete these folders?",
"AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM": "You're about to delete %s file(s) which may be used in your site's content. Carefully check the file usage on the files before deleting the folder.",
"AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM": "You're about to delete %s file(s) which may be used in your site's content. Carefully check the file usage on the files before deleting the file(s).",
"AssetAdmin.BULK_ACTIONS_DELETE_MULTI_CONFIRM": "There are %s files currently in use, are you sure you want to delete these files?",
"AssetAdmin.BULK_ACTIONS_DELETE_SINGLE_CONFIRM": "This file is currently in use in %s places, are you sure you want to delete it?",
"AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS": "%s folders/files were successfully archived.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ BulkDeleteConfirmation.propTypes = {
onCancel: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
archiveFiles: PropTypes.bool,
};

BulkDeleteConfirmation.defaultProps = {
archiveFiles: false
archiveFiles: PropTypes.bool.isRequired,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const confirmationMessage = (
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM';
let transDefault = [
"You're about to delete %s file(s) which may be used in your site's content.",
'Carefully check the file usage on the files before deleting the folder.'
'Carefully check the file usage on the files before deleting the file(s).'
].join(' ');
if (archiveFiles) {
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM';
transDefault = [
"You're about to archive %s file(s) which may be used in your site's content.",
'Carefully check the file usage on the files before archiving the folder.'
'Carefully check the file usage on the files before archiving the file(s).'
].join(' ');
}
return i18n.sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ DeletionModal.propTypes = {
handler: PropTypes.func,
color: PropTypes.string
})),
archiveFiles: PropTypes.bool,
};

DeletionModal.defaultProps = {
archiveFiles: false
archiveFiles: PropTypes.bool.isRequired,
};

export default DeletionModal;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from 'react';
import { Component } from '../BulkDeleteConfirmation';
import ShallowRenderer from 'react-test-renderer/shallow';

describe('BulkDeleteMessage', () => {
describe('BulkDeleteConfirmation', () => {
const renderer = new ShallowRenderer();

const FOLDER = 'folder';
Expand All @@ -28,10 +28,11 @@ describe('BulkDeleteMessage', () => {
onCancel: jest.fn(),
onModalClose: jest.fn(),
onConfirm: jest.fn(),
archiveFiles: false
};
});

it('Nothing in use', () => {
it('Nothing in use - delete', () => {
renderer.render(<Component {...props} files={files.slice(0, 2)} />);
const { props: { isOpen, actions } } = renderer.getRenderOutput();

Expand All @@ -45,20 +46,46 @@ describe('BulkDeleteMessage', () => {
expect(props.onCancel.mock.calls.length).toBe(0);
});

it('Folder in use', () => {
it('Nothing in use - archive', () => {
renderer.render(<Component
{...{
...props,
archiveFiles: true
}}
files={files.slice(0, 2)}
/>);
const { props: { actions } } = renderer.getRenderOutput();
expect(actions[0].label).toBe('Archive');
});

it('Folder in use - delete', () => {
renderer.render(<Component {...props} files={files} fileUsage={{ 1: 5 }} />);
const { props: { isOpen, actions } } = renderer.getRenderOutput();

expect(isOpen).toBe(true);
expect(actions.length).toBe(2);
expect(actions[0].label).toBe('Cancel');
expect(actions[1].label).toBe('Delete');

actions[0].handler();
expect(props.onConfirm.mock.calls.length).toBe(0);
expect(props.onCancel.mock.calls.length).toBe(1);
});

it('Files in use', () => {
it('Folder in use - archive', () => {
renderer.render(<Component
{...{
...props,
archiveFiles: true
}}
files={files}
fileUsage={{ 1: 5 }}
/>);
const { props: { actions } } = renderer.getRenderOutput();
expect(actions[1].label).toBe('Archive');
});

it('Files in use - delete', () => {
renderer.render(<Component {...props} files={files} fileUsage={{ 3: 5 }} />);
const { props: { isOpen, actions } } = renderer.getRenderOutput();

Expand All @@ -71,4 +98,17 @@ describe('BulkDeleteMessage', () => {
expect(props.onConfirm.mock.calls.length).toBe(0);
expect(props.onCancel.mock.calls.length).toBe(1);
});

it('Files in use - archive', () => {
renderer.render(<Component
{...{
...props,
archiveFiles: true
}}
files={files}
fileUsage={{ 3: 5 }}
/>);
const { props: { actions } } = renderer.getRenderOutput();
expect(actions[1].label).toBe('Archive');
});
});
Loading

0 comments on commit 5113f5d

Please sign in to comment.