Skip to content

Create from URL e2e tests #1195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"angular": false,
"by": false,
"before": false,
"beforeAll": false,
"beforeEach": false,
"browser": false,
"describe": false,
Expand Down
43 changes: 43 additions & 0 deletions test/integration/features/user_adds_imagestream_to_project.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

var h = require('../helpers');
var projectHelpers = require('../helpers/project');
var OverviewPage = require('../page-objects/overview').OverviewPage;
var CreateProjectPage = require('../page-objects/createProject').CreateProjectPage;
var ImageStreamsPage = require('../page-objects/imageStreams').ImageStreamsPage;
var centosImageStream = require('../fixtures/image-streams-centos7.json');

describe('User adds an image stream to a project', function() {

beforeEach(function() {
h.commonSetup();
h.login();
projectHelpers.deleteAllProjects();
});

afterEach(function() {
h.commonTeardown();
});

describe('after creating a new project', function() {
describe('using the "Import YAML/JSON" tab', function() {
it('should process and create the images in the image stream', function() {
var project = projectHelpers.projectDetails();
var createProjectPage = new CreateProjectPage(project);
createProjectPage.visit();
createProjectPage.createProject();
var overviewPage = new OverviewPage(project);
overviewPage.visit();
var catalogPage = overviewPage.clickAddToProject(); // implicit redirect to catalog page
catalogPage
.processImageStream(JSON.stringify(centosImageStream))
.then(function() {
// verify we have the nodejs image stream loaded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd kind of like to be able to get rid of this comment and have something in code like:

expect(tableRowFor('nodejs')).toBe(true);

But we can prob add that helper later as I bet we would want a few table helpers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO so we're consistent with user_adds_template_to_project.spec.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

var imageStreamsPage = new ImageStreamsPage(project);
imageStreamsPage.visit();
expect(element(by.cssContainingText('td', 'nodejs')).isPresent()).toBe(true); // TODO: use fixture
});
});
});
});
});
34 changes: 24 additions & 10 deletions test/integration/features/user_adds_template_to_project.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

require('jasmine-beforeall');
var h = require('../helpers');
var projectHelpers = require('../helpers/project');
var OverviewPage = require('../page-objects/overview').OverviewPage;
Expand All @@ -9,9 +8,6 @@ var DeploymentsPage = require('../page-objects/deployments').DeploymentsPage;
var ServicesPage = require('../page-objects/services').ServicesPage;
var RoutesPage = require('../page-objects/routes').RoutesPage;
var nodeMongoTemplate = require('../fixtures/nodejs-mongodb');
//var logger = require('../helpers/logger');
// TODO: use this to alter whitelist in the tests to support the create from url flow
// var env = require('../helpers/env');

describe('User adds a template to a project', function() {

Expand Down Expand Up @@ -42,24 +38,42 @@ describe('User adds a template to a project', function() {
// verify we have the 2 deployments in the template
var deploymentsPage = new DeploymentsPage(project);
deploymentsPage.visit();
expect(element(by.cssContainingText('td', 'mongodb')).isPresent()).toBe(true);
expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true);
expect(element(by.cssContainingText('td', 'mongodb')).isPresent()).toBe(true); // TODO: use fixture
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO's should be obvious what is needed for someone coming else looking at this later. Also fixture isn't doesn't seem like the right word here, shouldn't it be a helper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment means to eventually use the fixture (json) and pluck out the names, rather than hard-coding mongodb, nodejs-mongodb-example.

Is on my list to add some table helpers as well.

expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true); // TODO: use fixture
// verify we have the two services in the template
var servicesPage = new ServicesPage(project);
servicesPage.visit();
expect(element(by.cssContainingText('td', 'mongodb')).isPresent()).toBe(true);
expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true);
expect(element(by.cssContainingText('td', 'mongodb')).isPresent()).toBe(true); // TODO: use fixture
expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true); // TODO: use fixture
// verify we have one route for the mongo app
var routesPage = new RoutesPage(project);
routesPage.visit();
expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true);
expect(element(by.cssContainingText('td', 'nodejs-mongodb-example')).isPresent()).toBe(true); // TODO: use fixture
});
});

xit('should save the template in the project catalog', function() {
it('should save the template in the project catalog', function() {
// TODO: same flow as the above test, but use:
// catalogPage.saveTemplate(tpl)
// & assert that the template was added to the catalog in this project
var project = projectHelpers.projectDetails();
var createProjectPage = new CreateProjectPage(project);
createProjectPage.visit();
createProjectPage.createProject();
var overviewPage = new OverviewPage(project);
overviewPage.visit();
var catalogPage = overviewPage.clickAddToProject(); // implicit redirect to catalog page
catalogPage
.saveTemplate(JSON.stringify(nodeMongoTemplate))
.then((overview2) => {
var cat2 = overview2.clickAddToProject(); // implicit redirect to catalog page
// once the template processes, we just have to return
// to the catalog and verify the tile exists
cat2.visit();
cat2.clickCategory('JavaScript'); // TODO: pass in the tile name from the template fixture
cat2.findTileBy('Node.js + MongoDB (Ephemeral)', project.name); // TODO: pass in...
expect(element).toBeTruthy();
});
});
});
});
Expand Down
203 changes: 203 additions & 0 deletions test/integration/features/user_creates_from_url.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update the qs var to get rid of the + with a template literal and ${placeholders}:

let qs = `?imageStream=nodejs&imageTag=4&name=${name}&sourceURI=${sourceURI}&sourceRef=${sourceRef}&contextDir=${contextDir}&namespace=${namespaceForFixtures}`;
let uri = `project/${project.name}create/fromimage${qs}`;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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.');
});
});

});

});
23 changes: 4 additions & 19 deletions test/integration/features/user_creates_project.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
/* jshint unused:false */

require('jasmine-beforeall');
var h = require('../helpers.js');
var projectHelpers = require('../helpers/project.js');

var goToAddToProjectPage = function(projectName) {
var uri = 'project/' + projectName + '/create';
Expand Down Expand Up @@ -122,19 +122,11 @@ describe('', function() {

it('should be able to show the create project page', goToCreateProjectPage);

var timestamp = (new Date()).getTime();
var project = {
name: 'console-test-project-' + timestamp,
displayName: 'Console integration test Project ' + timestamp,
description: 'Created by assets/test/integration/rest-api/project.js'
};
var project = projectHelpers.projectDetails();

it('should successfully create a new project', function() {
goToCreateProjectPage();
for (var key in project) {
h.setInputValue(key, project[key]);
}
h.clickAndGo('Create', 'project/' + project['name'] + '/create');
projectHelpers.createProject(project, 'project/' + project['name'] + '/create');
h.waitForPresence('.breadcrumb li a', project['displayName']);
checkProjectSettings(project['name'], project['displayName'], project['description']);
});
Expand Down Expand Up @@ -184,14 +176,7 @@ describe('', function() {
});

it('should delete a project', function() {
h.goToPage('/');
var projectTile = element(by.cssContainingText(".project-info", project.displayName));
projectTile.element(by.css('.fa-trash-o')).click();
h.setInputValue('confirmName', project.name);
var deleteButton = element(by.cssContainingText(".modal-dialog .btn", "Delete"));
browser.wait(protractor.ExpectedConditions.elementToBeClickable(deleteButton), 2000);
deleteButton.click();
h.waitForPresence(".alert-success", "marked for deletion");
projectHelpers.deleteProject(project);
});

/*
Expand Down
Loading