forked from HospitalRun/hospitalrun-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin-test.js
158 lines (146 loc) · 4.79 KB
/
admin-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'hospitalrun/tests/helpers/start-app';
module('Acceptance | admin', {
beforeEach() {
this.application = startApp();
},
afterEach() {
Ember.run(this.application, 'destroy');
}
});
test('visiting /admin', function(assert) {
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin');
andThen(function() {
assert.equal(currentURL(), '/admin');
select('.lookup-type', 'Visit Types');
andThen(() => {
assert.equal(find('h3.panel-title').text(), 'Visit Types', 'Visit Types header is displayed');
assert.equal(find('td.lookup-type-value:first').text(), 'Admission', 'Admission visit type displays');
click('button:contains(Update)');
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'List Saved', 'Lookup list is saved');
});
});
});
});
});
test('add new lookup value', function(assert) {
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin');
andThen(function() {
assert.equal(currentURL(), '/admin');
select('.lookup-type', 'Anesthesiologists');
click('button:contains(Add Value)');
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Add Value', 'Add value modal is displayed');
fillIn('.lookup-type-value input', 'Dr Smith');
click('button:contains(Add):last');
andThen(() => {
waitToAppear('td.lookup-type-value:contains(Dr Smith)');
andThen(() => {
assert.equal(find('td.lookup-type-value:contains(Dr Smith)').length, 1, 'Added lookup type is added to list');
});
});
});
});
});
});
test('delete lookup value', function(assert) {
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin');
andThen(function() {
assert.equal(currentURL(), '/admin');
select('.lookup-type', 'Anesthesia Types');
andThen(() => {
assert.equal(find('td.lookup-type-value:contains(Epidural)').length, 1, 'Have lookup type to delete from list');
click('button:contains(Delete)');
waitToAppear('.modal-dialog');
});
andThen(() => {
assert.equal(find('.modal-title').text(), 'Delete Value', 'Delete value modal is displayed');
click('.modal-footer button:contains(Ok)');
});
andThen(() => {
assert.equal(find('td.lookup-type-value:contains(Epidural)').length, 0, 'Deleted lookup type is removed from the list');
});
});
});
});
test('Update address options', function(assert) {
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin/address');
andThen(function() {
assert.equal(currentURL(), '/admin/address');
fillIn('input', 'Address Label');
click('button:contains(Update)');
andThen(() => {
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Options Saved', 'Address Options Saved');
});
});
});
});
});
test('Update header options', function(assert) {
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin/print-header');
andThen(function() {
assert.equal(currentURL(), '/admin/print-header');
fillIn('input', 'Print Header Label');
click('button:contains(Update)');
andThen(() => {
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Options Saved', 'Header Options Saved');
});
});
});
});
});
test('Update workflow options', function(assert) {
let selector = 'input[type=checkbox]';
runWithPouchDump('admin', function() {
authenticateUser();
visit('/admin/workflow');
andThen(() => {
assert.equal(currentURL(), '/admin/workflow', 'Correctly navigated to admin workflow');
setAllTo(false, () => {
visit('/admin/workflow');
andThen(() => {
setAllTo(true);
});
});
});
});
function setAllTo(checked, cb) {
Array.prototype.slice.call(document.querySelectorAll(selector)).forEach((node) => {
node.checked = checked;
});
click('button:contains(Update)');
andThen(() => {
waitToAppear('.modal-dialog');
andThen(() => {
assert.equal(find('.modal-title').text(), 'Options Saved', 'Workflow Options Saved');
verifyAll(checked);
if (cb) {
cb();
}
});
});
}
function verifyAll(checked) {
Array.prototype.slice.call(document.querySelectorAll(selector)).forEach((node) => {
assert.equal(node.checked, checked, `Checkbox is ${(checked ? 'checked' : 'unchecked')}`);
});
}
});