Skip to content

Commit

Permalink
Create tests for VM dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
rawagner committed Jan 15, 2020
1 parent dacb3cd commit 90fbd50
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export class DetailView {
await isLoaded();
}

async navigateToDashboard() {
await this.navigateToListView();
await VmsListView.vmListByName(this.name).click();
await isLoaded();
await clickHorizontalTab('Dashboard');
await isLoaded();
}

async navigateToConsoles() {
await this.navigateToListView();
await VmsListView.vmListByName(this.name).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const rhelTinyCommonTemplateName = execSync(
"kubectl get template -n openshift | grep rhel7-desktop-tiny | awk '{print $1}'",
).toString();

export const NOT_AVAILABLE = 'Not available';

// TIMEOUTS
const SEC = 1000;
export const CLONE_VM_TIMEOUT_SECS = 720 * SEC;
Expand Down Expand Up @@ -56,6 +58,7 @@ export const COMMON_TEMPLATES_REVISION = '1';

export enum TAB {
Consoles = 'Consoles',
Dashboard = 'Dashboard',
Disks = 'Disks',
Events = 'Events',
NetworkInterfaces = 'Network Interfaces',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { browser, ExpectedConditions as until } from 'protractor';
import { testName } from '@console/internal-integration-tests/protractor.conf';
import {
addLeakableResource,
createResources,
removeLeakedResources,
} from '@console/shared/src/test-utils/utils';
import { VirtualMachineModel } from '../../src/models';
import {
vmDetailsName,
vmDetailsNamespace,
vmDetailsNode,
vmDetailsIPAddress,
vmStatus,
vmInventoryNICs,
vmInventoryDisks,
} from '../views/dashboard.view';
import { getVMManifest, hddDisk, multusNetworkInterface, multusNAD } from './utils/mocks';
import { VirtualMachine } from './models/virtualMachine';
import {
VM_STATUS,
VM_BOOTUP_TIMEOUT_SECS,
VM_ACTION,
VM_IMPORT_TIMEOUT_SECS,
TAB,
VM_STOP_TIMEOUT_SECS,
NOT_AVAILABLE,
PAGE_LOAD_TIMEOUT_SECS,
} from './utils/consts';

describe('Test VM dashboard', () => {
const leakedResources = new Set<string>();
const testVM = getVMManifest('URL', testName, null, 'foo');

let vm: VirtualMachine;

afterAll(async () => {
removeLeakedResources(leakedResources);
});

beforeAll(async () => {
createResources([multusNAD, testVM]);
addLeakableResource(leakedResources, testVM);
vm = new VirtualMachine(testVM.metadata);
await vm.navigateToDashboard();
try {
await browser.wait(
until.not(until.textToBePresentInElement(vmStatus, VM_STATUS.Off)),
PAGE_LOAD_TIMEOUT_SECS,
);
} catch (ex) {
// continue, this is optional condition
// we want to wait for import to start but in some cases it may have already completed
}
await browser.wait(
until.textToBePresentInElement(vmStatus, VM_STATUS.Off),
VM_IMPORT_TIMEOUT_SECS,
);
}, VM_IMPORT_TIMEOUT_SECS);

it('Inventory card', async () => {
expect(vmInventoryNICs.getText()).toEqual('1 NIC');
expect(vmInventoryNICs.$('a').getAttribute('href')).toMatch(
new RegExp(`.*/k8s/ns/${vm.namespace}/${VirtualMachineModel.plural}/${vm.name}/nics`),
);
expect(vmInventoryDisks.getText()).toEqual('2 Disks');
expect(vmInventoryDisks.$('a').getAttribute('href')).toMatch(
new RegExp(`.*/k8s/ns/${vm.namespace}/${VirtualMachineModel.plural}/${vm.name}/disks`),
);

await vm.addDisk(hddDisk);
await vm.addNIC(multusNetworkInterface);
await vm.navigateToTab(TAB.Dashboard);

expect(vmInventoryNICs.getText()).toEqual('2 NICs');
expect(vmInventoryDisks.getText()).toEqual('3 Disks');
});

it('Status card', async () => {
expect(vmStatus.getText()).toEqual(VM_STATUS.Off);

await vm.action(VM_ACTION.Start, true, VM_BOOTUP_TIMEOUT_SECS);
await vm.navigateToTab(TAB.Dashboard);

expect(vmStatus.getText()).toEqual(VM_STATUS.Running);
});

it('Details card', async () => {
expect(vmDetailsName.getText()).toEqual(vm.name);
expect(vmDetailsNamespace.getText()).toEqual(vm.namespace);
expect(vmDetailsNode.getText()).not.toEqual(NOT_AVAILABLE);
expect(vmDetailsIPAddress.getText()).not.toEqual(NOT_AVAILABLE);

await vm.action(VM_ACTION.Stop, true, VM_STOP_TIMEOUT_SECS);
await vm.navigateToTab(TAB.Dashboard);

expect(vmDetailsNode.getText()).toEqual(NOT_AVAILABLE);
expect(vmDetailsIPAddress.getText()).toEqual(NOT_AVAILABLE);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@console/shared/src/test-utils/utils';
import * as editCdView from '../views/editCDView';
import * as virtualMachineView from '../views/virtualMachine.view';
import { VM_CREATE_AND_EDIT_TIMEOUT_SECS, STORAGE_CLASS } from './utils/consts';
import { VM_CREATE_AND_EDIT_TIMEOUT_SECS, STORAGE_CLASS, NOT_AVAILABLE } from './utils/consts';
import { selectOptionByOptionValue } from './utils/utils';
import { VirtualMachine } from './models/virtualMachine';
import { vmConfig, getProvisionConfigs, getTestDataVolume } from './vm.wizard.configs';
Expand Down Expand Up @@ -55,7 +55,7 @@ describe('KubeVirt VM detail - edit cdroms', () => {
await browser.wait(
until.textToBePresentInElement(
virtualMachineView.vmDetailCd(vm.namespace, vm.name),
'Not available',
NOT_AVAILABLE,
),
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { $, $$ } from 'protractor';

export const vmDetails = $$('.co-details-card__body dd');
export const vmDetailsName = vmDetails.get(0);
export const vmDetailsNamespace = vmDetails.get(1).$('.co-resource-item__resource-name');
export const vmDetailsCreated = vmDetails.get(2);
export const vmDetailsNode = vmDetails.get(3);
export const vmDetailsIPAddress = vmDetails.get(4);

export const vmStatus = $('.co-status-card__health-body > span');

export const vmInventoryItems = $$('.co-inventory-card__item');
export const vmInventoryNICs = vmInventoryItems.get(0);
export const vmInventoryDisks = vmInventoryItems.get(1);

0 comments on commit 90fbd50

Please sign in to comment.