1 /*jshint trailing:true, white:true, indent:2, strict:true, curly:true,
2 immed:true, eqeqeq:true, forin:true, latedef:true,
3 newcap:true, noarg:true, undef:true, expr: true */
4 /*global XT:true, XM:true, XV:true, describe:true, it:true,
5 before:true, beforeEach: true, afterEach: true, module:true,
6 require:true, enyo:true, console:true, setTimeout:true,
7 clearInterval:true, setInterval:true */
12 var _ = require("underscore"),
13 zombieAuth = require("../../lib/zombie_auth"),
14 smoke = require("../../lib/smoke"),
15 common = require("../../lib/common"),
16 modelData = require("../../lib/model_data"),
17 assert = require("chai").assert;
19 describe('Characteristics widgets', function () {
21 before(function (done) {
22 this.timeout(30 * 1000);
23 zombieAuth.loadApp(done);
26 describe(' ', function () {
27 it('should be possible to add one', function (done) {
28 this.timeout(30 * 1000);
29 smoke.navigateToNewWorkspace(XT.app, "XV.ContactList", function (workspaceContainer) {
31 var workspace = workspaceContainer.$.workspace,
32 model = workspace.value,
37 assert.equal(model.recordType, "XM.Contact");
38 smoke.setWorkspaceAttributes(workspace, modelData.contact);
41 // Add a characteristic
43 assert.equal(model.get("characteristics").length, 0);
44 charWidget = workspace.$.contactCharacteristicsWidget;
46 // XXX it'd be better to do this through enyo
47 charModel = _.find(XM.characteristics.models, function (m) {
48 // support masterref and postbooks
49 return m.id === 'CONTACT-BIRTHDAY' || m.id === 'Birthday';
51 assert.isObject(charModel);
52 contactCharModel = charWidget.value.models[0];
53 contactCharModel.set({
54 characteristic: charModel,
59 // On the second save: exit
61 var modelResaved = function (m, status) {
62 if (status === XM.Model.READY_CLEAN) {
63 model.off("statusChange", modelResaved);
64 workspaceContainer.close();
66 setTimeout(function () {
67 assert(XT.app.$.postbooks.getActive().kind, "XV.Navigator");
75 // On the first save: try deleting the characteristic and resaving
77 var modelSaved = function (m, status) {
78 var charItem, picker, deleteItem;
80 if (status === XM.Model.READY_CLEAN) {
81 model.off("statusChange", modelSaved);
82 assert.equal(model.get("characteristics").length, 1);
84 charItem = charWidget.$.repeater.children[0].$.characteristicItem;
85 assert.isObject(charItem);
87 picker = charItem.$.characteristicPicker.$.picker;
88 deleteItem = _.find(picker.$, function (item) {
89 return item.value === null;
91 assert.isFunction(deleteItem.tap);
93 assert.equal(model.get("characteristics").models[0].getStatusString(),
96 model.on("statusChange", modelResaved);
97 workspaceContainer.apply();
101 model.on("statusChange", modelSaved);
102 workspaceContainer.apply();
109 * Test INCDT-21540 fix
111 describe.skip('INCDT-21540: Characteristics appear editable when they shouldn\'t be',
113 var workspaceContainer, workspace, model, id, moduleContainer, originalPrivileges;
115 beforeEach(function () {
116 originalPrivileges = _.clone(XT.session.privileges.attributes);
119 it('test Characteristics widgets for enable/disable capability', function (done) {
120 this.timeout(30 * 1000);
122 smoke.navigateToExistingWorkspace(XT.app, "XV.IncidentList",
123 function (_workspaceContainer) {
124 workspaceContainer = _workspaceContainer;
125 moduleContainer = XT.app.$.postbooks;
128 workspace = workspaceContainer.$.workspace;
129 id = workspace.getValue().id;
130 model = workspace.getValue();
133 _(workspaceContainer.$.workspace.$).filter(function (component) {
134 return component.name.indexOf("Characteristic") !== -1;
136 function (characteristic) {
137 assert.isDefined(characteristic.getDisabled);
138 assert.isFalse(characteristic.getDisabled());
144 it('test with insufficent permissions: fields should be disabled', function (done) {
145 this.timeout(30 * 1000);
147 // revoke permissions
148 _.each(XT.session.privileges.attributes, function (value, privilege) {
149 if (/Maintain/.test(privilege) && /Incident/.test(privilege)) {
150 XT.session.privileges.attributes[privilege] = false;
154 smoke.navigateToExistingWorkspace(XT.app, "XV.IncidentList",
155 function (_workspaceContainer) {
156 workspaceContainer = _workspaceContainer;
157 moduleContainer = XT.app.$.postbooks;
159 workspace = workspaceContainer.$.workspace;
160 id = workspace.getValue().id;
161 model = workspace.getValue();
163 var interval = setInterval(function () {
164 // XXX this busy-guard should be folded into smoke
165 if (!workspaceContainer.hasNode()) { return; }
167 clearInterval(interval);
169 _(workspaceContainer.$.workspace.$).filter(function (component) {
170 return component.name.indexOf("Characteristic") !== -1;
172 function (characteristic) {
173 assert.isDefined(characteristic.getDisabled);
175 characteristic.getDisabled(),
176 "CharacteristicsWidget should be disabled."
179 // Verify that the "New" button is disabled.
181 characteristic.$.newButton.getDisabled(),
182 "Characteristic 'New' button should be disabled.");
184 // Verify that each CharacteristicItem is disabled.
186 characteristic.$.repeater.controls,
189 item.$.characteristicItem.getDisabled(),
190 item.$.characteristicItem.id + " should be disabled."
201 afterEach(function (done) {
202 this.timeout(30 * 1000);
204 // restore permissions
205 _.extend(XT.session.privileges.attributes, originalPrivileges);
207 // maybe one of the tests already released the lock
208 if (!model.hasLockKey()) {
212 model.on("lockChange", function () {
213 model.off("lockChange");
214 assert.isFalse(model.hasLockKey());
216 setTimeout(function () {
220 workspaceContainer.close();