|
| 1 | +// Import Third-party Dependencies |
| 2 | +import { test, expect } from "@playwright/test"; |
| 3 | + |
| 4 | +test.describe("[search-command] presets", () => { |
| 5 | + let i18n; |
| 6 | + |
| 7 | + test.beforeEach(async({ page }) => { |
| 8 | + await page.goto("/"); |
| 9 | + await page.waitForSelector(`[data-menu="network--view"].active`); |
| 10 | + |
| 11 | + i18n = await page.evaluate(() => { |
| 12 | + const lang = document.getElementById("lang").dataset.lang; |
| 13 | + const activeLang = lang in window.i18n ? lang : "english"; |
| 14 | + |
| 15 | + return window.i18n[activeLang].search_command; |
| 16 | + }); |
| 17 | + |
| 18 | + await page.locator("body").click(); |
| 19 | + await page.keyboard.press("Control+k"); |
| 20 | + |
| 21 | + await expect(page.locator(".backdrop")).toBeVisible(); |
| 22 | + }); |
| 23 | + |
| 24 | + test("shows the Quick filters section on open", async({ page }) => { |
| 25 | + await expect(page.locator(".section-title").filter({ hasText: i18n.section_presets })).toBeVisible(); |
| 26 | + }); |
| 27 | + |
| 28 | + test("renders all five preset buttons", async({ page }) => { |
| 29 | + await expect(page.locator(".range-preset")).toHaveCount(5); |
| 30 | + }); |
| 31 | + |
| 32 | + test("clicking a preset adds a chip and hides the presets section", async({ page }) => { |
| 33 | + await page.locator(".range-preset").filter({ hasText: i18n.preset_has_vulnerabilities }).click(); |
| 34 | + |
| 35 | + await expect(page.locator("search-chip")).toBeVisible(); |
| 36 | + await expect(page.locator(".section-title").filter({ hasText: i18n.section_presets })).not.toBeVisible(); |
| 37 | + }); |
| 38 | + |
| 39 | + test("shows contextual empty message for has-vulnerabilities preset", async({ page }) => { |
| 40 | + await page.locator(".range-preset").filter({ hasText: i18n.preset_has_vulnerabilities }).click(); |
| 41 | + |
| 42 | + await expect(page.locator(".empty-state")).toHaveText(i18n.preset_empty_has_vulnerabilities); |
| 43 | + }); |
| 44 | + |
| 45 | + test("shows contextual empty message for deprecated preset", async({ page }) => { |
| 46 | + await page.locator(".range-preset").filter({ hasText: i18n.preset_deprecated }).click(); |
| 47 | + |
| 48 | + await expect(page.locator(".empty-state")).toHaveText(i18n.preset_empty_deprecated); |
| 49 | + }); |
| 50 | + |
| 51 | + test("shows generic empty message when a manual filter yields no results", async({ page }) => { |
| 52 | + await page.locator("#cmd-input").fill("flag:hasBannedFile"); |
| 53 | + await page.keyboard.press("Enter"); |
| 54 | + |
| 55 | + await expect(page.locator(".empty-state")).toHaveText(i18n.empty_after_filter); |
| 56 | + }); |
| 57 | + |
| 58 | + test("pressing Escape closes the palette", async({ page }) => { |
| 59 | + await page.keyboard.press("Escape"); |
| 60 | + |
| 61 | + await expect(page.locator(".backdrop")).not.toBeVisible(); |
| 62 | + }); |
| 63 | +}); |
0 commit comments