Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
n313893254 committed Aug 18, 2023
1 parent dccd266 commit 64368d8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
3 changes: 2 additions & 1 deletion cypress/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export const PageUrl = {
virtualMachine: '/harvester/c/local/kubevirt.io.virtualmachine',
vmNetwork: '/harvester/c/local/harvesterhci.io.networkattachmentdefinition',
namespace: '/harvester/c/local/namespace',
volumeSnapshot: '/harvester/c/local/harvesterhci.io.volumesnapshot'
volumeSnapshot: '/harvester/c/local/harvesterhci.io.volumesnapshot',
clusterMember: `/harvester/c/${Cypress.config('clusterId')}/management.cattle.io.clusterroletemplatebinding`
}

export const RancherPageUrl = {
Expand Down
24 changes: 11 additions & 13 deletions cypress/pageobjects/clusterMembers.po.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CruResourcePo from '@/utils/components/cru-resource.po';
import { MANAGEMENT } from '@/constants/types'
import LabeledSelectPo from '@/utils/components/labeled-select.po';
import RadioButtonPo from '@/utils/components/radio-button.po';

export default class UserPo extends CruResourcePo {
constructor() {
Expand All @@ -10,25 +11,22 @@ export default class UserPo extends CruResourcePo {
}

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

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

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

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

this.clusterPermissions().input(value?.clusterPermissions)
}

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

this.setValue(value)

Expand All @@ -42,10 +40,10 @@ export default class UserPo extends CruResourcePo {
buttonText?:string,
edit?: boolean;
} = {}) {
cy.intercept('POST', `/v3/users`).as('create');
cy.intercept('POST', `/v3/clusterroletemplatebindings`).as('createClusterMember');

this.clickFooterBtn(buttonText)
cy.wait('@create').then(res => {
cy.wait('@createClusterMember').then(res => {
expect(res.response?.statusCode, `Create ${this.type} success`).to.equal(201);
})
}
Expand Down
7 changes: 4 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Cypress.Commands.add('login', (params = {}) => {
headers: {
'x-api-csrf': CSRF
}
}).then(() => {
}).then(async () => {
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 })

Expand All @@ -51,14 +51,15 @@ Cypress.Commands.add('login', (params = {}) => {
cy.get('[data-testid="top-level-menu"]')

if (!Cypress.config('clusterId')) {
cy.window().then(async (win) => {
await cy.window().then(async (win) => {
// Rancher integration spec create cluster: 'fleet-default/harvester'
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
24 changes: 15 additions & 9 deletions cypress/testcases/users/user.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { RancherPageUrl } from "@/constants/constants";
import { RancherPageUrl, PageUrl } from "@/constants/constants";
import UserPage from "@/pageobjects/rancher/user.po";
import ClusterMemberPage from "@/pageobjects/clusterMembers.po";

const user = new UserPage();
const clusterMember = new ClusterMemberPage();

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",
Expand All @@ -33,10 +29,20 @@ describe("Setup users", () => {
confirmPassword: "password1234"
})
})
})

it.only('Add users to cluster', () => {
cy.login({
describe("Add users to cluster", () => {
beforeEach(() => {
cy.login({
username: "admin",
url: PageUrl.clusterMember
});
});

it('Add users to cluster', () => {
clusterMember.create({
selectMember: 'cluster-member',
clusterPermissions: 'Member'
})
})
})
46 changes: 45 additions & 1 deletion cypress/testcases/virtualmachines/virtual-machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,50 @@ const constants = new Constants();
const namespaces = new NamespacePage();
const imagePO = new ImagePage();

const roles = Cypress.env('roles');

console.log(roles, 'roles')

roles.map(role => {
describe(`${role}: VM Form Validation`, () => {
beforeEach(() => {
cy.login({
username: role,
url: PageUrl.virtualMachine
});
});

/**
* 1. Login
* 2. Navigate to the VM create page
* 3. Input required values
* 4. Validate the create request
* 5. Validate the config and yaml should show
*/
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');

const value = {
name: VM_NAME,
cpu: '1',
memory: '1',
image: Cypress._.toLower(imageEnv.name),
namespace,
}

vms.create(value)

vms.goToConfigDetail(VM_NAME);

vms.goToYamlEdit(VM_NAME);

vms.delete(namespace, VM_NAME)
});
})
})

describe('VM Form Validation', () => {
beforeEach(() => {
cy.login({url: PageUrl.virtualMachine});
Expand All @@ -24,7 +68,7 @@ describe('VM Form Validation', () => {
* 4. Validate the create request
* 5. Validate the config and yaml should show
*/
it.only('Create a vm with all the default values', () => {
it('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

0 comments on commit 64368d8

Please sign in to comment.