Skip to content

Commit

Permalink
feat: [AXIMST-517] request within the demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrylo Hudym-Levkovych authored and Kyrylo Hudym-Levkovych committed Feb 26, 2024
1 parent 68d7533 commit a3fb0ab
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/certificates/certificate-signatories/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,16 @@ const messages = defineMessages({
},
uploadImageButton: {
id: 'course-authoring.certificates.signatories.upload.image.button',
defaultMessage: 'Upload signature image',
defaultMessage: '{uploadText} signature image',
},
uploadModal: {
id: 'course-authoring.certificates.signatories.upload.modal',
defaultMessage: 'Upload',
},
uploadModalReplace: {
id: 'course-authoring.certificates.signatories.upload.modal.replace',
defaultMessage: 'Replace',
},
deleteSignatoryConfirmation: {
id: 'course-authoring.certificates.signatories.confirm-modal',
defaultMessage: 'Delete "{name}" from the list of signatories?',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ const SignatoryForm = ({
<span className="x-small">{intl.formatMessage(messages.imageDescription)}</span>
</Form.Control.Feedback>
</Stack>
<Button onClick={open}>{intl.formatMessage(messages.uploadImageButton)}</Button>
<Button onClick={open}>
{intl.formatMessage(
messages.uploadImageButton,
{
uploadText: signatureImagePath
? intl.formatMessage(messages.uploadModalReplace)
: intl.formatMessage(messages.uploadModal),
},
)}
</Button>
</Stack>
</Form.Group>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ import SignatoryForm from './SignatoryForm';

let store;

jest.mock('@edx/frontend-platform/i18n', () => ({
...jest.requireActual('@edx/frontend-platform/i18n'),
useIntl: () => ({
formatMessage: (message) => message.defaultMessage,
}),
getConfig: () => ({ STUDIO_BASE_URL: 'http://localhost' }),
}));

const renderSignatory = (props) => render(
<Provider store={store}>
<IntlProvider locale="en">
Expand Down Expand Up @@ -83,11 +75,14 @@ describe('Signatory Component', () => {

it('opens image upload modal on button click', () => {
const { getByRole, queryByRole } = renderSignatory(defaultProps);
const uploadButton = getByRole('button', { name: messages.uploadImageButton.defaultMessage });
const replaceButton = getByRole(
'button',
{ name: messages.uploadImageButton.defaultMessage.replace('{uploadText}', messages.uploadModalReplace.defaultMessage) },
);

expect(queryByRole('presentation')).not.toBeInTheDocument();

userEvent.click(uploadButton);
userEvent.click(replaceButton);

expect(getByRole('presentation')).toBeInTheDocument();
});
Expand Down Expand Up @@ -120,4 +115,47 @@ describe('Signatory Component', () => {

expect(deleteIcon).not.toBeInTheDocument();
});

it('renders button with Replace text if there is a signatureImagePath', () => {
const newProps = {
...defaultProps,
isEdit: false,
};

const { getByRole, queryByRole } = renderSignatory(newProps);

const replaceButton = getByRole(
'button',
{ name: messages.uploadImageButton.defaultMessage.replace('{uploadText}', messages.uploadModalReplace.defaultMessage) },
);
const uploadButton = queryByRole(
'button',
{ name: messages.uploadImageButton.defaultMessage.replace('{uploadText}', messages.uploadModal.defaultMessage) },
);

expect(replaceButton).toBeInTheDocument();
expect(uploadButton).not.toBeInTheDocument();
});

it('renders button with Upload text if there is no signatureImagePath', () => {
const newProps = {
...defaultProps,
signatureImagePath: '',
isEdit: false,
};

const { getByRole, queryByRole } = renderSignatory(newProps);

const uploadButton = getByRole(
'button',
{ name: messages.uploadImageButton.defaultMessage.replace('{uploadText}', messages.uploadModal.defaultMessage) },
);
const replaceButton = queryByRole(
'button',
{ name: messages.uploadImageButton.defaultMessage.replace('{uploadText}', messages.uploadModalReplace.defaultMessage) },
);

expect(uploadButton).toBeInTheDocument();
expect(replaceButton).not.toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/generic/modal-dropzone/useModalDropzone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const useModalDropzone = ({

setTimeout(() => {
onClose();
}, 1000);
}, 0);
}
} catch (error) {
onSavingStatus({ status: RequestStatus.FAILED });
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/es_419.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/fa_IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/fr_CA.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/pt_PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/uk.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/messages/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,9 @@
"course-authoring.certificates.signatories.image.label": "Signature image",
"course-authoring.certificates.signatories.image.placeholder": "Path to signature image",
"course-authoring.certificates.signatories.image.description": "Image must be in PNG format",
"course-authoring.certificates.signatories.upload.image.button": "Upload signature image",
"course-authoring.certificates.signatories.upload.image.button": "{uploadText} signature image",
"course-authoring.certificates.signatories.upload.modal": "Upload",
"course-authoring.certificates.signatories.upload.modal.replace": "Replace",
"course-authoring.certificates.signatories.confirm-modal": "Delete \"{name}\" from the list of signatories?",
"course-authoring.certificates.signatories.confirm-modal.message": "This action cannot be undone.",
"course-authoring.certificates.modal-dropzone.text": "Drag and drop your image here or click to upload",
Expand Down

0 comments on commit a3fb0ab

Please sign in to comment.