Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Unit test patient model mixin (#879)
Browse files Browse the repository at this point in the history
* Add unit model test for patient

- Add unit model test for patient

* Add mixin unit test fro patient-name

- Add mixin unit test fro patient-name

* Add displayPatientName test for patient-name mixin

- Add displayPatientName test for patient-name mixin
  • Loading branch information
mkly authored and jkleinsc committed Dec 19, 2016
1 parent 4d20f8a commit 0b61f2f
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
108 changes: 108 additions & 0 deletions tests/unit/mixins/patient-name-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import PatientName from 'hospitalrun/mixins/patient-name';
import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';
import DS from 'ember-data';

moduleFor('mixin:patient-name', 'Unit | Mixin | patient-name', {
needs: [
'model:patient',
'model:allergy',
'model:payment',
'model:price-profile'
],
subject(attrs) {
let subject;
Ember.run(() => {
let Test = DS.Model.extend(PatientName);
this.register('model:test', Test);
subject = this.store().createRecord('test', attrs);
});

return subject;
},
store() {
return this.container.lookup('service:store');
}
});

test('getPatientDisplayId friendlyId', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
friendlyId: 'test',
id: '123'
});
});

assert.strictEqual(this.subject().getPatientDisplayId(patient), 'test');
});

test('getPatientDisplayId externalPatientId', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
externalPatientId: '1234',
id: '4321'
});
});

assert.strictEqual(this.subject().getPatientDisplayId(patient), '1234');
});

test('getPatientDisplayId id', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
id: '9876'
});
});

assert.strictEqual(this.subject().getPatientDisplayId(patient), '9876');
});

test('getPatientDisplayName', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
firstName: 'First',
lastName: 'Last',
middleName: 'Middle'
});
});

assert.strictEqual(this.subject().getPatientDisplayName(patient), 'First Middle Last');
});

test('getPatientDisplayName first', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
firstName: 'First'
});
});

assert.strictEqual(this.subject().getPatientDisplayName(patient), 'First');
});

test('getPatientDisplayName first and last', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
firstName: 'First',
lastName: 'Last'
});
});

assert.strictEqual(this.subject().getPatientDisplayName(patient), 'First Last');
});

test('getPatientDisplayName last', function(assert) {
let patient;
Ember.run(() => {
patient = this.store().createRecord('patient', {
lastName: 'Last'
});
});

assert.strictEqual(this.subject().getPatientDisplayName(patient), 'Last');
});
40 changes: 40 additions & 0 deletions tests/unit/models/patient-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { moduleForModel, test } from 'ember-qunit';
import Ember from 'ember';
import tHelper from 'ember-i18n/helper';
import localeConfig from 'ember-i18n/config/en';

moduleForModel('patient', 'Unit | Model | patient', {
needs: [
'ember-validations@validator:local/format',
'ember-validations@validator:local/presence',
'model:allergy',
'model:payment',
'model:price-profile',
'service:i18n',
'locale:en/translations',
'locale:en/config',
'util:i18n/missing-message',
'util:i18n/compile-template',
'config:environment'
],
beforeEach() {
// set the locale and the config
this.container.lookup('service:i18n').set('locale', 'en');
this.registry.register('locale:en/config', localeConfig);

Ember.getOwner(this).inject('model', 'i18n', 'service:i18n');

// register t helper
this.registry.register('helper:t', tHelper);
}
});

test('displayAddress', function(assert) {
let patient = this.subject({
address: '123 Main St.',
address2: 'Apt #2',
address4: 'Test'
});

assert.strictEqual(patient.get('displayAddress'), '123 Main St., Apt #2, Test');
});

0 comments on commit 0b61f2f

Please sign in to comment.