-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for renaming and deleting views
- Loading branch information
1 parent
2271b0d
commit 27e8d9b
Showing
4 changed files
with
233 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { expect, type Locator, type Page } from '@playwright/test'; | ||
import { adjectives, animals, colors, uniqueNamesGenerator } from 'unique-names-generator'; | ||
|
||
export class View { | ||
confirmModal: Locator; | ||
confirmModalDeleteButton: Locator; | ||
invalidViewFilePath: string = 'e2e-tests/data/invalid-view.json'; | ||
navButtonView: Locator; | ||
navButtonViewMenu: Locator; | ||
navButtonViewMenuTitle: Locator; | ||
navButtonViewRenameViewMenuButton: Locator; | ||
navButtonViewSaveAsMenuButton: Locator; | ||
navButtonViewSavedViewsMenuButton: Locator; | ||
navButtonViewUploadViewMenuButton: Locator; | ||
renameViewMenuSaveViewButton: Locator; | ||
saveAsMenuSaveAsButton: Locator; | ||
tableRowDeleteButtonSelector: (viewName: string) => Locator; | ||
tableRowSelector: (viewName: string) => Locator; | ||
validViewFilePath: string = 'e2e-tests/data/valid-view.json'; | ||
|
||
constructor(public page: Page) { | ||
this.updatePage(page); | ||
} | ||
|
||
async createView(viewName: string = this.createViewName()) { | ||
await this.openSaveAs(); | ||
await this.fillViewInputName(viewName); | ||
await this.saveAsMenuSaveAsButton.click(); | ||
} | ||
|
||
createViewName() { | ||
return uniqueNamesGenerator({ dictionaries: [adjectives, colors, animals] }); | ||
} | ||
|
||
async deleteView(viewName: string) { | ||
await this.openSavedViews(); | ||
await expect(this.tableRowSelector(viewName)).toBeVisible(); | ||
await expect(this.tableRowDeleteButtonSelector(viewName)).not.toBeVisible(); | ||
|
||
await this.tableRowSelector(viewName).hover(); | ||
await this.tableRowDeleteButtonSelector(viewName).waitFor({ state: 'attached' }); | ||
await this.tableRowDeleteButtonSelector(viewName).waitFor({ state: 'visible' }); | ||
await expect(this.tableRowDeleteButtonSelector(viewName)).toBeVisible(); | ||
|
||
await expect(this.confirmModal).not.toBeVisible(); | ||
await this.tableRowDeleteButtonSelector(viewName).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.tableRowSelector(viewName).waitFor({ state: 'detached' }); | ||
await this.tableRowSelector(viewName).waitFor({ state: 'hidden' }); | ||
await expect(this.tableRowSelector(viewName)).not.toBeVisible(); | ||
} | ||
|
||
async fillViewInputFile(planFilePath: string = this.validViewFilePath) { | ||
const viewFileInput = this.page.locator('.modal-content input[name="file"]'); | ||
await viewFileInput.focus(); | ||
await viewFileInput.setInputFiles(planFilePath); | ||
await viewFileInput.evaluate(e => e.blur()); | ||
} | ||
|
||
async fillViewInputName(viewName: string = this.createViewName()) { | ||
const viewNameInput = this.page.locator('.modal-content input[name="name"]'); | ||
await viewNameInput.focus(); | ||
await viewNameInput.fill(viewName); | ||
await viewNameInput.evaluate(e => e.blur()); | ||
} | ||
|
||
async openRenameView() { | ||
await expect(this.navButtonViewRenameViewMenuButton).not.toBeVisible(); | ||
await this.openViewMenu(); | ||
await expect(this.navButtonViewRenameViewMenuButton).toBeVisible(); | ||
await this.navButtonViewRenameViewMenuButton.click(); | ||
} | ||
|
||
async openSaveAs() { | ||
await this.openViewMenu(); | ||
await expect(this.navButtonViewSaveAsMenuButton).toBeVisible(); | ||
await this.navButtonViewSaveAsMenuButton.click(); | ||
} | ||
|
||
async openSavedViews() { | ||
await this.openViewMenu(); | ||
await expect(this.navButtonViewSavedViewsMenuButton).toBeVisible(); | ||
await this.navButtonViewSavedViewsMenuButton.click(); | ||
await expect(this.page.locator('.modal .modal-header:has-text("Saved Views")')).toBeVisible(); | ||
} | ||
|
||
async openViewMenu() { | ||
this.navButtonView.hover(); | ||
await expect(this.navButtonViewMenu).toBeVisible(); | ||
} | ||
|
||
async renameView(viewName: string) { | ||
await this.openRenameView(); | ||
await this.fillViewInputName(viewName); | ||
await this.renameViewMenuSaveViewButton.click(); | ||
} | ||
|
||
updatePage(page: Page): void { | ||
this.confirmModal = page.locator(`.modal:has-text("Delete View")`); | ||
this.confirmModalDeleteButton = page.locator(`.modal:has-text("Delete View") >> button:has-text("Delete")`); | ||
this.navButtonView = page.locator('.view-menu-button'); | ||
this.navButtonViewMenu = page.locator(`.view-menu`); | ||
this.navButtonViewMenuTitle = page.locator(`.view-menu-button .nav-button-title`); | ||
this.navButtonViewSaveAsMenuButton = page.locator(`.view-menu .menu-item:has-text("Save as")`); | ||
this.navButtonViewUploadViewMenuButton = page.locator(`.view-menu .menu-item:has-text("Upload view file")`); | ||
this.navButtonViewSavedViewsMenuButton = page.locator(`.view-menu .menu-item:has-text("Browse saved views")`); | ||
this.navButtonViewRenameViewMenuButton = page.locator(`.view-menu .menu-item:has-text("Rename view")`); | ||
this.renameViewMenuSaveViewButton = page.locator('.modal .st-button:has-text("Save View")'); | ||
this.saveAsMenuSaveAsButton = page.locator('.modal .st-button:has-text("Save View")'); | ||
this.tableRowSelector = (viewName: string) => page.locator(`.ag-row:has-text("${viewName}")`); | ||
this.tableRowDeleteButtonSelector = (viewName: string) => | ||
page.locator(`.ag-row:has-text("${viewName}") >> button[aria-label="Delete View"]`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Constraints } from '../fixtures/Constraints.js'; | ||
import { Models } from '../fixtures/Models.js'; | ||
import { Plan } from '../fixtures/Plan.js'; | ||
import { Plans } from '../fixtures/Plans.js'; | ||
import { expect, test, type BrowserContext, type Page } from '../fixtures/PlaywrightTest.js'; | ||
import { SchedulingConditions } from '../fixtures/SchedulingConditions.js'; | ||
import { SchedulingGoals } from '../fixtures/SchedulingGoals.js'; | ||
import { View } from '../fixtures/View.js'; | ||
|
||
let context: BrowserContext; | ||
let models: Models; | ||
let page: Page; | ||
let plan: Plan; | ||
let plans: Plans; | ||
let view: View; | ||
let constraints: Constraints; | ||
let schedulingConditions: SchedulingConditions; | ||
let schedulingGoals: SchedulingGoals; | ||
|
||
test.beforeAll(async ({ browser }) => { | ||
context = await browser.newContext(); | ||
page = await context.newPage(); | ||
|
||
models = new Models(page); | ||
plans = new Plans(page, models); | ||
constraints = new Constraints(page, models); | ||
schedulingConditions = new SchedulingConditions(page, models); | ||
schedulingGoals = new SchedulingGoals(page, models); | ||
plan = new Plan(page, plans, constraints, schedulingGoals, schedulingConditions); | ||
view = new View(page); | ||
|
||
await models.goto(); | ||
await models.createModel(); | ||
await plans.goto(); | ||
await plans.createPlan(); | ||
await plan.goto(); | ||
await plan.setRoleIfNeeded(); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await plans.goto(); | ||
await plans.deletePlan(); | ||
await models.goto(); | ||
await models.deleteModel(); | ||
await page.close(); | ||
await context.close(); | ||
}); | ||
|
||
test.describe.serial('View', () => { | ||
test(`Clicking on 'Browse Saved Views' in the view menu should pop up a SavedViewsModal`, async () => { | ||
await view.openViewMenu(); | ||
await view.openSavedViews(); | ||
await page.locator('.modal .st-button .bi-x').click(); | ||
}); | ||
|
||
test(`Clicking on 'Upload view file' in the view menu should pop up a UploadViewModal`, async () => { | ||
await view.openViewMenu(); | ||
await expect(view.navButtonViewUploadViewMenuButton).toBeVisible(); | ||
await view.navButtonViewUploadViewMenuButton.click(); | ||
await expect(page.locator('.modal .modal-header:has-text("Upload View JSON")')).toBeVisible(); | ||
await page.locator('.modal .st-button:has-text("Cancel")').click(); | ||
}); | ||
|
||
test(`Clicking on 'Rename View' in the view menu should pop up an EditViewModal`, async () => { | ||
await view.openViewMenu(); | ||
// Since no view is loaded the rename menu button should not be visible | ||
await expect(view.navButtonViewRenameViewMenuButton).not.toBeVisible(); | ||
const viewName = view.createViewName(); | ||
const viewName2 = view.createViewName(); | ||
await view.createView(viewName); | ||
await view.renameView(viewName2); | ||
await expect(view.navButtonViewMenuTitle).toHaveText(viewName); | ||
Check failure on line 72 in e2e-tests/tests/view.test.ts
|
||
await view.deleteView(viewName2); | ||
}); | ||
|
||
test(`Clicking on 'Save As' in the view menu should pop up a CreateViewModal`, async () => { | ||
await view.openSaveAs(); | ||
await expect(page.locator('.modal .modal-header:has-text("Save new view")')).toBeVisible(); | ||
await page.locator('.modal .st-button:has-text("Cancel")').click(); | ||
}); | ||
|
||
test(`Selecting an invalid view file should display an error and prevent the file from being uploaded`, async () => { | ||
await view.openViewMenu(); | ||
await expect(view.navButtonViewUploadViewMenuButton).toBeVisible(); | ||
await view.navButtonViewUploadViewMenuButton.click(); | ||
await view.fillViewInputName(); | ||
await view.fillViewInputFile(view.invalidViewFilePath); | ||
await expect(page.locator('.modal-content .error')).toBeVisible(); | ||
await expect(page.locator('.modal .st-button:has-text("Upload View")')).toBeDisabled(); | ||
await expect(page.locator('.modal')).toBeVisible(); | ||
// Expect validation error collapse to be visible | ||
await expect(page.locator('.modal-content .collapse')).toBeVisible(); | ||
await page.locator('.modal .st-button:has-text("Cancel")').click(); | ||
}); | ||
|
||
test(`Selecting an valid view file should not display an error and not prevent the file from being uploaded`, async () => { | ||
await view.openViewMenu(); | ||
await expect(view.navButtonViewUploadViewMenuButton).toBeVisible(); | ||
await view.navButtonViewUploadViewMenuButton.click(); | ||
await view.fillViewInputName(); | ||
await view.fillViewInputFile(); | ||
await expect(page.locator('.modal-content .error')).not.toBeVisible(); | ||
await page.locator('.modal .st-button:has-text("Upload View")').click(); | ||
await expect(page.locator('.modal')).not.toBeVisible(); | ||
}); | ||
}); |