Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix date formatting for unit tests. #217

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions test/unit/blocks/edit/da-versions/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { expect } from '@esm-bundle/chai';
import { formatDate, formatVersions } from '../../../../../blocks/edit/da-versions/helpers.js';

const TIME_OPTS = { hour: 'numeric', minute: '2-digit' };
const DATE_OPTS = { year: 'numeric', month: 'short', day: 'numeric' };

describe('Versions helper', () => {
it('Format date', () => {
const { date: d, time: t } = formatDate(1709205071123);
expect(d).to.equal('February 29, 2024');

expect(d).to.equal(new Date(1709205071123).toLocaleDateString([], DATE_OPTS));
expect(t).to.equal(new Date(1709205071123).toLocaleTimeString([], TIME_OPTS));
});

Expand All @@ -23,8 +25,8 @@ describe('Versions helper', () => {
}

expect(before).to.deep.equal(after);
const expectedDate = now.toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' });
const expectedTime = now.toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
const expectedDate = now.toLocaleDateString(undefined, DATE_OPTS);
const expectedTime = now.toLocaleTimeString(undefined, TIME_OPTS);
expect(expectedDate).to.equal(after.date);
expect(expectedTime).to.equal(after.time);
});
Expand Down Expand Up @@ -63,25 +65,25 @@ describe('Versions helper', () => {
const formatted = formatVersions(versions);

const expected = [{
date: 'May 15, 2024',
date: new Date(1715766906908).toLocaleDateString([], DATE_OPTS),
audits: [{
date: 'May 15, 2024',
date: new Date(1715766906908).toLocaleDateString([], DATE_OPTS),
time: new Date(1715766906908).toLocaleTimeString([], TIME_OPTS),
users: [{ email: '[email protected]' }, { email: 'anonymous' }],
timestamp: 1715766906908,
path: 'da-aem-boilerplate/blah7.html',
isVersion: false,
},
{
date: 'May 15, 2024',
date: new Date(1715766405165).toLocaleDateString([], DATE_OPTS),
time: new Date(1715766405165).toLocaleTimeString([], TIME_OPTS),
users: [{ email: '[email protected]' }],
timestamp: 1715766405165,
path: 'da-aem-boilerplate/blah7.html',
isVersion: false,
}],
}, {
date: 'May 15, 2024',
date: new Date(1715766894180).toLocaleDateString([], DATE_OPTS),
time: new Date(1715766894180).toLocaleTimeString([], TIME_OPTS),
url: '/versionsource/joey/ghi.html',
users: [{ email: '[email protected]' }],
Expand All @@ -90,25 +92,25 @@ describe('Versions helper', () => {
label: 'hello',
isVersion: true,
}, {
date: 'May 14, 2024',
date: new Date(1715701875589).toLocaleDateString([], DATE_OPTS),
audits: [{
date: 'May 14, 2024',
date: new Date(1715701875589).toLocaleDateString([], DATE_OPTS),
time: new Date(1715701875589).toLocaleTimeString([], TIME_OPTS),
users: [{ email: 'anonymous' }],
timestamp: 1715701875589,
path: 'da-aem-boilerplate/blah7.html',
isVersion: false,
}],
}, {
date: 'May 13, 2024',
date: new Date(1715594902707).toLocaleDateString([], DATE_OPTS),
time: new Date(1715594902707).toLocaleTimeString([], TIME_OPTS),
url: '/versionsource/joey/def.html',
users: [{ email: 'anonymous' }],
timestamp: 1715594902707,
path: 'da-aem-boilerplate/blah7.html',
isVersion: true,
}, {
date: 'May 13, 2024',
date: new Date(1715594886177).toLocaleDateString([], DATE_OPTS),
time: new Date(1715594886177).toLocaleTimeString([], TIME_OPTS),
url: '/versionsource/joey/abc.html',
users: [{ email: 'anonymous' }],
Expand Down
Loading