Skip to content

Commit

Permalink
TPv2: Add Divisions Pages (#7203)
Browse files Browse the repository at this point in the history
* Add division page

* Merge package-lock

* Fix types

* Use type import

* Set header values

* Unit test fix
  • Loading branch information
shamrickus authored Nov 22, 2022
1 parent 2556e49 commit 3ff8ae5
Show file tree
Hide file tree
Showing 29 changed files with 5,658 additions and 4,891 deletions.
48 changes: 32 additions & 16 deletions experimental/traffic-portal/nightwatch/globals/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import * as https from "https";

import axios, {AxiosError} from "axios";
import {NightwatchBrowser} from "nightwatch";
import { ChangeLogsPageObject } from "nightwatch/page_objects/changeLogs";
import type { ChangeLogsPageObject } from "nightwatch/page_objects/changeLogs";
import type {CommonPageObject} from "nightwatch/page_objects/common";
import type {DeliveryServiceCardPageObject} from "nightwatch/page_objects/deliveryServiceCard";
import type {DeliveryServiceDetailPageObject} from "nightwatch/page_objects/deliveryServiceDetail";
import type {DeliveryServiceInvalidPageObject} from "nightwatch/page_objects/deliveryServiceInvalidationJobs";
import type { DivisionDetailPageObject } from "nightwatch/page_objects/divisionDetail";
import type { DivisionsPageObject } from "nightwatch/page_objects/divisionsTable";
import type {LoginPageObject} from "nightwatch/page_objects/login";
import type {ServersPageObject} from "nightwatch/page_objects/servers";
import { TenantDetailPageObject } from "nightwatch/page_objects/tenantDetail";
import { TenantsPageObject } from "nightwatch/page_objects/tenants";
import type { TenantDetailPageObject } from "nightwatch/page_objects/tenantDetail";
import type { TenantsPageObject } from "nightwatch/page_objects/tenants";
import type {UsersPageObject} from "nightwatch/page_objects/users";
import {
CDN,
Expand All @@ -34,7 +36,7 @@ import {
ResponseCDN,
ResponseDeliveryService,
RequestTenant,
ResponseTenant, TypeFromResponse, RequestSteeringTarget
ResponseTenant, TypeFromResponse, RequestSteeringTarget, ResponseDivision, RequestDivision
} from "trafficops-types";

declare module "nightwatch" {
Expand All @@ -47,6 +49,8 @@ declare module "nightwatch" {
deliveryServiceCard: () => DeliveryServiceCardPageObject;
deliveryServiceDetail: () => DeliveryServiceDetailPageObject;
deliveryServiceInvalidationJobs: () => DeliveryServiceInvalidPageObject;
divisionsDetail: () => DivisionDetailPageObject;
divisionsTable: () => DivisionsPageObject;
login: () => LoginPageObject;
servers: () => ServersPageObject;
tenants: () => TenantsPageObject;
Expand Down Expand Up @@ -76,8 +80,11 @@ export interface CreatedData {
ds2: ResponseDeliveryService;
steeringDS: ResponseDeliveryService;
tenant: ResponseTenant;
division: ResponseDivision;
}

const testData = {};

const globals = {
adminPass: "twelve12",
adminUser: "admin",
Expand Down Expand Up @@ -140,11 +147,11 @@ const globals = {
}

try {
const testData = globals.testData as CreatedData;
const data = testData as CreatedData;
resp = await client.post(`${apiUrl}/cdns`, JSON.stringify(cdn));
respCDN = resp.data.response;
console.log(`Successfully created CDN ${respCDN.name}`);
testData.cdn = respCDN;
data.cdn = respCDN;

const ds: RequestDeliveryService = {
active: false,
Expand Down Expand Up @@ -184,32 +191,32 @@ const globals = {
resp = await client.post(`${apiUrl}/deliveryservices`, JSON.stringify(ds));
let respDS: ResponseDeliveryService = resp.data.response[0];
console.log(`Successfully created DS '${respDS.displayName}'`);
testData.ds = respDS;
data.ds = respDS;

ds.displayName = `test DS2${globals.uniqueString}`;
ds.xmlId = `testDS2${globals.uniqueString}`;
resp = await client.post(`${apiUrl}/deliveryservices`, JSON.stringify(ds));
respDS = resp.data.response[0];
console.log(`Successfully created DS '${respDS.displayName}'`);
testData.ds2 = respDS;
data.ds2 = respDS;

ds.displayName = `test steering DS${globals.uniqueString}`;
ds.xmlId = `testSDS${globals.uniqueString}`;
ds.typeId = steeringType.id;
resp = await client.post(`${apiUrl}/deliveryservices`, JSON.stringify(ds));
respDS = resp.data.response[0];
console.log(`Successfully created DS '${respDS.displayName}'`);
testData.steeringDS = respDS;
data.steeringDS = respDS;

const target: RequestSteeringTarget = {
targetId: testData.ds.id,
targetId: data.ds.id,
typeId: steeringWeightType.id,
value: 1
};
await client.post(`${apiUrl}/steering/${testData.steeringDS.id}/targets`, JSON.stringify(target));
target.targetId = testData.ds2.id;
await client.post(`${apiUrl}/steering/${testData.steeringDS.id}/targets`, JSON.stringify(target));
console.log(`Created steering targets for ${testData.steeringDS.displayName}`);
await client.post(`${apiUrl}/steering/${data.steeringDS.id}/targets`, JSON.stringify(target));
target.targetId = data.ds2.id;
await client.post(`${apiUrl}/steering/${data.steeringDS.id}/targets`, JSON.stringify(target));
console.log(`Created steering targets for ${data.steeringDS.displayName}`);

const tenant: RequestTenant = {
active: true,
Expand All @@ -219,14 +226,23 @@ const globals = {
resp = await client.post(`${apiUrl}/tenants`, JSON.stringify(tenant));
const respTenant: ResponseTenant = resp.data.response;
console.log(`Successfully created Tenant ${respTenant.name}`);
(globals.testData as CreatedData).tenant = respTenant;
data.tenant = respTenant;

const division: RequestDivision = {
name: `testD${globals.uniqueString}`
};
resp = await client.post(`${apiUrl}/divisions`, JSON.stringify(division));
const respDivision: ResponseDivision = resp.data.response;
console.log(`Successfully created Division ${respDivision.name}`);
data.division = respDivision;
} catch(e) {
console.error((e as AxiosError).message);
throw e;
}
done();
},
beforeEach: (browser: NightwatchBrowser, done: () => void): void => {
browser.globals.testData = testData as CreatedData;
browser.page.login()
.navigate().section.loginForm
.loginAndWait(browser.globals.adminUser, browser.globals.adminPass);
Expand All @@ -235,7 +251,7 @@ const globals = {
done();
});
},
testData: {},
testData,
trafficOpsURL: "https://localhost:6443",
uniqueString: new Date().getTime().toString()
};
Expand Down
10 changes: 5 additions & 5 deletions experimental/traffic-portal/nightwatch/globals/tables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

import type { EnhancedElementInstance, EnhancedPageObject, EnhancedSectionInstance } from "nightwatch";
import type { Awaitable, EnhancedElementInstance, EnhancedPageObject, EnhancedSectionInstance } from "nightwatch";

/**
* TableSectionCommands is the base type for page object sections representing
Expand All @@ -36,7 +36,7 @@ export const columnMenuSelector = "div.toggle-columns > button.mat-menu-trigger"
export const searchboxSelector = "input[name='fuzzControl']";

/**
* Gets the state of an AG-Grid column by checking whether or not it's checked
* Gets the state of an AG-Grid column by checking whether it's checked
* in the column visibility menu (doesn't actually verify that this means the
* column is visible).
*
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function getColumnState(this: TableSectionCommands, column: string)
* @returns The calling command section for call-chaining the way Nightwatch
* likes to do.
*/
export function searchText<T extends TableSectionCommands>(this: T, text: string): T {
export function searchText<T extends TableSectionCommands>(this: T, text: string): Awaitable<T, null> {
return this.setValue(searchboxSelector, text);
}

Expand All @@ -96,8 +96,8 @@ export function searchText<T extends TableSectionCommands>(this: T, text: string
* @returns The calling command section for call-chaining the way Nightwatch
* likes to do.
*/
export function toggleColumn<T extends TableSectionCommands>(this: T, column: string): T {
return this.click(columnMenuSelector).click(`mat-input[name='${column}']`).click(columnMenuSelector);
export function toggleColumn<T extends TableSectionCommands>(this: T, column: string): Awaitable<T, null> {
return this.click(columnMenuSelector).click(`mat-input[name='${column}']`).click(columnMenuSelector) as Awaitable<T, null>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { EnhancedPageObject } from "nightwatch";

/**
* Defines the PageObject for Division Details.
*/
export type DivisionDetailPageObject = EnhancedPageObject<{}, typeof divisionDetailPageObject.elements>;

const divisionDetailPageObject = {
elements: {
id: {
selector: "input[name='id']"
},
lastUpdated: {
selector: "input[name='lastUpdated']"
},
name: {
selector: "input[name='name']"
},
saveBtn: {
selector: "button[type='submit']"
}
},
};

export default divisionDetailPageObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { EnhancedPageObject, EnhancedSectionInstance, NightwatchAPI } from "nightwatch";

import { TABLE_COMMANDS, TableSectionCommands } from "../globals/tables";

/**
* Defines the Divisions table commands
*/
type DivisionsTableCommands = TableSectionCommands;

/**
* Defines the Page Object for the Divisions page.
*/
export type DivisionsPageObject = EnhancedPageObject<{}, {},
EnhancedSectionInstance<DivisionsTableCommands>>;

const divisionsPageObject = {
api: {} as NightwatchAPI,
sections: {
divisionsTable: {
commands: {
...TABLE_COMMANDS
},
elements: {},
selector: "mat-card"
}
},
url(): string {
return `${this.api.launchUrl}/core/divisions`;
}
};

export default divisionsPageObject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

describe("Division Detail Spec", () => {
it("Test division", () => {
const page = browser.page.divisionDetail();
browser.url(`${page.api.launchUrl}/core/divisions/${browser.globals.testData.division.id}`, res => {
browser.assert.ok(res.status === 0);
page.waitForElementVisible("mat-card")
.assert.enabled("@name")
.assert.enabled("@saveBtn")
.assert.not.enabled("@id")
.assert.not.enabled("@lastUpdated")
.assert.valueEquals("@name", browser.globals.testData.division.name)
.assert.valueEquals("@id", String(browser.globals.testData.division.id));
});
});

it("New division", () => {
const page = browser.page.divisionDetail();
browser.url(`${page.api.launchUrl}/core/divisions/new`, res => {
browser.assert.ok(res.status === 0);
page.waitForElementVisible("mat-card")
.assert.enabled("@name")
.assert.enabled("@saveBtn")
.assert.not.elementPresent("@id")
.assert.not.elementPresent("@lastUpdated")
.assert.valueEquals("@name", "");
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

describe("Divisions Spec", () => {
it("Loads elements", async () => {
browser.page.divisionsTable().navigate()
.waitForElementPresent("input[name=fuzzControl]");
browser.elements("css selector", "div.ag-row", rows => {
browser.assert.ok(rows.status === 0);
browser.assert.ok((rows.value as []).length >= 2);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
* limitations under the License.
*/

import { NightwatchTypedCallbackResult } from "nightwatch";

describe("Tenants Spec", () => {
it("Loads elements", async () => {
browser.page.tenants().navigate()
.waitForElementPresent("input[name=fuzzControl]");
browser.elements("css selector", "div.ag-row", rows => {
browser.assert.ok(rows.status === 0);
browser.assert.ok((rows as NightwatchTypedCallbackResult<{ELEMENT: string}[]>).value.length >= 2);
browser.assert.ok((rows.value as []).length >= 2);
});
});
});
3 changes: 1 addition & 2 deletions experimental/traffic-portal/nightwatch/tsconfig.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"target": "es5",
"types": [
"node",
"nightwatch",
"mocha"
"nightwatch"
],
"rootDirs": ["./page_objects", "./tests", "./globals"]
}
Expand Down
Loading

0 comments on commit 3ff8ae5

Please sign in to comment.