Skip to content

Commit

Permalink
Add users
Browse files Browse the repository at this point in the history
  • Loading branch information
n313893254 committed Aug 18, 2023
1 parent 823d3cf commit dccd266
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 18 deletions.
6 changes: 5 additions & 1 deletion cypress/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Constants {
public uiSourceUrl = '/harvester/c/local/harvesterhci.io.setting/ui-source?mode=edit';
public hostsPage = '/harvester/c/local/harvesterhci.io.host';
public supportPage = '/harvester/c/local/support';
public vmPage = '/harvester/c/local/kubevirt.io.virtualmachine';
public vmPage = `/harvester/c/${Cypress.config('clusterId')}/kubevirt.io.virtualmachine`;
public settingUrl = '/harvester/c/local/harvesterhci.io.setting';
public volumePage = '/harvester/c/local/harvesterhci.io.volume';
public imagePage = '/harvester/c/local/harvesterhci.io.virtualmachineimage';
Expand All @@ -39,6 +39,10 @@ export const PageUrl = {
volumeSnapshot: '/harvester/c/local/harvesterhci.io.volumesnapshot'
}

export const RancherPageUrl = {
user: `/c/local/auth/management.cattle.io.user`,
}

export const MenuNav = {
dashboard: ['Dashboard', 'harvester/c/local/harvesterhci.io.dashboard', 'Harvester Cluster: local'],
Host: ['Hosts', 'harvester/c/local/harvesterhci.io.host', 'Hosts'],
Expand Down
10 changes: 10 additions & 0 deletions cypress/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const HCI = {
volumeSnapshot: 'snapshot.storage.k8s.io.volumesnapshot'
};


export const CAPI = {
RANCHER_CLUSTER: 'provisioning.cattle.io.cluster',
};

export const MANAGEMENT = {
USER: 'management.cattle.io.user',
CLUSTER_ROLE_TEMPLATE_BINDING: 'management.cattle.io.clusterroletemplatebinding',
}

export const HCI_URL = {
volumeSnapshot: 'harvesterhci.io.volumesnapshot'
}
Expand Down
52 changes: 52 additions & 0 deletions cypress/pageobjects/clusterMembers.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import CruResourcePo from '@/utils/components/cru-resource.po';
import { MANAGEMENT } from '@/constants/types'
import LabeledSelectPo from '@/utils/components/labeled-select.po';

export default class UserPo extends CruResourcePo {
constructor() {
super({
type: MANAGEMENT.CLUSTER_ROLE_TEMPLATE_BINDING
});
}

public selectMember() {
return new LabeledInputPo('.labeled-input', `:contains("Select Member")`)
}

public newPassword() {
return new LabeledInputPo('.labeled-input', `:contains("New Password")`)
}

public confirmPassword() {
return new LabeledInputPo('.labeled-input', `:contains("Confirm Password")`)
}

public setValue(value: any) {
this.username().input(value?.username)
this.newPassword().input(value?.newPassword)
this.confirmPassword().input(value?.confirmPassword)
}

public create(value: any, urlWithNamespace?: boolean) {
cy.visit(`/c/local/auth/${this.type}/create`)

this.setValue(value)

this.save()
}

public save({
buttonText = 'save',
edit,
} : {
buttonText?:string,
edit?: boolean;
} = {}) {
cy.intercept('POST', `/v3/users`).as('create');

this.clickFooterBtn(buttonText)
cy.wait('@create').then(res => {
expect(res.response?.statusCode, `Create ${this.type} success`).to.equal(201);
})
}
}
52 changes: 52 additions & 0 deletions cypress/pageobjects/rancher/user.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import CruResourcePo from '@/utils/components/cru-resource.po';
import { MANAGEMENT } from '@/constants/types'
import LabeledInputPo from '@/utils/components/labeled-input.po';

export default class UserPo extends CruResourcePo {
constructor() {
super({
type: MANAGEMENT.USER
});
}

public username() {
return new LabeledInputPo('.labeled-input', `:contains("Username")`)
}

public newPassword() {
return new LabeledInputPo('.labeled-input', `:contains("New Password")`)
}

public confirmPassword() {
return new LabeledInputPo('.labeled-input', `:contains("Confirm Password")`)
}

public setValue(value: any) {
this.username().input(value?.username)
this.newPassword().input(value?.newPassword)
this.confirmPassword().input(value?.confirmPassword)
}

public create(value: any, urlWithNamespace?: boolean) {
cy.visit(`/c/local/auth/${this.type}/create`)

this.setValue(value)

this.save()
}

public save({
buttonText = 'save',
edit,
} : {
buttonText?:string,
edit?: boolean;
} = {}) {
cy.intercept('POST', `/v3/users`).as('create');

this.clickFooterBtn(buttonText)
cy.wait('@create').then(res => {
expect(res.response?.statusCode, `Create ${this.type} success`).to.equal(201);
})
}
}
8 changes: 4 additions & 4 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ export class VmsPage extends CruResourcePo {
edit = false,
} = {}) {
if (edit) {
cy.intercept('PUT', '/v1/harvester/kubevirt.io.virtualmachines/*/*').as('createVM');
cy.intercept('PUT', '**/v1/harvester/kubevirt.io.virtualmachines/*/*').as('createVM');
cy.get('.cru-resource-footer').contains('Save').click()
cy.get('.card-actions').contains('Save & Restart').click()
} else {
cy.intercept('POST', '/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');
cy.intercept('POST', '**/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');
cy.get('.cru-resource-footer').contains('Create').click()
}

Expand Down Expand Up @@ -353,15 +353,15 @@ export class VmsPage extends CruResourcePo {
}

public delete(namespace:string, name: string, displayName?: string, { removeRootDisk, id }: { removeRootDisk?: boolean, id?: string } = { removeRootDisk: true }) {
cy.visit(`/harvester/c/local/${this.type}`)
cy.visit(`/harvester/c/${Cypress.config('clusterId')}/${this.type}`)

this.clickAction(name, 'Delete').then((_) => {
if (!removeRootDisk) {
this.rootDisk().click();
}
})

cy.intercept('DELETE', `/v1/harvester/${this.realType}s/${namespace}/${name}*`).as('delete');
cy.intercept('DELETE', `**/v1/harvester/${this.realType}s/${namespace}/${name}*`).as('delete');
cy.get(this.confirmRemove).contains('Delete').click();
cy.wait('@delete').then(res => {
cy.window().then((win) => {
Expand Down
32 changes: 28 additions & 4 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import cookie from 'cookie';
import addContext from "mochawesome/addContext";

import { Constants } from '../constants/constants'
import { CAPI } from '@/constants/types'

const path = require('path')

Expand All @@ -11,11 +12,17 @@ require('cy-verify-downloads').addCustomCommand();

Cypress.Commands.add('login', (params = {}) => {
const url = params.url || constants.dashboardUrl;
const username = params.username || Cypress.env('username');
let 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`;
const multiTenant = Cypress.env('multiTenant');

if (multiTenant !== 'true') {
Cypress.config('baseUrl', Cypress.env('baseUrl'));
} else {
Cypress.config('baseUrl', Cypress.env('rancherUrl'));
}

cy.visit(`/auth/login`);
cy.intercept('GET', '/v3-public/authProviders').as('authProviders');
cy.wait('@authProviders').then(res => {
Expand All @@ -35,7 +42,24 @@ Cypress.Commands.add('login', (params = {}) => {
}).then(() => {
cy.visit(url); // After successful login, you can switch to the specified page, which is the home page by default
cy.get('.initial-load-spinner', { timeout: constants.timeout.maxTimeout })
cy.get(".dashboard-content .product-name").contains("Harvester")

if (multiTenant !== 'true') {
cy.get(".dashboard-content .product-name").contains("Harvester")

Cypress.config('clusterId', 'local');
} else {
cy.get('[data-testid="top-level-menu"]')

if (!Cypress.config('clusterId')) {
cy.window().then(async (win) => {
return cy.wrap(win.$nuxt.$store.getters['management/byId'](CAPI.RANCHER_CLUSTER, 'fleet-default/harvester')).then((cluster) => {
const clusterId = cluster?.status?.clusterName;
console.log('clusterId', clusterId)
Cypress.config('clusterId', clusterId);
})
})
}
}
});
})
});
Expand Down
42 changes: 42 additions & 0 deletions cypress/testcases/users/user.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { RancherPageUrl } from "@/constants/constants";
import UserPage from "@/pageobjects/rancher/user.po";

const user = new UserPage();

describe("Setup users", () => {
it("Setup users", () => {
cy.login({
username: "admin",
});

user.create({
username: "cluster-owner",
newPassword: "password1234",
confirmPassword: "password1234"
})

user.create({
username: "cluster-member",
newPassword: "password1234",
confirmPassword: "password1234"
})

user.create({
username: "project-owner",
newPassword: "password1234",
confirmPassword: "password1234"
})

user.create({
username: "project-member",
newPassword: "password1234",
confirmPassword: "password1234"
})
})

it.only('Add users to cluster', () => {
cy.login({
username: "admin",
});
})
})
4 changes: 2 additions & 2 deletions cypress/testcases/virtualmachines/virtual-machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('VM Form Validation', () => {
* 4. Validate the create request
* 5. Validate the config and yaml should show
*/
it('Create a vm with all the default values', () => {
it.only('Create a vm with all the default values', () => {
const VM_NAME = generateName('test-vm-create');
const namespace = 'default'
const imageEnv = Cypress.env('image');
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('VM runStategy Validation (Halted)', () => {

const namespace = 'default'

it.only('Craete VM use Halted (Run Strategy)', () => {
it('Craete VM use Halted (Run Strategy)', () => {
vms.goToCreate();

const imageEnv = Cypress.env('image');
Expand Down
15 changes: 8 additions & 7 deletions cypress/utils/components/cru-resource.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class CruResourcePo extends PagePo {
}

public create(value: any, urlWithNamespace?: boolean) {
cy.visit(`/harvester/c/local/${this.type}/create`)
cy.visit(`/harvester/c/${Cypress.config('clusterId')}/${this.type}/create`)

this.setValue(value)

Expand Down Expand Up @@ -89,9 +89,9 @@ export default class CruResourcePo extends PagePo {
edit?: boolean;
} = {}) {
if (namespace) {
cy.intercept('POST', `/v1/harvester/${this.realType}s/${namespace}`).as('create');
cy.intercept('POST', `**/v1/harvester/${this.realType}s/${namespace}`).as('create');
} else {
cy.intercept('POST', `/v1/harvester/${this.realType}s`).as('create');
cy.intercept('POST', `**/v1/harvester/${this.realType}s`).as('create');
}

this.clickFooterBtn(buttonText)
Expand All @@ -101,7 +101,7 @@ export default class CruResourcePo extends PagePo {
}

public delete(namespace:any, name:string, displayName?: string) {
cy.visit(`/harvester/c/local/${this.type}`)
cy.visit(`/harvester/c/${Cypress.config('clusterId')}/${this.type}`)

this.clickAction(displayName || name, 'Delete')

Expand All @@ -113,7 +113,7 @@ export default class CruResourcePo extends PagePo {
id = `${namespace}/${name}`;
}

cy.intercept('DELETE', `/v1/harvester/${this.realType}s/${id}*`).as('delete');
cy.intercept('DELETE', `**/v1/harvester/${this.realType}s/${id}*`).as('delete');
cy.get(this.confirmRemove).contains('Delete').click();
cy.wait('@delete').then(res => {
cy.window().then((win) => {
Expand Down Expand Up @@ -258,8 +258,9 @@ export default class CruResourcePo extends PagePo {
}

public goToList() {
cy.intercept('GET', `/v1/harvester/${this.realType}s`).as('goToList');
cy.visit(`/harvester/c/local/${this.type}`)
cy.intercept('GET', `**/v1/harvester/${this.realType}s`).as('goToList');

cy.visit(`/harvester/c/${Cypress.config('clusterId')}/${this.type}`)
cy.wait('@goToList');
}

Expand Down

0 comments on commit dccd266

Please sign in to comment.