Skip to content
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

[CY] polish baseUrl #651

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cypress/pageobjects/clusterNetwork.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class SettingsPagePo extends CruResource {
cy.get('span').contains(actionText).click();

cy.get(this.detailPageHead).then(() => {
cy.url().should('eq', `${this.basePath()}${editPageUrl}/${urlSuffix}?mode=edit`)
cy.url().should('eq', `${Cypress.env('urlPath')}${editPageUrl}/${urlSuffix}?mode=edit`)
})
}
}
2 changes: 1 addition & 1 deletion cypress/pageobjects/settings.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class SettingsPagePo extends CruResource {
cy.get('span').contains(actionText).click();

cy.get(this.detailPageHead).then(() => {
cy.url().should('eq', `${this.basePath()}${editPageUrl}/${urlSuffix}?mode=edit`)
cy.url().should('eq', `${Cypress.env('urlPath')}${editPageUrl}/${urlSuffix}?mode=edit`)
})
}

Expand Down
4 changes: 0 additions & 4 deletions cypress/pageobjects/volume.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,4 @@ export class VolumePage extends CruResourcePo {
this.delete("default", volumeName.trim());
});
}

basePath() {
return Cypress.env('NODE_ENV') === 'dev' ? Cypress.env('baseUrl') : `${Cypress.env('baseUrl')}/dashboard`;
}
}
3 changes: 3 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
config.baseUrl = config.env.baseUrl;

config.env.urlPath = config.env['NODE_ENV'] === 'dev' ? config.env.baseUrl : `${config.env.baseUrl}/dashboard`;

on("task", {
isFileExist,
findFiles,
Expand Down
12 changes: 2 additions & 10 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Cypress.Commands.add('login', (params = {}) => {
const username = params.username || Cypress.env('username');
const password = params.password || Cypress.env('password');

const isDev = Cypress.env('NODE_ENV') === 'dev';
const baseUrl = isDev ? Cypress.config('baseUrl') : `${Cypress.config('baseUrl')}/dashboard`;
cy.visit(`/auth/login`);
cy.intercept('GET', '/v3-public/authProviders').as('authProviders');
cy.wait('@authProviders').then(res => {
Expand Down Expand Up @@ -43,17 +41,11 @@ Cypress.Commands.add('stopOnFailed', () => {
})
})

Cypress.Commands.overwrite('visit', (originalFn, url = '', options) => {
const isDev = Cypress.env('NODE_ENV') === 'dev';

if (!isDev) {
url = `/dashboard${url}`;
}

Cypress.Commands.overwrite('visit', (originalFn, url, options) => {
url = Cypress.env('urlPath')
return originalFn(url, options)
})


Cypress.on('uncaught:exception', (err, runable) => {
return false;
})
24 changes: 3 additions & 21 deletions cypress/utils/components/page.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Navbar {

cy.location().should(loc => {
const deleteHash = loc.href.replace(loc.hash, '');
expect(deleteHash).to.eq(`${new Navbar().basePath()}/${matchUrl}`)
expect(deleteHash).to.eq(`${Cypress.env('urlPath')}/${matchUrl}`)
})

cy.wait(2000); // need to wait here, because when you click on the secondary menu, it will automatically jump to the first position in the secondary menu
Expand All @@ -104,7 +104,7 @@ export class Navbar {
cy.get("nav a").contains(new RegExp("^" + navName + "$")).click();
cy.location().should(loc => {
const deleteHash = loc.href.replace(loc.hash, '');
expect(deleteHash).to.eq(`${this.basePath()}/${matchUrl}`)
expect(deleteHash).to.eq(`${Cypress.env('urlPath')}/${matchUrl}`)
})

cy.wait(2000);
Expand All @@ -120,10 +120,6 @@ export class Navbar {
})
}
}

basePath() {
return Cypress.env('NODE_ENV') === 'dev' ? Cypress.env('baseUrl') : `${Cypress.env('baseUrl')}/dashboard`;
}
}

class Header {
Expand Down Expand Up @@ -157,24 +153,10 @@ export default class PagePo extends ComponentPo {
}

isCurrentPage(): Cypress.Chainable<boolean> {
return cy.url().then(url => url === Cypress.env('baseUrl') + this.wrapPath(this.path));
return cy.url().then(url => url === Cypress.env('urlPath') + this.path);
}

checkIsCurrentPage() {
return this.isCurrentPage().should('eq', true);
}

wrapPath(path: string) {
const isDev = Cypress.env('NODE_ENV') === 'dev';
let url = path;
if (!isDev) {
url = `/dashboard${path}`;
}

return url
}

basePath() {
return Cypress.env('NODE_ENV') === 'dev' ? Cypress.env('baseUrl') : `${Cypress.env('baseUrl')}/dashboard`;
}
}