Skip to content

Commit

Permalink
chore: adding e2e test for rendering swagger (#3696)
Browse files Browse the repository at this point in the history
* fix: adding e2e test for rendering swagger

Signed-off-by: nx673747 <[email protected]>

* fix: updating service homepage url in the e2e test

Signed-off-by: nx673747 <[email protected]>

* using custom command in e2e cypress tests

Signed-off-by: nx673747 <[email protected]>

---------

Signed-off-by: nx673747 <[email protected]>
Co-authored-by: nx673747 <[email protected]>
  • Loading branch information
nxhafa and nx673747 authored Aug 23, 2024
1 parent f3d7db3 commit e413a9d
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 110 deletions.
21 changes: 3 additions & 18 deletions api-catalog-ui/frontend/cypress/e2e/dashboard/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,11 @@
/* eslint-disable spaced-comment */
/// <reference types="Cypress" />

function login() {
cy.visit(`${Cypress.env('catalogHomePage')}/#/`);
cy.url().should('contain', '/login');

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();

cy.contains('Version: ');
}

describe('>>> Dashboard test', () => {
it('dashboard test', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');

cy.get('.header').should('exist');

Expand Down
30 changes: 10 additions & 20 deletions api-catalog-ui/frontend/cypress/e2e/dashboard/wizard-dialog.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,11 @@
/* eslint-disable spaced-comment */
/// <reference types="Cypress" />

function login() {
cy.visit(`${Cypress.env('catalogHomePage')}/#/`);
cy.url().should('contain', '/login');

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();
}

describe('>>> Wizard Dialog test', () => {
it('should test enabler 1', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('.header').should('exist');

cy.get('#onboard-wizard-button').should('exist').click();
Expand All @@ -52,8 +38,9 @@ describe('>>> Wizard Dialog test', () => {
});

it('should test enabler 2', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('.header').should('exist');

cy.get('#onboard-wizard-button').should('exist').click();
Expand All @@ -70,8 +57,9 @@ describe('>>> Wizard Dialog test', () => {
});

it('should test enabler 3', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('.header').should('exist');

cy.get('#onboard-wizard-button').should('exist').click();
Expand All @@ -88,8 +76,9 @@ describe('>>> Wizard Dialog test', () => {
});

it('should test enabler 4', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('.header').should('exist');

cy.get('#onboard-wizard-button').should('exist').click();
Expand All @@ -106,8 +95,9 @@ describe('>>> Wizard Dialog test', () => {
});

it('should test enabler 5', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('.header').should('exist');

cy.get('#onboard-wizard-button').should('exist').click();
Expand Down
26 changes: 8 additions & 18 deletions api-catalog-ui/frontend/cypress/e2e/detail-page/detail-page.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,12 @@
* Copyright Contributors to the Zowe Project.
*/
/* eslint-disable spaced-comment */
/// <reference types="Cypress" />

function login() {
cy.visit(`${Cypress.env('catalogHomePage')}/#/login`);

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();
}
/// <reference types="Cypress" />

describe('>>> Detail page test', () => {
it('Detail page test', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.get('#grid-container').contains('API Catalog').click();

Expand All @@ -44,8 +31,9 @@ describe('>>> Detail page test', () => {
});

it('Should display the API Catalog service title, URL and description in Swagger', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.get('#grid-container').contains('API Catalog').click();

cy.visit(`${Cypress.env('catalogHomePage')}/#/service/apicatalog`);
Expand Down Expand Up @@ -77,8 +65,9 @@ describe('>>> Detail page test', () => {
});

it('Should display the Gateway information in the detail page', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.contains('API Gateway').click();

cy.visit(`${Cypress.env('catalogHomePage')}/#/service/gateway`);
Expand Down Expand Up @@ -113,8 +102,9 @@ describe('>>> Detail page test', () => {
});

it('Should go to the detail page, go back to the dashboard page and check if the search bar works', () => {
login();
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Version: ');
cy.contains('API Gateway').click();

cy.url().should('contain', '/service/gateway');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@ const PATH_TO_VERSION_SELECTOR_ITEMS2 =

describe('>>> Service version compare Test', () => {
beforeEach(() => {
cy.visit(`${Cypress.env('catalogHomePage')}/#/login`);
cy.login(Cypress.env('username'), Cypress.env('password'));

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();
cy.contains('Version: ');

cy.contains('Service Spring Onboarding Enabler sample application API').click(); // discoverable client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@
*/
describe('>>> Service version change Test', () => {
beforeEach(() => {
cy.visit(`${Cypress.env('catalogHomePage')}/#/login`);
cy.login(Cypress.env('username'), Cypress.env('password'));

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();
cy.contains('Version: ');

cy.contains('Service Spring Onboarding Enabler sample application API').click();

Expand Down Expand Up @@ -47,6 +39,6 @@ describe('>>> Service version change Test', () => {
cy.get('#version-menu').should('exist').click();

cy.get('#menu- > div > ul > li').eq(2).click();
cy.get('.servers', { timeout: 10000 }).contains('/discoverableclient/api/v2');
cy.get('.servers', {timeout: 10000}).contains('/discoverableclient/api/v2');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
*
* * This program and the accompanying materials are made available under the terms of the
* * Eclipse Public License v2.0 which accompanies this distribution, and is available at
* * https://www.eclipse.org/legal/epl-v20.html
* *
* * SPDX-License-Identifier: EPL-2.0
* *
* * Copyright Contributors to the Zowe Project.
*
*/

describe("Swagger rendering", () => {

beforeEach("Login to API Catalog", () => {
cy.login(Cypress.env('username'), Cypress.env('password'));
cy.contains('Version: ');
});

[
{
"serviceName": "API Gateway",
"serviceId": "gateway",
"serviceHomepage": `${Cypress.env('catalogHomePage')}`.split("/apicatalog")[0]
},
{
"serviceName": "API Catalog",
"serviceId": "apicatalog",
"serviceHomepage": `${Cypress.env('catalogHomePage')}`.split("/apicatalog")[0]
},
{
"serviceName": "Mock zOSMF",
"serviceId": "mockzosmf",
"serviceHomepage": ":10013/"
},
].forEach((service) => {
it("Rendering Swagger for " + service.serviceName, () => {

cy.get('#grid-container').contains(service.serviceName).click();

cy.get('div.tabs-swagger').should('exist');

cy.get('div.tabs-swagger > div.serviceTab > div.header > h4').should('contain', service.serviceName);

cy.get('div.tabs-swagger > div.serviceTab > div.header > a:nth-child(2)')
.as('serviceHomepage').should("contain", "Service Homepage");

cy.get('@serviceHomepage').should('have.attr', 'title', 'Open Service Homepage')

cy.get('div.tabs-swagger')
.find('.apiInfo-item')
.get('h6:nth-Child(1)')
.as('basePath');

cy.get('@basePath')
.get('label')
.should('contain', "API Base Path:");

const regex = new RegExp(`^\/${service.serviceId}\/api(\/v1)?$`);
cy.get('@basePath')
.get('#apiBasePath').invoke("text").should(text => {
expect(text).to.match(regex);
});

cy.get('div.tabs-swagger')
.find('.apiInfo-item')
.get('h6:nth-Child(2)')
.as('sId');

cy.get('@sId')
.get('label')
.should('contain', "Service ID:");

cy.get('@sId')
.get('#serviceId')
.should('contain', service.serviceId);

cy.get('#swagger-label')
.should('exist')
.should('contain', 'Swagger');

cy.get('#swaggerContainer').as('swaggerContainer');

cy.get('@swaggerContainer').should('exist');

cy.get('@swaggerContainer')
.get('div.swagger-ui > div:nth-child(2) > div.information-container')
.should('exist');

cy.get('@swaggerContainer')
.get('div.information-container > section > div > div.info > .main')
.as('mainInfo');

cy.get('@mainInfo').should('exist');

cy.get('@mainInfo')
.get('h2')
.should('have.class', 'title');

cy.get('@mainInfo')
.get('h2')
.find('pre.version')
.should('exist');

cy.get('@swaggerContainer')
.get('div.swagger-ui > div:nth-child(2) > div.wrapper')
.should('exist');

cy.get('@swaggerContainer')
.get('div.wrapper > section > div > div.apiInfo-item > p > label')
.as('instanceUrlLabel');

cy.get('@instanceUrlLabel')
.should('exist')
.should('contain', 'Instance URL:');

cy.get('@swaggerContainer')
.get('div.swagger-ui > div:nth-child(2) > div.wrapper')
.should('exist');

cy.get('@swaggerContainer')
.get('div.wrapper > section > div > div > div.opblock-tag-section')
.as('operationBlock');

cy.get('@operationBlock').should('exist');

cy.get('@operationBlock')
.find('.operation-tag-content')
.should('exist');

cy.get('@operationBlock')
.get('.operation-tag-content')
.find('.opblock')
.should('exist');

cy.get('@operationBlock')
.get('.operation-tag-content > .opblock > .opblock-summary > button:first-child')
.should('exist');
cy.get('@operationBlock')
.get('button:first-child')
.should('have.class', 'opblock-summary-control');

cy.get('@serviceHomepage').click();

cy.url().should('contain', service.serviceHomepage);
});
})
});

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@

describe('>>> Swagger Try Out and Code Snippets Test', () => {
beforeEach(() => {
cy.visit(`${Cypress.env('catalogHomePage')}/#/login`);

const username = Cypress.env('username');
const password = Cypress.env('password');

cy.get('button[type="submit"').as('submitButton');

cy.get('#username').type(username);
cy.get('input[name="password"]').type(password);

cy.get('@submitButton').click();
cy.login(Cypress.env('username'), Cypress.env('password'));
cy.contains('Version: ');
});

[
Expand Down
Loading

0 comments on commit e413a9d

Please sign in to comment.