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

Reports->Terms->Program Year title fixed #8170

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
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