This repository was archived by the owner on Sep 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 669
tests(ui): test security event form submission #6020
Merged
whitdog47
merged 2 commits into
main
from
tests/add-playwright-test-for-event-report-form
May 29, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| import { expect, Locator, Page } from "@playwright/test" | ||
| import { orgSlug, Routes } from "../routes" | ||
|
|
||
| export class ReportEventPage { | ||
| readonly page: Page | ||
| readonly route: string | ||
| readonly reportHeader: Locator | ||
| readonly descriptionTextBox: Locator | ||
| readonly urgentCheckbox: Locator | ||
| readonly submitButton: Locator | ||
| readonly pageBorder: Locator | ||
|
|
||
| constructor(page: Page) { | ||
| this.page = page | ||
| this.route = orgSlug + Routes.ReportEvent | ||
| this.reportHeader = page.getByText("Report a Security Event").first() | ||
| this.descriptionTextBox = page.getByLabel("Description", { exact: true }) | ||
| this.urgentCheckbox = page.getByLabel( | ||
| "URGENT: I need immediate help with this (the oncall will be paged)", | ||
| { exact: true } | ||
| ) | ||
| this.submitButton = page.getByRole("button", { name: "Submit" }) | ||
| this.pageBorder = this.page.locator("span").filter({ | ||
| hasText: "Security Events are an input", | ||
| }) | ||
| } | ||
|
|
||
| async goto() { | ||
| await Promise.all([ | ||
| this.page.goto(this.route), | ||
| await this.page.waitForURL(this.route), | ||
| await expect(this.reportHeader).toBeVisible(), | ||
|
whitdog47 marked this conversation as resolved.
|
||
| ]) | ||
| } | ||
|
|
||
| async reportEvent(description: string, urgent: boolean = false) { | ||
| await this.goto() | ||
| // give time for default project to settle | ||
| await this.page.waitForTimeout(3000) | ||
|
whitdog47 marked this conversation as resolved.
|
||
| await this.addDescription(description) | ||
| if (urgent) { | ||
| await this.urgentCheckbox.click() | ||
| } | ||
| await this.page.waitForTimeout(1500) | ||
|
whitdog47 marked this conversation as resolved.
|
||
| await this.resetPageView() | ||
| await Promise.all([ | ||
| await this.submitButton.click(), | ||
| await this.page.waitForLoadState("networkidle"), | ||
| ]) | ||
| } | ||
|
|
||
| async addDescription(description: string) { | ||
| await this.descriptionTextBox.click() | ||
| await this.descriptionTextBox.fill(description) | ||
| } | ||
|
|
||
| async resetPageView() { | ||
| // await this.pageBorder.click() | ||
| } | ||
|
|
||
| async pageObjectModel(description: string, urgent: boolean = false) { | ||
| await this.reportEvent(description, urgent) | ||
| } | ||
|
whitdog47 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or 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,90 @@ | ||
| import register from "./utils/register" | ||
| import { test, expect } from "./fixtures/dispatch-fixtures" | ||
|
|
||
| test.describe("Authenticated Dispatch App", () => { | ||
| test.beforeEach(async ({ authPage }) => { | ||
| await register(authPage) | ||
| }), | ||
| test("Should allow me to report an event", async ({ page, reportEventPage }) => { | ||
| /* The ability to report a case is one of the most critical | ||
| user stories in the Dispatch application. */ | ||
|
|
||
| const description = "Security Event Test Created by Playwright" | ||
| const title = "Security Event Triage" | ||
|
|
||
| await reportEventPage.reportEvent(description) | ||
| // Soft validate that we get redirected to the event submission form | ||
| const expectedURL = encodeURI( | ||
| `/default/events/report?project=default&title=${title}&description=${description}` | ||
| ) | ||
| // replace + with %20 | ||
| const pageURL = page.url().replace(/\+/g, "%20") | ||
|
|
||
| await expect.soft(pageURL).toContain(expectedURL) | ||
|
|
||
| // Soft validate that we receive the post-create resources form. | ||
| await expect | ||
| .soft( | ||
| page.getByText( | ||
| "This page will be populated with case resources as they are created (if available). If you have any questions, please feel free to review the Frequently Asked Questions (FAQ) document linked below, and/or reach out to the listed assignee." | ||
| ), | ||
| "'Case Resources' text visible on page after submission of a case." | ||
| ) | ||
| .toBeVisible() | ||
|
|
||
| // Soft validate that the ticket link is present | ||
| const loc = page.getByRole("link", { | ||
| name: "Ticket Ticket for tracking purposes. It contains information and links to resources.", | ||
|
whitdog47 marked this conversation as resolved.
|
||
| }) | ||
| await expect | ||
| .soft(await loc.first().getAttribute("href")) | ||
| .toContain("default/cases/dispatch-default-default-") | ||
| }), | ||
| test("Should allow me to report an event with urgent flagged", async ({ | ||
| page, | ||
| reportEventPage, | ||
| }) => { | ||
| /* The ability to report a case is one of the most critical | ||
| user stories in the Dispatch application. */ | ||
|
|
||
| const description = "Security Event Test Created by Playwright" | ||
| const title = "Security Event Triage" | ||
|
|
||
| await reportEventPage.reportEvent(description, true) | ||
| // Soft validate that we get redirected to the case submission form | ||
| const expectedURL = encodeURI( | ||
| `/default/events/report?project=default&title=${title}&description=${description}` | ||
| ) | ||
| // replace + with %20 | ||
| const pageURL = page.url().replace(/\+/g, "%20") | ||
|
|
||
| await expect.soft(pageURL).toContain(expectedURL) | ||
|
|
||
| // Soft validate that we receive the post-create resources form. | ||
| await expect | ||
| .soft( | ||
| page.getByText( | ||
| "This page will be populated with case resources as they are created (if available). If you have any questions, please feel free to review the Frequently Asked Questions (FAQ) document linked below, and/or reach out to the listed assignee." | ||
| ), | ||
| "'Case Resources' text visible on page after submission of an event." | ||
| ) | ||
| .toBeVisible() | ||
|
|
||
| // Validate that the Priority is set to 'Critical' | ||
| const priorityElement = page.getByText("Priority") | ||
|
|
||
| const subtitleElement = priorityElement.locator( | ||
| 'xpath=following-sibling::div[contains(@class, "v-list-item-subtitle")]' | ||
| ) | ||
| await expect(subtitleElement).toBeVisible() | ||
| await expect(subtitleElement).toHaveText(/Critical/) | ||
|
|
||
| // Soft validate that the ticket link is present | ||
| const loc = page.getByRole("link", { | ||
| name: "Ticket Ticket for tracking purposes. It contains information and links to resources.", | ||
| }) | ||
| await expect | ||
| .soft(await loc.first().getAttribute("href")) | ||
| .toContain("default/cases/dispatch-default-default-") | ||
| }) | ||
| }) | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.