summaryrefslogtreecommitdiff
path: root/extensions/mistral/test/js/workbook.controller.spec.js
blob: c2ce5eef47c136dd9dade153db826c2f9cc9c155 (plain)
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

/*    Copyright (c) 2015 Mirantis, Inc.

 Licensed under the Apache License, Version 2.0 (the "License"); you may
 not use this file except in compliance with the License. You may obtain
 a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 License for the specific language governing permissions and limitations
 under the License.
 */
describe('together workbook model and controller', function() {
  var models, utils, workbook;

  beforeEach(function () {
    module('mistral');
    inject(function ($injector) {
      models = $injector.get('mistral.workbook.models');
      utils = $injector.get('merlin.utils');
    });
    workbook = models.Workbook.create();
  });


  describe('define top-level actions available to user:', function () {
    var wbCtrl;

    beforeEach(inject(function (_$controller_) {
      wbCtrl = _$controller_('WorkbookController', {});
      wbCtrl.workbook = workbook;
    }));

    describe("'Add Action' action", function () {
      it('adds a new Action', function () {
        wbCtrl.addAction();

        expect(workbook.get('actions').get(0)).toBeDefined();
      });

      it('creates action with predefined name', function () {
        wbCtrl.addAction();

        expect(workbook.get('actions').get(0).getID()).toBeGreaterThan('');
      });

      describe('', function () {
        var actionID;
        beforeEach(inject(function (baseActionID) {
          actionID = baseActionID + '1';
        }));

        it("corresponding JSON has the right key for the Action", function () {
          wbCtrl.addAction();

          expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeDefined();
        });

        it("once the Action ID is changed, it's reflected in JSON", function () {
          var newID = 'action10';

          wbCtrl.addAction();
          workbook.get('actions').getByID(actionID).setID(newID);

          expect(workbook.toJSON({pretty: true}).actions[actionID]).toBeUndefined();
          expect(workbook.toJSON({pretty: true}).actions[newID]).toBeDefined();
        });

      });

      it('creates actions with different names on 2 successive calls', function () {
        wbCtrl.addAction();
        wbCtrl.addAction();

        expect(workbook.get('actions').get(0).getID()).not.toEqual(
          workbook.get('actions').get(1).getID())
      });
    });

    describe("'Add Workflow' action", function () {
      it('adds a new Workflow', function () {
        wbCtrl.addWorkflow();

        expect(workbook.get('workflows').get(0)).toBeDefined();
      });

      describe('', function () {
        var workflowID;
        beforeEach(inject(function (baseWorkflowID) {
          workflowID = baseWorkflowID + '1';
        }));

        it("corresponding JSON has the right key for the Workflow", function () {
          wbCtrl.addWorkflow();

          expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeDefined();
        });

        it("once the workflow ID is changed, it's reflected in JSON", function () {
          var newID = 'workflow10';

          wbCtrl.addWorkflow();
          workbook.get('workflows').getByID(workflowID).setID(newID);

          expect(workbook.toJSON({pretty: true}).workflows[workflowID]).toBeUndefined();
          expect(workbook.toJSON({pretty: true}).workflows[newID]).toBeDefined();
        });

      });

      it('creates workflow with predefined name', function () {
        wbCtrl.addWorkflow();

        expect(workbook.get('workflows').get(0).getID()).toBeGreaterThan('');
      });

      it('creates workflows with different names on 2 successive calls', function () {
        wbCtrl.addWorkflow();
        wbCtrl.addWorkflow();

        expect(workbook.get('workflows').get(0).getID()).not.toEqual(
          workbook.get('workflows').get(1).getID())
      });

    });

    describe("'Create'/'Modify'/'Cancel' actions", function () {
      it('edit causes a request to an api and a return to main page', function () {

      });

      it('cancel causes just a return to main page', function () {

      });
    });

  })
});