Skip to content

Commit

Permalink
Dev sequencing (#1275)
Browse files Browse the repository at this point in the history
  • Loading branch information
cohansen authored May 17, 2024
1 parent fb42f8c commit d0150f9
Show file tree
Hide file tree
Showing 88 changed files with 9,432 additions and 486 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ node_modules
test-results
unit-test-results
*.local
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
4 changes: 3 additions & 1 deletion e2e-tests/fixtures/Dictionaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export class Dictionaries {
this.updatePage(page);
}

async createDictionary() {
async createDictionary(): Promise<string> {
await expect(this.tableRow).not.toBeVisible();
await this.fillInputFile();
await this.createButton.click();
await this.tableRow.waitFor({ state: 'attached' });
await this.tableRow.waitFor({ state: 'visible' });
await expect(this.tableRow).toBeVisible();

return this.dictionaryName;
}

/**
Expand Down
30 changes: 15 additions & 15 deletions e2e-tests/fixtures/ExpansionRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { expect, type Locator, type Page } from '@playwright/test';
import { adjectives, animals, colors, uniqueNamesGenerator } from 'unique-names-generator';
import { fillEditorText } from '../utilities/editor.js';
import { getOptionValueFromText } from '../utilities/selectors.js';
import { Dictionaries } from './Dictionaries.js';
import { Models } from './Models.js';
import { Parcels } from './Parcels.js';

export class ExpansionRules {
cancelButton: Locator;
Expand All @@ -12,13 +12,13 @@ export class ExpansionRules {
confirmModalDeleteButton: Locator;
inputActivityType: Locator;
inputActivityTypeSelector: string = 'select[name="activityType"]';
inputCommandDictionary: Locator;
inputCommandDictionarySelector: string = 'select[name="commandDictionary"]';
inputEditor: Locator;
inputModel: Locator;
inputModelSelector: string = 'select[name="modelId"]';
inputName: Locator;
inputNameSelector: string = 'input[name="name"]';
inputParcel: Locator;
inputParcelSelector: string = 'select[name="parcel"]';
newButton: Locator;
ruleActivityType = 'PeelBanana';
ruleLogic: string = `export default function({ activityInstance: ActivityType }): ExpansionReturn { return [C.FSW_CMD_0({ boolean_arg_0: true, enum_arg_0: "OFF", float_arg_0: 0.0 })]; }`;
Expand All @@ -29,7 +29,7 @@ export class ExpansionRules {

constructor(
public page: Page,
public dictionaries: Dictionaries,
public parcels: Parcels,
public models: Models,
) {
this.updatePage(page);
Expand All @@ -41,7 +41,7 @@ export class ExpansionRules {
await this.newButton.click();
await this.page.waitForURL(`${baseURL}/expansion/rules/new`);
await expect(this.saveButton).toBeDisabled();
await this.selectCommandDictionary();
await this.selectParcel();
await this.selectModel();
await this.selectActivityType();
await this.fillInputName();
Expand Down Expand Up @@ -103,15 +103,6 @@ export class ExpansionRules {
await this.inputActivityType.evaluate(e => e.blur());
}

async selectCommandDictionary() {
const { dictionaryName } = this.dictionaries;
await this.page.waitForSelector(`option:has-text("${dictionaryName} - 1.0.0")`, { state: 'attached' });
const value = await getOptionValueFromText(this.page, this.inputCommandDictionarySelector, dictionaryName);
await this.inputCommandDictionary.focus();
await this.inputCommandDictionary.selectOption(value);
await this.inputCommandDictionary.evaluate(e => e.blur());
}

async selectModel() {
const { modelName } = this.models;
await this.page.waitForSelector(`option:has-text("${modelName}")`, { state: 'attached' });
Expand All @@ -121,6 +112,15 @@ export class ExpansionRules {
await this.inputModel.evaluate(e => e.blur());
}

async selectParcel() {
const { parcelName } = this.parcels;
await this.page.waitForSelector(`option:has-text("${parcelName}")`, { state: 'attached' });
const value = await getOptionValueFromText(this.page, this.inputParcelSelector, parcelName);
await this.inputParcel.focus();
await this.inputParcel.selectOption(value);
await this.inputParcel.evaluate(e => e.blur());
}

updatePage(page: Page): void {
this.cancelButton = page.locator(`button:has-text("Cancel")`);
this.closeButton = page.locator(`button:has-text("Close")`);
Expand All @@ -129,7 +129,7 @@ export class ExpansionRules {
`.modal:has-text("Delete Expansion Rule") >> button:has-text("Delete")`,
);
this.inputActivityType = page.locator(this.inputActivityTypeSelector);
this.inputCommandDictionary = page.locator(this.inputCommandDictionarySelector);
this.inputParcel = page.locator(this.inputParcelSelector);
this.inputEditor = page.locator('.panel >> textarea.inputarea');
this.inputModel = page.locator(this.inputModelSelector);
this.inputName = page.locator(this.inputNameSelector);
Expand Down
30 changes: 15 additions & 15 deletions e2e-tests/fixtures/ExpansionSets.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { expect, type Locator, type Page } from '@playwright/test';
import { adjectives, animals, colors, uniqueNamesGenerator } from 'unique-names-generator';
import { getOptionValueFromText } from '../utilities/selectors.js';
import { Dictionaries } from './Dictionaries.js';
import { ExpansionRules } from './ExpansionRules.js';
import { Models } from './Models.js';
import { Parcels } from './Parcels.js';

export class ExpansionSets {
inputCommandDictionary: Locator;
inputCommandDictionarySelector: string = 'select[name="commandDictionary"]';
inputModel: Locator;
inputModelSelector: string = 'select[name="modelId"]';
inputName: Locator;
inputNameSelector: string = 'input[name="name"]';
inputParcel: Locator;
inputParcelSelector: string = 'select[name="Parcel"]';
inputRule: Locator;
inputRuleSelector: string;
newButton: Locator;
Expand All @@ -20,7 +20,7 @@ export class ExpansionSets {

constructor(
public page: Page,
public dictionaries: Dictionaries,
public parcels: Parcels,
public models: Models,
public expansionRules: ExpansionRules,
) {
Expand All @@ -34,7 +34,7 @@ export class ExpansionSets {
await this.newButton.click();
await this.page.waitForURL(`${baseURL}/expansion/sets/new`);
await expect(this.saveButton).toBeDisabled();
await this.selectCommandDictionary();
await this.selectParcel();
await this.selectModel();
await this.selectRule();
await this.fillInputName();
Expand All @@ -56,15 +56,6 @@ export class ExpansionSets {
await expect(this.setsNavButton).toHaveClass(/selected/);
}

async selectCommandDictionary() {
const { dictionaryName } = this.dictionaries;
await this.page.waitForSelector(`option:has-text("${dictionaryName} - 1.0.0")`, { state: 'attached' });
const value = await getOptionValueFromText(this.page, this.inputCommandDictionarySelector, dictionaryName);
await this.inputCommandDictionary.focus();
await this.inputCommandDictionary.selectOption(value);
await this.inputCommandDictionary.evaluate(e => e.blur());
}

async selectModel() {
const { modelName } = this.models;
await this.page.waitForSelector(`option:has-text("${modelName}")`, { state: 'attached' });
Expand All @@ -74,15 +65,24 @@ export class ExpansionSets {
await this.inputModel.evaluate(e => e.blur());
}

async selectParcel() {
const { parcelName } = this.parcels;
await this.page.waitForSelector(`option:has-text("${parcelName}")`, { state: 'attached' });
const value = await getOptionValueFromText(this.page, this.inputParcelSelector, parcelName);
await this.inputParcel.focus();
await this.inputParcel.selectOption(value);
await this.inputParcel.evaluate(e => e.blur());
}

async selectRule() {
await this.page.waitForSelector(this.inputRuleSelector, { state: 'attached' });
await this.inputRule.first().click();
}

updatePage(page: Page): void {
this.inputCommandDictionary = page.locator(this.inputCommandDictionarySelector);
this.inputModel = page.locator(this.inputModelSelector);
this.inputName = page.locator(this.inputNameSelector);
this.inputParcel = page.locator(this.inputParcelSelector);
this.inputRule = page.locator(this.inputRuleSelector);
this.newButton = page.locator(`button:has-text("New")`);
this.page = page;
Expand Down
74 changes: 74 additions & 0 deletions e2e-tests/fixtures/Parcels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Locator, Page, expect } from '@playwright/test';
import { adjectives, animals, colors, uniqueNamesGenerator } from 'unique-names-generator';

export class Parcels {
closeButton: Locator;
confirmModal: Locator;
confirmModalDeleteButton: Locator;
createButton: Locator;
nameField: Locator;
newButton: Locator;
parcelName: string;
tableRow: Locator;
tableRowDeleteButton: Locator;

constructor(public page: Page) {
this.parcelName = uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] });

this.updatePage(page);
}

async createParcel(dictionaryName: string) {
await this.newButton.click();
await this.page.getByText(dictionaryName).click();
await this.updatePage(this.page);
await expect(this.tableRow).not.toBeVisible();
await this.nameField.fill(this.parcelName);
await this.createButton.click();
await this.closeButton.click();
await this.tableRow.waitFor({ state: 'attached' });
await this.tableRow.waitFor({ state: 'visible' });
await expect(this.tableRow).toBeVisible();
}

async deleteParcel() {
await expect(this.tableRow).toBeVisible();
await expect(this.tableRowDeleteButton).not.toBeVisible();

await this.tableRow.hover();
await this.tableRowDeleteButton.waitFor({ state: 'attached' });
await this.tableRowDeleteButton.waitFor({ state: 'visible' });
await expect(this.tableRowDeleteButton).toBeVisible();

await expect(this.confirmModal).not.toBeVisible();
await this.tableRowDeleteButton.click();
await this.confirmModal.waitFor({ state: 'attached' });
await this.confirmModal.waitFor({ state: 'visible' });
await expect(this.confirmModal).toBeVisible();

await expect(this.confirmModalDeleteButton).toBeVisible();
await this.confirmModalDeleteButton.click();
await this.tableRow.waitFor({ state: 'detached' });
await this.tableRow.waitFor({ state: 'hidden' });
await expect(this.tableRow).not.toBeVisible();
}

async goto() {
await this.page.goto('/parcels', { waitUntil: 'networkidle' });
await this.page.waitForTimeout(250);
}

updatePage(page: Page): void {
this.closeButton = page.locator(`button:has-text("Close")`);
this.confirmModal = page.locator(`.modal:has-text("Delete Parcel")`);
this.confirmModalDeleteButton = page.locator(`.modal:has-text("Delete Parcel") >> button:has-text("Delete")`);
this.createButton = page.locator(`button:has-text("Save")`);
this.nameField = page.locator(`input[name="parcelName"]`);
this.newButton = page.locator(`button:has-text("New")`);
this.page = page;
this.tableRow = page.locator(`.ag-row:has-text("${this.parcelName}")`);
this.tableRowDeleteButton = page.locator(
`.ag-row:has-text("${this.parcelName}") >> button[aria-label="Delete Parcel"]`,
);
}
}
14 changes: 9 additions & 5 deletions e2e-tests/tests/expansion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@ import { Dictionaries } from '../fixtures/Dictionaries.js';
import { ExpansionRules } from '../fixtures/ExpansionRules.js';
import { ExpansionSets } from '../fixtures/ExpansionSets.js';
import { Models } from '../fixtures/Models.js';
import { Parcels } from '../fixtures/Parcels.js';
let context: BrowserContext;
let dictionaries: Dictionaries;
let expansionRules: ExpansionRules;
let expansionSets: ExpansionSets;
let models: Models;
let page: Page;
let parcels: Parcels;

test.beforeAll(async ({ browser }) => {
context = await browser.newContext();
page = await context.newPage();

models = new Models(page);
dictionaries = new Dictionaries(page);
expansionRules = new ExpansionRules(page, dictionaries, models);
expansionSets = new ExpansionSets(page, dictionaries, models, expansionRules);
parcels = new Parcels(page);
expansionRules = new ExpansionRules(page, parcels, models);
expansionSets = new ExpansionSets(page, parcels, models, expansionRules);

await models.goto();
await models.createModel();
await dictionaries.goto();
await dictionaries.createDictionary();
const dictionaryName = await dictionaries.createDictionary();
await parcels.goto();
await parcels.createParcel(dictionaryName);
await expansionRules.goto();
});

test.afterAll(async () => {
await models.goto();
await models.deleteModel();
await dictionaries.goto();
await dictionaries.deleteDictionary();
await parcels.goto();
await page.close();
await context.close();
});
Expand Down
34 changes: 34 additions & 0 deletions e2e-tests/tests/parcels.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import test, { type BrowserContext, type Page } from '@playwright/test';
import { Dictionaries } from '../fixtures/Dictionaries.js';
import { Parcels } from '../fixtures/Parcels.js';
let context: BrowserContext;
let dictionaries: Dictionaries;
let dictionaryName: string;
let parcels: Parcels;
let page: Page;

test.beforeAll(async ({ browser }) => {
context = await browser.newContext();
page = await context.newPage();
dictionaries = new Dictionaries(page);
parcels = new Parcels(page);

await dictionaries.goto();
dictionaryName = await dictionaries.createDictionary();
await parcels.goto();
});

test.afterAll(async () => {
await page.close();
await context.close();
});

test.describe.serial('Parcels', () => {
test('Create parcel', async () => {
await parcels.createParcel(dictionaryName);
});

test('Delete parcel', async () => {
await parcels.deleteParcel();
});
});
Loading

0 comments on commit d0150f9

Please sign in to comment.