Skip to content

Commit

Permalink
fix(shared-link-settings-modal): correct expiration date formatting (#…
Browse files Browse the repository at this point in the history
…3545)

* fix(shared-link-settings-modal): correct expiration date formatting

* fix(shared-link-settings-modal): unit tests

* fix(shared-link-settings-modal): unit tests

* fix(shared-link-settings-modal): translations

* fix(shared-link-settings-modal): translations
  • Loading branch information
lukasztyszko authored May 15, 2024
1 parent 79a7b40 commit e47892f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"javascript.validate.enable": false,
"typescript.validate.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
}
}
6 changes: 4 additions & 2 deletions src/features/shared-link-settings-modal/ExpirationSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Fieldset from '../../components/fieldset';

import messages from './messages';

const displayFormat = {
export const defaultDisplayFormat = {
weekday: 'short',
year: 'numeric',
month: 'short',
Expand All @@ -18,6 +18,7 @@ const displayFormat = {
const ExpirationSection = ({
canChangeExpiration,
dateFormat,
dateDisplayFormat = defaultDisplayFormat,
error,
expirationCheckboxProps = {},
expirationDate,
Expand All @@ -31,7 +32,7 @@ const ExpirationSection = ({
<div>
<DatePicker
dateFormat={dateFormat}
displayFormat={displayFormat}
displayFormat={dateDisplayFormat}
error={error}
hideLabel
inputProps={expirationInputProps}
Expand Down Expand Up @@ -65,6 +66,7 @@ const ExpirationSection = ({

ExpirationSection.propTypes = {
canChangeExpiration: PropTypes.bool.isRequired,
dateDisplayFormat: PropTypes.object,
/** The format of the date value for form submit */
dateFormat: PropTypes.string,
error: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ function getAccessNoticeMessageId(accessLevel, canDownload) {

class SharedLinkSettingsModal extends Component {
static propTypes = {
/* Pass dateDisplayFormat to define INTL timezone for formatting date for utc format */
dateDisplayFormat: PropTypes.object,
/** The format of the expiration date value for form submit */
dateFormat: PropTypes.string,
hideVanityNameSection: PropTypes.bool,
Expand Down Expand Up @@ -291,12 +293,19 @@ class SharedLinkSettingsModal extends Component {
}

renderExpirationSection() {
const { canChangeExpiration, dateFormat, expirationCheckboxProps, expirationInputProps } = this.props;
const {
canChangeExpiration,
dateDisplayFormat,
dateFormat,
expirationCheckboxProps,
expirationInputProps,
} = this.props;
const { expirationDate, isExpirationEnabled, expirationError } = this.state;

return (
<ExpirationSection
canChangeExpiration={canChangeExpiration}
dateDisplayFormat={dateDisplayFormat}
dateFormat={dateFormat}
error={expirationError}
expirationCheckboxProps={expirationCheckboxProps}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import sinon from 'sinon';

import ExpirationSection from '../ExpirationSection';
import ExpirationSection, { defaultDisplayFormat } from '../ExpirationSection';

const sandbox = sinon.sandbox.create();

Expand All @@ -12,6 +12,13 @@ describe('features/shared-link-settings-modal/ExpirationSection', () => {
const onCheckboxChange = sandbox.stub();
const onExpirationDateChange = sandbox.stub();

const dateDisplayFormat = {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'Europe/Warsaw',
};

const getWrapper = (props = {}) =>
shallow(
<ExpirationSection
Expand Down Expand Up @@ -104,5 +111,19 @@ describe('features/shared-link-settings-modal/ExpirationSection', () => {

expect(wrapper.prop('dateFormat')).toEqual(dateFormat);
});

test('should use default displayFormat in DatePicker when dateDisplayFormat not defined', () => {
const wrapper = getSubsection();

expect(wrapper.prop('displayFormat')).toEqual(defaultDisplayFormat);
});

test('should pass dateDisplayFormat to DatePicker displayFormat', () => {
const wrapper = getSubsection({
dateDisplayFormat,
});

expect(wrapper.prop('displayFormat')).toEqual(dateDisplayFormat);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('features/shared-link-settings-modal/SharedLinkSettingsModal', () => {
const isDirectLinkAvailable = true;
const isDirectLinkUnavailableDueToDownloadSettings = true;
const isDirectLinkUnavailableDueToAccessPolicy = true;
const isDirectLinkUnavailableDueToMaliciousContent = false;

const getWrapper = (props = {}) =>
shallow(
Expand Down Expand Up @@ -59,6 +60,7 @@ describe('features/shared-link-settings-modal/SharedLinkSettingsModal', () => {
isDirectLinkAvailable={isDirectLinkAvailable}
isDirectLinkUnavailableDueToDownloadSettings={isDirectLinkUnavailableDueToDownloadSettings}
isDirectLinkUnavailableDueToAccessPolicy={isDirectLinkUnavailableDueToAccessPolicy}
isDirectLinkUnavailableDueToMaliciousContent={isDirectLinkUnavailableDueToMaliciousContent}
{...props}
/>,
);
Expand Down Expand Up @@ -244,9 +246,16 @@ describe('features/shared-link-settings-modal/SharedLinkSettingsModal', () => {
test('should render an ExpirationSection', () => {
const dateFormat = 'utcTime';
const expirationDate = new Date('11/7/17');
const dateDisplayFormat = {
day: 'numeric',
month: 'long',
year: 'numeric',
timeZone: 'Europe/Warsaw',
};

const wrapper = getWrapper({
dateFormat,
dateDisplayFormat,
expirationTimestamp: 123,
});

Expand All @@ -260,6 +269,7 @@ describe('features/shared-link-settings-modal/SharedLinkSettingsModal', () => {
expect(section.length).toBe(1);
expect(section.prop('canChangeExpiration')).toEqual(canChangeExpiration);
expect(section.prop('dateFormat')).toEqual(dateFormat);
expect(section.prop('dateDisplayFormat')).toEqual(dateDisplayFormat);
expect(section.prop('expirationDate')).toEqual(expirationDate);
expect(section.prop('isExpirationEnabled')).toBe(true);
expect(section.prop('onCheckboxChange')).toEqual(wrapper.instance().onExpirationCheckboxChange);
Expand Down

0 comments on commit e47892f

Please sign in to comment.