Skip to content

Commit

Permalink
Merge pull request #8170 from michaelchadwick/frontend-4934-prog-year…
Browse files Browse the repository at this point in the history
…-report-fix

Reports->Terms->Program Year title fixed
  • Loading branch information
dartajax authored Oct 17, 2024
2 parents bdaa1df + 710c8ab commit 4576853
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/frontend/app/services/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@ export default class ReportingService extends Service {
const objectKey = objectTranslations[prepositionalObject];
const objectTranslation = this.intl.t(objectKey);
let object;

if (model === 'user') {
object = record.fullName;
} else if (model === 'mesh-descriptor') {
object = record.name;
} else if (model === 'program-year') {
const program = await record.program;
const title = program.title;
const classOfYear = await record.getClassOfYear();
object = `${classOfYear} ${title}`;
} else {
object = record.title;
}
Expand Down
40 changes: 40 additions & 0 deletions packages/frontend/tests/unit/services/reporting-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupIntl } from 'ember-intl/test-support';
import { setupMirage } from 'frontend/tests/test-support/mirage';
import { DateTime } from 'luxon';

module('Unit | Service | reporting', function (hooks) {
setupTest(hooks);
Expand Down Expand Up @@ -226,6 +227,45 @@ module('Unit | Service | reporting', function (hooks) {
);
});

test('buildReportDescription() - all terms for program year X in school Y', async function (assert) {
const school = this.server.create('school', { title: 'School of Schools' });
const program = this.server.create('program', { school: school });
const programYear = this.server.create('program-year', {
program,
startYear: DateTime.now().year,
});
const vocabulary = this.server.create('vocabulary', { school });
this.server.create('term', {
title: 'foo bar',
programYears: [programYear],
vocabulary,
});
const report = this.server.create('report', {
subject: 'term',
prepositionalObject: 'program year',
prepositionalObjectTableRowId: programYear.id,
school,
});

const store = this.owner.lookup('service:store');
const reportModel = await store.findRecord('report', report.id);
const programYearModel = await store.findRecord('program year', programYear.id);
const schoolModel = await store.findRecord('school', school.id);
const title = await this.service.buildReportDescription(
reportModel.subject,
reportModel.prepositionalObject,
reportModel.prepositionalObjectTableRowId,
school,
);
const classOfYear = await programYearModel.getClassOfYear();
const programYearTitle = `${classOfYear} ${program.title}`;

assert.strictEqual(
title,
`This report shows all Terms associated with Program Year "${programYearTitle}" in ${schoolModel.title}.`,
);
});

test('buildReportDescription() - broken report', async function (assert) {
const school = this.server.create('school', { title: 'School of Schools' });
const report = this.server.create('report', {
Expand Down

0 comments on commit 4576853

Please sign in to comment.