Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
icelandld committed Jun 17, 2024
1 parent 5a26836 commit 1e82bcf
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 36 deletions.
6 changes: 1 addition & 5 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = defineConfig({
env:{
adminUrl: 'http://localhost:8001',
clientUrl: 'http://localhost:8000',
//config whether the execution can be reapeatable
repeatable: true
},
reporter: 'mochawesome',
Expand All @@ -19,10 +20,5 @@ module.exports = defineConfig({
// implement node event listeners here
},
},
env: {
//config whether the execution can be reapeatable
repeatable: true
},
"screenshotsFolder": "outputs/screenshots"

});
3 changes: 3 additions & 0 deletions cypress/KongBase/KongElement.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* KongElement, get the element by data-testid or aria-label which specified by Kong
*/
export default class KongElement {

static fromTAId(uatId) {
Expand Down
9 changes: 5 additions & 4 deletions cypress/e2e/route.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe('test for route creation', () => {
})
});

//add route with data from parameter
it('create route', () => {

//access route page
beforeEach(() => {
home.access();
home.openWS();
nav.navigate('Routes');
})

it('create route', () => {
routes.add();
//create route with data object
route.create({
name: "example_route",
service: service.id,
Expand All @@ -39,6 +39,7 @@ describe('test for route creation', () => {
});
})

//FIXME: this test works in local but not in CI, response as 404 in CI
it('check route works', () => {
if (routeName) {
const clientBase = `${Cypress.env('clientUrl')}`;
Expand Down
14 changes: 9 additions & 5 deletions cypress/pages/base.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import ke from "../KongBase/KongElement";

// cypress/pages/BasePage.js
export const ReapatAble = (() => Cypress.env('repeatable'))();

import ke from "../KongBase/KongElement";

/**
* BasePage, the base page for all page object
*/
export default class BasePage {

constructor(url) {
Expand All @@ -15,12 +17,14 @@ export default class BasePage {
}
ke.open(this.url)
}

/** Load data from fixture file or data object
* @param {*} data
* @returns return as cypress chainable object
*/
loadData(data) {
if (!data) {
throw new Error('Data is required');
}

if (typeof (data) !== 'object' && data.includes('.json')) {
return cy.fixture(data).then((fixtureData) => {
return fixtureData;
Expand Down
8 changes: 5 additions & 3 deletions cypress/pages/home.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// import ke from "../widgets/KongElement";
import BasePage from "./base";

const HomePage = {
defaultWorkspace: "workspace-link-default"
}

//-------------------Hompage-------------------//

import ke from "../KongBase/KongElement";
import BasePage from "./base";

export class Home extends BasePage {
constructor() {
super('/')
Expand Down
13 changes: 9 additions & 4 deletions cypress/pages/navigator.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
// import ke from "../widgets/KongElement";


//automatioin id for the main menu
const NavigationMenu = {
main: "Open Main Menu",
"Gateway Serivces": "sidebar-item-gateway-services",
"Routes": "sidebar-item-routes"
}

//-------------------NavigatorPage-------------------//

import ke from "../KongBase/KongElement";

class Navigator {

/** Navigate to the page by name
* @param {string} name
*/
navigate(name) {
ke.fromTAId(NavigationMenu[name]).then(($el) => {
if (Cypress.dom.isVisible($el)) {
Expand All @@ -18,6 +22,7 @@ class Navigator {
ke.fromTAId(NavigationMenu[name]).click();
}
})
cy.log(`Navigated to ${name}`)
}
}

Expand Down
21 changes: 17 additions & 4 deletions cypress/pages/route.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
//key is same as entity property name
const RouteForm = {
"name": "route-form-name",
"name": "route-form-name",
"service": "route-form-service-id",
"paths": "route-form-paths-input-{index}",
"service-select": "select-item-{serviceId}",
"Save": "form-submit"
}

import { randomNum } from "../utils/randomUtil";
//-------------------RoutePage-------------------//

import BasePage, { ReapatAble } from "./base";
import ke from "../KongBase/KongElement";
import { randomNum } from "../utils/randomUtil";

export class Route extends BasePage {

constructor(ws = 'default', rootId) {
super(`/${ws}/routes/${rootId}`);
}

/**
* create route with given data
* @param {*} data {service: string, name: string, paths: string[]}
* @returns cypress chain object
*/
create(data) {
return super.loadData(data).then((route) => {
if (ReapatAble) {
route.name = route.name + randomNum(6);
}

Object.entries(route).forEach(([key, value]) => {
cy.log(key, value);
if (key === 'service') {
ke.fromTAId(RouteForm["service"]).click();
ke.fromTAId(RouteForm["service-select"].replace("{serviceId}", value)).click();
Expand All @@ -32,6 +44,7 @@ export class Route extends BasePage {
});
ke.fromTAId(RouteForm["Save"]).click();
cy.get('.toaster-message').should('have.text', `Route "${route.name}" successfully created!`);
cy.log('route created', route);
return cy.wrap(route);
});
}
Expand Down
10 changes: 8 additions & 2 deletions cypress/pages/routes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const RoutesPage = {
"New Route": ["new-route", "toolbar-add-route"]
}
//-------------------RoutesPage-------------------//

import BasePage from "./base";
import ke from "../KongBase/KongElement";

export class Routes extends BasePage {

constructor(ws = 'default') {
super(`/${ws}/routes`);
}

add() {
ke.fromTAId(RoutesPage["New Route"][0]).click();
ke.fromTAId(RoutesPage["New Route"][1]).click();

//FIXME: How to handle there's already routes
//FIXME: How to handle there's routes already exist
// cy.get('body').then($el => {
// let $element = $el.find(`[data-testid="${RoutesPage["New Route"][1]}"]`);
// if ($element.length > 0 && $element.css('display')!=='none') {
Expand Down
28 changes: 20 additions & 8 deletions cypress/pages/service.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
// import ke from "../widgets/KongElement";
import BasePage, { ReapatAble } from "./base";
import { randomNum } from "../utils/randomUtil";
import route from "./route";

//automatioin id for the main menu
const ServiceForm = {
name: "gateway-service-name-input",
url: "gateway-service-url-input",
submit: "form-submit"
}

//-------------------ServicePage-------------------//


import BasePage, { ReapatAble } from "./base";
import route from "./route";
import { randomNum } from "../utils/randomUtil";
import ke from "../KongBase/KongElement";

export class Service extends BasePage {

constructor(ws = 'default', serviceId) {
super(`/${ws}/services/${serviceId}`);
}

/**
* create service with given data
* @param {} service {name: string, url: string}
* @returns cypress chain object
*/
create(service) {
return super.loadData(service).then((serviceData) => {
if (ReapatAble) {
serviceData.name = serviceData.name + randomNum(6);
}
Object.entries(serviceData).forEach(([key, value]) => {
cy.log(key, value);
cy.log(`set service with ${key} as ${value}`);
ke.fromTAId(ServiceForm[key]).type(value);
});
ke.fromTAId(ServiceForm["submit"]).click();
cy.get('.toaster-message').should('have.text', `Gateway Service "${serviceData.name}" successfully created!`);

cy.log('service created', serviceData);
return cy.wrap(serviceData);
});
}
Expand Down
11 changes: 10 additions & 1 deletion cypress/pages/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ const ServicesPage = {
"Service-Row": "{serviceName}",
}

//-------------------ServicesPage-------------------//

import BasePage from "./base";
import ke from "../KongBase/KongElement";

export class Services extends BasePage {
constructor(ws = 'default') {
super(`/${ws}/services`);
}

add() {
ke.fromTAId(ServicesPage["New Gateway Service"][1]).click();
//FIXME: How to handle there's services already exist
// cy.get('body').then($el => {
// let $element = $el.find(`[data-testid="${ServicesPage["New Gateway Service"][1]}"]`);
// if ($element.length >0 && $element.css('display')!=='None') {
// if ($element.length >0 && $element.css('display')!=='none') {
// ke.fromTAId(ServicesPage["New Gateway Service"][1]).click();
// } else {
// ke.fromTAId(ServicesPage["New Gateway Service"][0]).click();
Expand All @@ -35,6 +43,7 @@ export class Services extends BasePage {
ke.fromTAId(ServicesPage["Service-Row"].replace("{serviceName}", serviceName))
.should('be.visible').first()
.click();
cy.log('service is opened', serviceName)
}

}
Expand Down

0 comments on commit 1e82bcf

Please sign in to comment.