-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create mod definitions fixture for e2e tests (#8604)
* Renaming fixture files for clarity * fix renaming * Create mod definitions fixture for e2e tests * fix merging fixtures * add extra note * lint error fixes * PR feedback
- Loading branch information
1 parent
5256aa0
commit d095691
Showing
17 changed files
with
326 additions
and
35 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,52 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { test as pageContextFixture } from "./pageContext"; | ||
import { WorkshopPage } from "../pageObjects/extensionConsole/workshop/workshopPage"; | ||
|
||
export const test = pageContextFixture.extend<{ | ||
// These should correspond 1-1 with the mod definition file names in the fixtures/modDefinitions directory | ||
modDefinitionNames: string[]; | ||
createdModIds: string[]; | ||
}>({ | ||
modDefinitionNames: [], | ||
createdModIds: [ | ||
async ({ modDefinitionNames, page, extensionId }, use) => { | ||
const createdIds: string[] = []; | ||
if (modDefinitionNames.length > 0) { | ||
const workshopPage = new WorkshopPage(page, extensionId); | ||
for (const definition of modDefinitionNames) { | ||
await workshopPage.goto(); | ||
const createdModId = | ||
await workshopPage.createNewModFromDefinition(definition); | ||
createdIds.push(createdModId); | ||
} | ||
} | ||
|
||
await use(createdIds); | ||
|
||
if (createdIds.length > 0) { | ||
const workshopPage = new WorkshopPage(page, extensionId); | ||
for (const id of createdIds) { | ||
await workshopPage.goto(); | ||
await workshopPage.deletePackagedModByModId(id); | ||
} | ||
} | ||
}, | ||
{ auto: true }, | ||
], | ||
}); |
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,27 @@ | ||
This directory contains yaml definition files for mods used in end to end tests. They are | ||
used alongside the `modDefinitions` fixture to automatically create the specified mods | ||
and handle their cleanup for each test. | ||
|
||
Definition file names must be lowercase in dash-case. The definition yaml must contain a placeholder value | ||
for the mod id, which will be replaced with the actual mod id when the mod is created. The placeholder | ||
value is `"{{ modId }}"`. | ||
|
||
Test Usage: | ||
|
||
``` | ||
// Specify what mods to create and use in the test. In this case, a file named `mod-example-1.yaml` should be | ||
// in the `modDefinitions` directory. | ||
test.use({ | ||
modDefinitions: ['mod-example-1'], | ||
}); | ||
test('test name', async ({ | ||
page, | ||
extensionId, | ||
createdModIds, | ||
}) => { | ||
// Get the created mod Id from the `createdModIds` fixture | ||
const modExample1Id = createdModIds[0]; | ||
// Activate the mod, etc. | ||
}); | ||
``` |
73 changes: 73 additions & 0 deletions
73
end-to-end-tests/fixtures/modDefinitions/simple-sidebar-panel.yaml
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,73 @@ | ||
kind: recipe | ||
options: | ||
schema: | ||
type: object | ||
properties: {} | ||
uiSchema: | ||
ui:order: | ||
- "*" | ||
metadata: | ||
id: "{{ modId }}" | ||
name: Simple Sidebar Panel | ||
version: 1.0.0 | ||
description: Created with the PixieBrix Page Editor | ||
apiVersion: v3 | ||
definitions: | ||
extensionPoint: | ||
kind: extensionPoint | ||
definition: | ||
type: actionPanel | ||
reader: | ||
- "@pixiebrix/document-metadata" | ||
- "@pixiebrix/document-context" | ||
isAvailable: | ||
matchPatterns: | ||
- https://pbx.vercel.app/* | ||
urlPatterns: [] | ||
selectors: [] | ||
trigger: load | ||
debounce: | ||
waitMillis: 250 | ||
leading: false | ||
trailing: true | ||
customEvent: null | ||
extensionPoints: | ||
- label: Simple Sidebar Panel | ||
config: | ||
heading: Simple Sidebar Panel | ||
body: | ||
- id: "@pixiebrix/document" | ||
rootMode: document | ||
config: | ||
body: | ||
- type: container | ||
config: {} | ||
children: | ||
- type: row | ||
config: {} | ||
children: | ||
- type: column | ||
config: {} | ||
children: | ||
- type: header | ||
config: | ||
title: !nunjucks Simple Sidebar Panel | ||
heading: h1 | ||
- type: row | ||
config: {} | ||
children: | ||
- type: column | ||
config: {} | ||
children: | ||
- type: text | ||
config: | ||
text: !nunjucks >- | ||
Simple sidebar panel for testing sidepanel | ||
open/close behavior | ||
enableMarkdown: true | ||
root: null | ||
permissions: | ||
origins: [] | ||
permissions: [] | ||
id: extensionPoint | ||
services: {} |
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
31 changes: 31 additions & 0 deletions
31
end-to-end-tests/pageObjects/extensionConsole/workshop/createWorkshopModPage.ts
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,31 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { type Locator, type Page } from "@playwright/test"; | ||
import { WorkshopModEditor } from "./modEditor"; | ||
|
||
export class CreateWorkshopModPage { | ||
readonly editor: WorkshopModEditor; | ||
readonly createBrickButton: Locator; | ||
|
||
constructor(private readonly page: Page) { | ||
this.editor = new WorkshopModEditor(this.page); | ||
this.createBrickButton = this.page.getByRole("button", { | ||
name: "Create Brick", | ||
}); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
end-to-end-tests/pageObjects/extensionConsole/workshop/modEditor.ts
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,61 @@ | ||
/* | ||
* Copyright (C) 2024 PixieBrix, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { type Locator, type Page } from "@playwright/test"; | ||
import fs from "node:fs/promises"; | ||
import path from "node:path"; | ||
import { uuidv4 } from "@/types/helpers"; | ||
|
||
export class WorkshopModEditor { | ||
readonly textArea: Locator; | ||
readonly baseLocator: Locator; | ||
|
||
constructor(private readonly page: Page) { | ||
this.baseLocator = this.page.getByLabel("Editor"); | ||
this.textArea = this.baseLocator.getByRole("textbox"); | ||
} | ||
|
||
async findText(text: string) { | ||
await this.baseLocator.locator(".ace_content").click(); // Focus on the visible editor | ||
await this.page.keyboard.press("ControlOrMeta+f"); | ||
await this.page.getByPlaceholder("Search for").fill(text); | ||
} | ||
|
||
async findAndReplaceText(findText: string, replaceText: string) { | ||
await this.findText(findText); | ||
await this.page.getByText("+", { exact: true }).click(); | ||
await this.page.getByPlaceholder("Replace with").fill(replaceText); | ||
await this.page.getByText("Replace").click(); | ||
} | ||
|
||
// Loads the corresponding yaml from the fixtures/modDefinitions directory | ||
async replaceWithModDefinition(modDefinitionName: string) { | ||
const modDefinition = await fs.readFile( | ||
path.join( | ||
__dirname, | ||
`../../../fixtures/modDefinitions/${modDefinitionName}.yaml`, | ||
), | ||
"utf8", | ||
); | ||
const uuid = uuidv4(); | ||
const modId = `@extension-e2e-test-unaffiliated/${modDefinitionName}-${uuid}`; | ||
const replacedDefinition = modDefinition.replace("{{ modId }}", modId); | ||
|
||
await this.textArea.fill(replacedDefinition); | ||
return modId; | ||
} | ||
} |
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
Oops, something went wrong.