summaryrefslogtreecommitdiffstats
path: root/testapi/opnfv_testapi/tests/UI/e2e/podsControllerSpec.js
blob: c3961ab4bdc500e276ca1a336af5d257354e003d (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
'use strict';

var mock = require('protractor-http-mock');
var baseURL = "http://localhost:8000"
describe('testing the Pods page for anonymous user', function () {

	beforeEach(function(){
		mock([{
			request: {
			  path: '/api/v1/pods',
			  method: 'GET'
			},
			response: {
				data: {
					pods: [{role: "community-ci", name: "test", owner: "testUser",
					details: "DemoDetails", mode: "metal", _id: "59f02f099a07c84bfc5c7aed",
					creation_date: "2017-10-25 11:58:25.926168"}]
				}
			}
		  }]);
	});

	afterEach(function(){
		mock.teardown();
	});

	it( 'should navigate to pods link ', function() {
		browser.get(baseURL);
		var podslink = element(by.linkText('Pods')).click();
		var EC = browser.ExpectedConditions;
		browser.wait(EC.urlContains(baseURL+ '/#/pods'), 10000);
	});

	it('create button is not visible for anonymous user', function () {
		browser.get(baseURL+'#/pods');
		var buttonCreate = element(by.buttonText('Create'));
		expect(buttonCreate.isDisplayed()).toBeFalsy();
	});

	it('filter button is visible for anonymous user', function () {
		var buttonFilter = element(by.buttonText('Filter'));
		expect(buttonFilter.isDisplayed()).toBe(true)
	});

	it('clear button is visible for anonymous user', function () {
		var buttonClear = element(by.buttonText('Clear'));
		expect(buttonClear.isDisplayed()).toBe(true)
	});

	it('Show results when click filter button', function () {
		var buttonFilter = element(by.buttonText('Filter'));
		buttonFilter.click();
		var pod = element(by.css('.show-pod'));
		expect(pod.isPresent()).toBe(true);
	});

	it('Show results when click clear button', function () {
		browser.get(baseURL+'#/pods');
		var buttonClear = element(by.buttonText('Clear'));
		buttonClear.click();
		var pod = element(by.css('.show-pod'));
		expect(pod.isPresent()).toBe(true);
	});

	it('If details is not shown then show details when click the link',function() {
		expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(true);
		var podslink = element(by.linkText('test')).click();
		expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(false);
	});

	it('If details is shown then hide details when click the link',function() {
		expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(false);
		var podslink = element(by.linkText('test')).click();
		expect(element(by.css('.show-pod.hidden')).isPresent()).toBe(true);
	});

	it('If backend is not responding then show error when click filter button', function () {
		browser.get(baseURL + '/#/pods');
		mock.teardown();
		var buttonFilter = element(by.buttonText('Filter'));
		buttonFilter.click().then(function(){
			expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope'))
			.isDisplayed()).toBe(true);
		});
	});

});

describe('testing the Pods page for authorized user', function () {

	beforeEach(function(){
		mock([
			{
				request: {
				  path: '/api/v1/pods',
				  method: 'POST'
				},
				response: {
					data: {
						href: baseURL+"/api/v1/pods/test"
					}
				}
			  },
			  {
				request: {
				  path: '/api/v1/pods',
				  method: 'POST',
				  data: {
					name: 'test1',
					details : 'DemoDetails',
					role : 'community-ci',
					mode : 'metal'
				  }
				},
				response: {
					status : 403
				}
			  },
			  {
				request: {
				path: '/api/v1/profile',
				method: 'GET'
				},
				response: {
					data: {
						"fullname": "Test User", "_id": "79f82eey9a00c84bfhc7aed",
						"user": "testUser", "groups": ["opnfv-testapi-users",
						"opnfv-gerrit-functest-submitters"], "email": "testuser@test.com"
					}
				}
			}
		]);
	});

	afterEach(function(){
		mock.teardown();
	});

	it('create button is visible for authorized user', function () {
		browser.get(baseURL + '/#/pods');
		var buttonCreate = element(by.buttonText('Create'));
		expect(buttonCreate.isDisplayed()).toBe(true);
	});

	it('Do not show error if input is acceptable', function () {
		var name = element(by.model('ctrl.name'));
		var details = element(by.model('ctrl.details'));
		name.sendKeys('test');
		details.sendKeys('DemoDetails');
		var buttonCreate = element(by.buttonText('Create'));
		buttonCreate.click().then(function(){
			expect(element(by.css('.alert.alert-danger.ng-binding.ng-scope'))
			.isDisplayed()).toBe(false);
		});
	});

	it('Show error when user click the create button with a empty name', function () {
		browser.get(baseURL+ '/#/pods');
		var details = element(by.model('ctrl.details'));
		details.sendKeys('DemoDetails');
		var buttonCreate = element(by.buttonText('Create'));
		buttonCreate.click();
		expect(element(by.cssContainingText(".alert","Name is missing.")).isDisplayed()).toBe(true);
	});

	it('Show error when user click the create button with an already existing name', function () {
		browser.get(baseURL+ '/#/pods');
		var name = element(by.model('ctrl.name'));
		var details = element(by.model('ctrl.details'));
		name.sendKeys('test1');
		details.sendKeys('DemoDetails');
		var buttonCreate = element(by.buttonText('Create'));
		buttonCreate.click();
		expect(element(by.cssContainingText(".alert","Error creating the new pod from server: undefined")).isDisplayed()).toBe(true);
	});

	it('If backend is not responding then show error when user click the create button',function(){
		mock.teardown();
		mock([
			  {
				request: {
				path: '/api/v1/profile',
				method: 'GET'
				},
				response: {
					data: {
						"fullname": "Test User", "_id": "79f82eey9a00c84bfhc7aed",
						"user": "testUser", "groups": ["opnfv-testapi-users"],
						"email": "testuser@test.com"
					}
				}
			}
		]);
		browser.get(baseURL+ '/#/pods');
		var name = element(by.model('ctrl.name'));
		var details = element(by.model('ctrl.details'));
		name.sendKeys('test');
		details.sendKeys('DemoDetails');
		var buttonCreate = element(by.buttonText('Create'));
		buttonCreate.click().then(function(){
			expect(element(by.css('.alert.alert-danger.ng-binding'))
			.isDisplayed()).toBe(true);
		});
	});
});