-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathuser_creates_from_url.spec.js
203 lines (176 loc) · 9.28 KB
/
user_creates_from_url.spec.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
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
'use strict';
require('jasmine-beforeall');
const h = require('../helpers');
const addExtension = require('../helpers/extensions').addExtension;
const resetExtensions = require('../helpers/extensions').resetExtensions;
const matchersHelpers = require('../helpers/matchers');
const projectHelpers = require('../helpers/project');
const inputsHelpers = require('../helpers/inputs');
const CreateFromURLPage = require('../page-objects/createFromURL').CreateFromURLPage;
const CreateProjectPage = require('../page-objects/createProject').CreateProjectPage;
const CatalogPage = require('../page-objects/catalog').CatalogPage;
const nodeMongoTemplate = require('../fixtures/nodejs-mongodb');
const centosImageStream = require('../fixtures/image-streams-centos7.json');
describe('authenticated e2e-user', function() {
let project = projectHelpers.projectDetails();
let namespaceForFixtures = "template-dumpster";
let setupEnv = function() {
// add namespace to create whitelist for template and image stream
addExtension(`
(function() {
// Update whilelist:
window.OPENSHIFT_CONSTANTS.CREATE_FROM_URL_WHITELIST = ['openshift', '${namespaceForFixtures}'];
})();
`);
let fixturesProject = {name: namespaceForFixtures};
let createProjectPage = new CreateProjectPage(fixturesProject);
createProjectPage.visit();
createProjectPage.createProject();
let catalogPage = new CatalogPage(fixturesProject);
// - add an image stream to that namespace
catalogPage.visit();
catalogPage.processImageStream(JSON.stringify(centosImageStream));
// - add a template to that namespace
catalogPage.visit();
catalogPage.saveTemplate(JSON.stringify(nodeMongoTemplate));
};
beforeAll(function() {
h.commonSetup();
h.login();
projectHelpers.deleteAllProjects();
setupEnv();
});
afterAll(function() {
projectHelpers.deleteAllProjects();
resetExtensions();
h.afterAllTeardown();
});
describe('create from URL', function() {
describe('using an image stream and image stream tag supplied as query string params', function() {
let name = 'nodejs-edited';
let sourceURI = 'https://github.com/openshift/nodejs-ex.git-edited';
let sourceRef = 'master-edited';
let contextDir = '/-edited';
let qs = `?imageStream=nodejs&imageTag=4&name=${name}&sourceURI=${sourceURI}&sourceRef=${sourceRef}&contextDir=${contextDir}&namespace=${namespaceForFixtures}`;
let uri = `project/${project.name}create/fromimage${qs}`;
let heading = 'Node.js 4';
let words = project.name.split(' ');
let timestamp = words[words.length - 1];
it('should display details about the the image', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit(qs);
matchersHelpers.expectHeading(heading);
});
it('should load the image stream in to a newly created project', function(){
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit(qs);
createFromURLPage.clickCreateNewProjectTab();
projectHelpers.createProject(project, 'project/' + project['name'] + 'create/fromimage' + qs);
matchersHelpers.expectHeading(heading);
projectHelpers.deleteProject(project);
});
it('should load the image stream in to an existing project and verify the query string params are loaded in to the corresponding form fields', function(){
let createFromURLPage = new CreateFromURLPage();
projectHelpers.visitCreatePage();
projectHelpers.createProject(project);
createFromURLPage.visit(qs);
createFromURLPage.selectExistingProject(timestamp, uri);
matchersHelpers.expectHeading(heading);
let nameInput = element(by.model('name'));
expect(nameInput.getAttribute('value')).toEqual(name);
let sourceURIInput = element(by.model('buildConfig.sourceUrl'));
expect(sourceURIInput.getAttribute('value')).toEqual(sourceURI);
createFromURLPage.clickShowAdvanced();
let sourceRefInput = element(by.model('buildConfig.gitRef'));
expect(sourceRefInput.getAttribute('value')).toEqual(sourceRef);
let contextDirInput = element(by.model('buildConfig.contextDir'));
expect(contextDirInput.getAttribute('value')).toEqual(contextDir);
projectHelpers.deleteProject(project);
});
});
describe('using a template supplied as a query string param', function() {
let sourceURL = "https://github.com/openshift/nodejs-ex.git-edited";
let qs = '?template=nodejs-mongodb-example&templateParamsMap=%7B"SOURCE_REPOSITORY_URL":"' + sourceURL + '"%7D' + '&namespace=' + namespaceForFixtures;
let uri = 'project/' + project.name + 'create/fromtemplate' + qs;
let heading = 'Node.js + MongoDB (Ephemeral)';
let words = project.name.split(' ');
let timestamp = words[words.length - 1];
it('should display details about the template', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit(qs);
matchersHelpers.expectHeading(heading);
});
it('should load the template in to a newly created project', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit(qs);
createFromURLPage.clickCreateNewProjectTab();
projectHelpers.createProject(project, 'project/' + project['name'] + 'create/fromtemplate' + qs);
matchersHelpers.expectHeading(heading);
projectHelpers.deleteProject(project);
});
it('should load the template in an existing project and verify the query string param sourceURL is loaded in to a corresponding form field', function(){
let createFromURLPage = new CreateFromURLPage();
projectHelpers.visitCreatePage();
projectHelpers.createProject(project);
createFromURLPage.visit(qs);
createFromURLPage.selectExistingProject(timestamp, uri);
matchersHelpers.expectHeading(heading);
inputsHelpers
.findValueInInputs(element.all(by.model('parameter.value')), sourceURL)
.then(function(found) {
expect(found).toEqual(sourceURL);
projectHelpers.deleteProject(project);
});
});
});
describe('using a namespace that is not in the whitelist', function() {
it('should display an error about the namespace', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?namespace=not-whitelisted');
matchersHelpers.expectAlert('Resources from the namespace "not-whitelisted" are not permitted.');
});
});
describe('using an unavailable image stream supplied as a query string param', function() {
it('should display an error about the image stream', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?imageStream=unavailable-imageStream');
matchersHelpers.expectAlert('The requested image stream "unavailable-imageStream" could not be loaded.');
});
});
describe('using an unavailable image tag supplied as a query string param', function() {
it('should display an error about the image tag', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?imageStream=nodejs&imageTag=unavailable-imageTag' + '&namespace=' + namespaceForFixtures);
matchersHelpers.expectAlert('The requested image stream tag "unavailable-imageTag" could not be loaded.');
});
});
describe('using an unavailable template supplied as a query string param', function() {
it('should display an error about the template', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?template=unavailable-template');
matchersHelpers.expectAlert('The requested template "unavailable-template" could not be loaded.');
});
});
describe('without using an image stream or a template', function() {
it('should display an error about needing a resource', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('');
matchersHelpers.expectAlert('An image stream or template is required.');
});
});
describe('using both an image stream and a template', function() {
it('should display an error about combining resources', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?imageStream=nodejs&template=nodejs-mongodb-example' + '&namespace=' + namespaceForFixtures);
matchersHelpers.expectAlert('Image streams and templates cannot be combined.');
});
});
describe('using an invalid app name as a query string param', function() {
it('should display an error about the app name', function() {
let createFromURLPage = new CreateFromURLPage();
createFromURLPage.visit('?name=InvalidAppName&imageStream=nodejs' + '&namespace=' + namespaceForFixtures);
matchersHelpers.expectAlert('The app name "InvalidAppName" is not valid. An app name is an alphanumeric (a-z, and 0-9) string with a maximum length of 24 characters, where the first character is a letter (a-z), and the \'-\' character is allowed anywhere except the first or last character.');
});
});
});
});