Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / opnfv_testapi / tests / UI / e2e / podsControllerSpec.js
1 'use strict';
2
3 var mock = require('protractor-http-mock');
4 var baseURL = "http://localhost:8000"
5 describe('testing the Pods page for anonymous user', function () {
6
7         beforeEach(function(){
8                 mock([{
9                         request: {
10                           path: '/api/v1/pods',
11                           method: 'GET'
12                         },
13                         response: {
14                                 data: {
15                                         pods: [{role: "community-ci", name: "test", owner: "testUser", details: "DemoDetails", mode: "metal", _id: "59f02f099a07c84bfc5c7aed", creation_date: "2017-10-25 11:58:25.926168"}]
16                                 }
17                         }
18                   }]);
19         });
20
21         it( 'should navigate to pods link ', function() {
22                 browser.get(baseURL);
23                 var podslink = element(by.linkText('Pods')).click();
24                 var EC = browser.ExpectedConditions;
25                 browser.wait(EC.urlContains(baseURL+ '/#/pods'), 10000);
26         });
27
28         it('create button is not visible for anonymous user', function () {
29                 browser.get(baseURL+'#/pods');
30                 var buttonCreate = element(by.buttonText('Create'));
31                 expect(buttonCreate.isDisplayed()).toBeFalsy();
32         });
33
34         it('filter button is visible for anonymous user', function () {
35                 var buttonFilter = element(by.buttonText('Filter'));
36                 expect(buttonFilter.isDisplayed()).toBe(true)
37         });
38
39         it('clear button is visible for anonymous user', function () {
40                 var buttonClear = element(by.buttonText('Clear'));
41                 expect(buttonClear.isDisplayed()).toBe(true)
42         });
43
44         it('Show results when click filter button', function () {
45                 var buttonFilter = element(by.buttonText('Filter'));
46                 buttonFilter.click();
47                 var pod = element(by.css('.show-pod'));
48                 expect(pod.isPresent()).toBe(true);
49         });
50
51         it('Show results when click clear button', function () {
52                 browser.get(baseURL+'#/pods');
53                 var buttonClear = element(by.buttonText('Clear'));
54                 buttonClear.click();
55                 var pod = element(by.css('.show-pod'));
56                 expect(pod.isPresent()).toBe(true);
57         });
58
59         it('If details is not shown then show details when click the link',function() {
60                 expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(true);
61                 var podslink = element(by.linkText('test')).click();
62                 expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(false);
63         });
64
65         it('If details is shown then hide details when click the link',function() {
66                 expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(false);
67                 var podslink = element(by.linkText('test')).click();
68                 expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(true);
69         });
70
71         it('If backend is not responding then show error when click filter button', function () {
72                 browser.get(baseURL + '/#/pods');
73                 mock.teardown();
74                 var buttonFilter = element(by.buttonText('Filter'));
75                 buttonFilter.click().then(function(){
76                         expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope')).isDisplayed()).toBe(true);
77                 });
78         });
79
80 });
81
82 describe('testing the Pods page for authorized user', function () {
83
84         beforeEach(function(){
85                 mock([
86                         {
87                                 request: {
88                                   path: '/api/v1/pods',
89                                   method: 'POST'
90                                 },
91                                 response: {
92                                         data: {
93                                                 href: baseURL+"/api/v1/pods/test"
94                                         }
95                                 }
96                           },
97                           {
98                                 request: {
99                                   path: '/api/v1/pods',
100                                   method: 'POST',
101                                   data: {
102                                         name: 'test1',
103                                         details : 'DemoDetails',
104                                         role : 'community-ci',
105                                         mode : 'metal'
106                                   }
107                                 },
108                                 response: {
109                                         status : 403
110                                 }
111                           },
112                           {
113                                 request: {
114                                 path: '/api/v1/profile',
115                                 method: 'GET'
116                                 },
117                                 response: {
118                                         data: {
119                                                 "fullname": "Test User", "_id": "79f82eey9a00c84bfhc7aed", "user": "testUser", "groups": ["opnfv-testapi-users"], "email": "testuser@test.com"
120                                         }
121                                 }
122                         }
123                 ]);
124         });
125
126         it('create button is visible for authorized user', function () {
127                 browser.get(baseURL + '/#/pods');
128                 var buttonCreate = element(by.buttonText('Create'));
129                 expect(buttonCreate.isDisplayed()).toBe(true);
130         });
131
132         it('Do not show error if input is acceptable', function () {
133                 var name = element(by.model('ctrl.name'));
134                 var details = element(by.model('ctrl.details'));
135                 name.sendKeys('test');
136                 details.sendKeys('DemoDetails');
137                 var buttonCreate = element(by.buttonText('Create'));
138                 buttonCreate.click().then(function(){
139                         expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope')).isDisplayed()).toBe(false);
140                 });
141         });
142
143         it('Show error when user click the create button with a empty name', function () {
144                 browser.get(baseURL+ '/#/pods');
145                 var details = element(by.model('ctrl.details'));
146                 details.sendKeys('DemoDetails');
147                 var buttonCreate = element(by.buttonText('Create'));
148                 buttonCreate.click();
149                 expect(element(by.cssContainingText(".alert","Name is missing.")).isDisplayed()).toBe(true);
150         });
151
152         it('Show error when user click the create button with an already existing name', function () {
153                 browser.get(baseURL+ '/#/pods');
154                 var name = element(by.model('ctrl.name'));
155                 var details = element(by.model('ctrl.details'));
156                 name.sendKeys('test1');
157                 details.sendKeys('DemoDetails');
158                 var buttonCreate = element(by.buttonText('Create'));
159                 buttonCreate.click();
160                 expect(element(by.cssContainingText(".alert","Error creating the new pod from server: Pod's name already exists")).isDisplayed()).toBe(true);
161         });
162
163         it('If backend is not responding then show error when user click the create button',function(){
164                 mock.teardown();
165                 mock([
166                           {
167                                 request: {
168                                 path: '/api/v1/profile',
169                                 method: 'GET'
170                                 },
171                                 response: {
172                                         data: {
173                                                 "fullname": "Test User", "_id": "79f82eey9a00c84bfhc7aed", "user": "testUser", "groups": ["opnfv-testapi-users"], "email": "testuser@test.com"
174                                         }
175                                 }
176                         }
177                 ]);
178                 browser.get(baseURL+ '/#/pods');
179                 var name = element(by.model('ctrl.name'));
180                 var details = element(by.model('ctrl.details'));
181                 name.sendKeys('test');
182                 details.sendKeys('DemoDetails');
183                 var buttonCreate = element(by.buttonText('Create'));
184                 buttonCreate.click().then(function(){
185                         expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope')).isDisplayed()).toBe(true);
186                 });
187         })
188 });