|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupAuthentication } from 'ilios-common'; |
| 3 | +import { setupRenderingTest } from 'test-app/tests/helpers'; |
| 4 | +import { render } from '@ember/test-helpers'; |
| 5 | +import { setupMirage } from 'test-app/tests/test-support/mirage'; |
| 6 | +import { DateTime } from 'luxon'; |
| 7 | +import { component } from 'ilios-common/page-objects/components/offering-manager'; |
| 8 | +import noop from 'ilios-common/helpers/noop'; |
| 9 | +import OfferingManager from 'ilios-common/components/offering-manager'; |
| 10 | + |
| 11 | +module('Integration | Component | offering-manager', function (hooks) { |
| 12 | + setupRenderingTest(hooks); |
| 13 | + setupMirage(hooks); |
| 14 | + |
| 15 | + test('it renders', async function (assert) { |
| 16 | + this.school = this.server.create('school'); |
| 17 | + this.user = await setupAuthentication({ school: this.school }, true); |
| 18 | + const users = this.server.createList('user', 4); |
| 19 | + const today = DateTime.fromObject({ hour: 8 }); |
| 20 | + const course = this.server.create('course'); |
| 21 | + const sessionType = this.server.create('session-type'); |
| 22 | + const session = this.server.create('session', { |
| 23 | + course, |
| 24 | + sessionType, |
| 25 | + }); |
| 26 | + const learnerGroup1 = this.server.create('learner-group'); |
| 27 | + const learnerGroup2 = this.server.create('learner-group'); |
| 28 | + const offering = this.server.create('offering', { |
| 29 | + session, |
| 30 | + startDate: today.toJSDate(), |
| 31 | + endDate: today.plus({ hour: 1 }).toJSDate(), |
| 32 | + room: 'room 123', |
| 33 | + learners: [users[0], users[1]], |
| 34 | + learnerGroups: [learnerGroup1, learnerGroup2], |
| 35 | + instructors: [users[2], users[3]], |
| 36 | + url: 'http://foo.com', |
| 37 | + }); |
| 38 | + |
| 39 | + const offeringModel = await this.owner |
| 40 | + .lookup('service:store') |
| 41 | + .findRecord('offering', offering.id); |
| 42 | + this.set('offering', offeringModel); |
| 43 | + |
| 44 | + await render( |
| 45 | + <template> |
| 46 | + <OfferingManager @offering={{this.offering}} @remove={{(noop)}} @editable={{false}} /> |
| 47 | + </template>, |
| 48 | + ); |
| 49 | + |
| 50 | + assert.strictEqual( |
| 51 | + component.learners, |
| 52 | + '(2) 1 guy M. Mc1son, 2 guy...', |
| 53 | + 'list of learners correct', |
| 54 | + ); |
| 55 | + assert.strictEqual( |
| 56 | + component.learnerGroups[0].title, |
| 57 | + 'learner group 0', |
| 58 | + 'first learner group title is correct', |
| 59 | + ); |
| 60 | + assert.strictEqual( |
| 61 | + component.learnerGroups[1].title, |
| 62 | + 'learner group 1', |
| 63 | + 'second learner group title is correct', |
| 64 | + ); |
| 65 | + assert.strictEqual(component.location, 'room 123', 'offering location is correct'); |
| 66 | + assert.ok(component.hasUrl, 'offering has url'); |
| 67 | + assert.strictEqual(component.url, 'http://foo.com/', 'url is correct'); |
| 68 | + assert.strictEqual( |
| 69 | + component.instructors[0].userNameInfo.fullName, |
| 70 | + '3 guy M. Mc3son', |
| 71 | + 'first instructor name is correct', |
| 72 | + ); |
| 73 | + assert.strictEqual( |
| 74 | + component.instructors[1].userNameInfo.fullName, |
| 75 | + '4 guy M. Mc4son', |
| 76 | + 'second instructor name is correct', |
| 77 | + ); |
| 78 | + }); |
| 79 | +}); |
0 commit comments