Skip to content

Commit

Permalink
Merge pull request #7417 from stopfstedt/session-type-aamc-method
Browse files Browse the repository at this point in the history
fixes state management in school session type manager
  • Loading branch information
dartajax committed Sep 19, 2023
2 parents 635fe10 + d8cdeaa commit 425a17f
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/components/school-session-type-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class SchoolSessionTypeFormComponent extends Component {
if (!isValid) {
return false;
}
this.clearErrorDisplay();
yield this.args.save(
this.title,
this.calendarColor,
Expand All @@ -83,7 +84,6 @@ export default class SchoolSessionTypeFormComponent extends Component {
this.selectedAamcMethod,
this.isActive,
);
this.clearErrorDisplay();
}

@dropTask
Expand Down
3 changes: 1 addition & 2 deletions app/components/school-session-type-manager.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div
class="school-session-type-manager"
{{did-insert (perform this.load)}}
{{did-update (perform this.load) @sessionType}}
data-test-school-session-type-manager
...attributes
>
Expand All @@ -23,7 +22,7 @@
@canEditAssessmentOption={{and @canUpdate (eq @sessionType.sessionCount 0)}}
@canEditActive={{@canUpdate}}
@canUpdate={{@canUpdate}}
@save={{perform this.save}}
@save={{@save}}
@close={{@close}}
/>
{{else}}
Expand Down
1 change: 1 addition & 0 deletions app/components/school-session-types-expanded.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<SchoolSessionTypeManager
@sessionType={{this.managedSessionType}}
@close={{fn @setSchoolManagedSessionType null}}
@save={{perform this.update}}
@canUpdate={{@canUpdate}}
/>
{{else if (and (is-array this.sessionTypes) this.sessionTypes.length)}}
Expand Down
17 changes: 17 additions & 0 deletions app/components/school-session-types-expanded.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@ export default class SchoolSessionTypesExpandedComponent extends Component {

yield sessionType.save();
}

@dropTask
*update(title, calendarColor, assessment, assessmentOption, aamcMethod, isActive) {
const aamcMethods = aamcMethod ? [aamcMethod] : [];
const sessionType = this.managedSessionType;
this.args.setSchoolManagedSessionType(null);
sessionType.setProperties({
title,
calendarColor,
assessment,
assessmentOption,
aamcMethods,
active: isActive,
});

yield sessionType.save();
}
}
105 changes: 105 additions & 0 deletions tests/acceptance/school/session-types-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { module, test } from 'qunit';
import { setupAuthentication } from 'ilios-common';
import { setupApplicationTest } from 'ember-qunit';
import { currentURL } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import page from 'ilios/tests/pages/school';

// @todo flesh out test coverage - the full CRUD, read-only mode, etc [ST 2023/09/18]
module('Acceptance | School - Session Types', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);

hooks.beforeEach(async function () {
const school = this.server.create('school');
this.school = school;
this.formative = this.server.create('assessment-option', {
name: 'formative',
});
this.summative = this.server.create('assessment-option', {
name: 'summative',
});
await setupAuthentication({ school, administeredSchools: [school] }, true);
});

test('update session type', async function (assert) {
const aamcMethods = [
this.server.create('aamc-method', { id: 'AM001', description: 'Celebration', active: true }),
this.server.create('aamc-method', { id: 'AM002', description: 'Lecture', active: true }),
];
this.server.create('session-type', {
title: 'one',
calendarColor: '#cc0000',
assessment: true,
assessmentOption: this.summative,
aamcMethods: [aamcMethods[0]],
school: this.school,
});

await page.visit({ schoolId: this.school.id });
assert.strictEqual(currentURL(), '/schools/1');

await page.manager.schoolSessionTypesCollapsed.expand();
assert.strictEqual(currentURL(), '/schools/1?schoolSessionTypeDetails=true');

assert.strictEqual(page.manager.schoolSessionTypesExpanded.list.sessionTypes.length, 1);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].title.text,
'one',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].sessionCount,
'0',
);
assert.ok(page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].isAssessment);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].assessmentOption,
'summative',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].aamcMethod,
'Celebration',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].calendarColor,
'background-color: #cc0000',
);

await page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].manage();
assert.strictEqual(
currentURL(),
'/schools/1?schoolManagedSessionType=1&schoolSessionTypeDetails=true',
);
await page.manager.schoolSessionTypesExpanded.manager.form.title.set('lorem ipsum');
await page.manager.schoolSessionTypesExpanded.manager.form.aamcMethod.select(aamcMethods[1].id);
await page.manager.schoolSessionTypesExpanded.manager.form.calendarColor.set('#000000');
await page.manager.schoolSessionTypesExpanded.manager.form.assessmentSelector.select(
this.formative.id,
);
await page.manager.schoolSessionTypesExpanded.manager.form.submit.click();

assert.strictEqual(currentURL(), '/schools/1?schoolSessionTypeDetails=true');

assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].title.text,
'lorem ipsum',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].sessionCount,
'0',
);
assert.ok(page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].isAssessment);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].assessmentOption,
'formative',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].aamcMethod,
'Lecture',
);
assert.strictEqual(
page.manager.schoolSessionTypesExpanded.list.sessionTypes[0].calendarColor,
'background-color: #000000',
);
});
});

0 comments on commit 425a17f

Please sign in to comment.