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

Week at a Glance now translates month names when displaying #8001

Merged
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions packages/ilios-common/addon/components/week-glance.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,23 @@ export default class WeeklyGlance extends Component {
return '';
}

const from = this.midnightAtTheStartOfTheWeekDateTime.toFormat('MMMM d');
const from =
this.intl.formatDate(this.midnightAtTheStartOfTheWeekDateTime, { month: 'long' }) +
' ' +
this.midnightAtTheStartOfTheWeekDateTime.toFormat('d');

let to = this.midnightAtTheEndOfTheWeekDateTime.toFormat('d');

if (
!this.midnightAtTheStartOfTheWeekDateTime.hasSame(
this.midnightAtTheEndOfTheWeekDateTime,
'month',
)
) {
to = this.midnightAtTheEndOfTheWeekDateTime.toFormat('MMMM d');
to =
this.intl.formatDate(this.midnightAtTheEndOfTheWeekDateTime, { month: 'long' }) +
' ' +
this.midnightAtTheEndOfTheWeekDateTime.toFormat('d');
return `${from} - ${to}`;
}
return `${from}-${to}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'test-app/tests/test-support/mirage';
import { component } from 'ilios-common/page-objects/components/week-glance';
import { a11yAudit } from 'ember-a11y-testing/test-support';
import { setLocale, setupIntl } from 'ember-intl/test-support';

module('Integration | Component | week glance', function (hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);
setupIntl(hooks, 'en-us');

const testDate = DateTime.fromObject({
year: 2017,
month: 1,
Expand Down Expand Up @@ -79,22 +82,26 @@ module('Integration | Component | week glance', function (hooks) {
});

this.getTitle = function (fullTitle) {
this.intl = this.owner.lookup('service:intl');
const ld = this.owner.lookup('service:locale-days');
const startOfWeek = DateTime.fromJSDate(ld.firstDayOfDateWeek(testDate.toJSDate()));
const endOfWeek = DateTime.fromJSDate(ld.lastDayOfDateWeek(testDate.toJSDate()));

let expectedTitle;
if (startOfWeek.month != endOfWeek.month) {
const from = startOfWeek.toFormat('MMMM d');
const to = endOfWeek.toFormat('MMMM d');
const from =
this.intl.formatDate(startOfWeek, { month: 'long' }) + ' ' + startOfWeek.toFormat('d');
const to =
this.intl.formatDate(endOfWeek, { month: 'long' }) + ' ' + endOfWeek.toFormat('d');
expectedTitle = `${from} - ${to}`;
} else {
const from = startOfWeek.toFormat('MMMM d');
const from =
this.intl.formatDate(startOfWeek, { month: 'long' }) + ' ' + startOfWeek.toFormat('d');
const to = endOfWeek.toFormat('d');
expectedTitle = `${from}-${to}`;
}
if (fullTitle) {
expectedTitle += ' Week at a Glance';
expectedTitle += ' ' + this.intl.t('general.weekAtAGlance');
}

return expectedTitle;
Expand Down Expand Up @@ -206,7 +213,7 @@ module('Integration | Component | week glance', function (hooks) {
assert.ok(true, 'no a11y errors found!');
});

test('click to expend', async function (assert) {
test('click to expand', async function (assert) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😀

assert.expect(1);
this.owner.register('service:user-events', this.blankEventsMock);
this.userEvents = this.owner.lookup('service:user-events');
Expand Down Expand Up @@ -317,4 +324,24 @@ module('Integration | Component | week glance', function (hooks) {

return settled();
});

test('title month is properly translated', async function (assert) {
this.set('today', testDate.toJSDate());
this.set('week', testDate.weekNumber);
await render(hbs`<WeekGlance
@collapsible={{true}}
@collapsed={{true}}
@showFullTitle={{true}}
@year={{format-date this.today year="numeric"}}
@week={{this.week}}
/>`);

assert.strictEqual(component.title, this.getTitle(true));

await setLocale('es');
assert.strictEqual(component.title, this.getTitle(true));

await setLocale('fr');
assert.strictEqual(component.title, this.getTitle(true));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { setupRenderingTest } from 'test-app/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { component } from 'ilios-common/page-objects/components/weekly-events';
import { setLocale, setupIntl } from 'ember-intl/test-support';

module('Integration | Component | weekly events', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks, 'en-us');

test('it renders', async function (assert) {
this.intl = this.owner.lookup('service:intl');
this.set('year', 2017);
await render(hbs`<WeeklyEvents
@year={{this.year}}
Expand All @@ -23,6 +26,14 @@ module('Integration | Component | weekly events', function (hooks) {
assert.strictEqual(component.bottomNavigation.previousYear.title, 'Go to previous year');
assert.strictEqual(component.bottomNavigation.nextYear.title, 'Go to next year');
assert.strictEqual(component.weeks.length, 52);

assert.strictEqual(component.weeks[0].title, 'January 1-7');

await setLocale('es');
assert.strictEqual(component.weeks[0].title, 'enero 2-8');

await setLocale('fr');
assert.strictEqual(component.weeks[0].title, 'janvier 2-8');
});

test('top navigation - go to next year', async function (assert) {
Expand Down