mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2025-12-06 12:20:20 +01:00
Terminal tests
This commit is contained in:
parent
e134468f82
commit
ada66aeabf
22
e2e/components/apps/Terminal.spec.ts
Normal file
22
e2e/components/apps/Terminal.spec.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { test } from "@playwright/test";
|
||||
import { TERMINAL_BASE_CD } from "e2e/constants";
|
||||
import {
|
||||
captureConsoleLogs,
|
||||
disableWallpaper,
|
||||
terminalDirectoryMatchesPublicFolder,
|
||||
terminalHasRows,
|
||||
terminalHasText,
|
||||
windowsAreVisible,
|
||||
} from "e2e/functions";
|
||||
|
||||
test.beforeEach(captureConsoleLogs);
|
||||
test.beforeEach(disableWallpaper);
|
||||
test.beforeEach(async ({ page }) => page.goto("/?app=Terminal"));
|
||||
test.beforeEach(windowsAreVisible);
|
||||
test.beforeEach(terminalHasRows);
|
||||
|
||||
test("has current directory", async ({ page }) =>
|
||||
terminalHasText({ page }, `${TERMINAL_BASE_CD}>`));
|
||||
|
||||
test("has directory listing", async ({ page }) =>
|
||||
terminalDirectoryMatchesPublicFolder({ page }, TERMINAL_BASE_CD));
|
||||
|
|
@ -98,6 +98,8 @@ export const FILE_EXPLORER_SELECTION_SELECTOR = `${FILE_EXPLORER_SELECTOR}>span`
|
|||
export const FILE_EXPLORER_ENTRIES_SELECTOR = `${FILE_EXPLORER_SELECTOR}>li`;
|
||||
export const FILE_EXPLORER_ENTRIES_FOCUSED_SELECTOR = `${FILE_EXPLORER_SELECTOR}>li${FOCUSED_ENTRY_SELECTOR}`;
|
||||
export const FILE_EXPLORER_ENTRIES_RENAMING_SELECTOR = `${FILE_EXPLORER_ENTRIES_SELECTOR}>button>figure>textarea`;
|
||||
export const TERMINAL_SELECTOR = `${WINDOW_SELECTOR}>${VIEWPORT_SELECTOR}>${APP_CONTAINER_SELECTOR}>.terminal`;
|
||||
export const TERMINAL_ROWS_SELECTOR = `${TERMINAL_SELECTOR}>.xterm-screen>.xterm-rows>div`;
|
||||
export const SHEEP_SELECTOR = `${DESKTOP_SELECTOR}>div>img[src^=data]`;
|
||||
|
||||
export const CALENDAR_LABEL = /^Calendar$/;
|
||||
|
|
@ -244,3 +246,7 @@ export const UNKNOWN_ICON_PATH = "/System/Icons/48x48/unknown.png";
|
|||
const OG_REQUIRED_TAGS = ["title", "image", "url", "type"];
|
||||
|
||||
export const OG_TAGS = [...OG_REQUIRED_TAGS, "description"];
|
||||
|
||||
export const TERMINAL_BASE_CD = "/Users/Public";
|
||||
|
||||
export const ROOT_PUBLIC_FOLDER = "public";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { readdirSync, statSync } from "fs";
|
||||
import { join } from "path";
|
||||
import {
|
||||
type Locator,
|
||||
type Page,
|
||||
|
|
@ -48,6 +50,9 @@ import {
|
|||
SEARCH_MENU_INPUT_SELECTOR,
|
||||
SEARCH_MENU_RESULTS_SELECTOR,
|
||||
FILE_EXPLORER_SEARCH_BOX_SELECTOR,
|
||||
TERMINAL_ROWS_SELECTOR,
|
||||
TERMINAL_SELECTOR,
|
||||
ROOT_PUBLIC_FOLDER,
|
||||
} from "e2e/constants";
|
||||
|
||||
type TestProps = {
|
||||
|
|
@ -783,10 +788,52 @@ export const fileExplorerEntriesAreVisible = async ({
|
|||
}: TestProps): Promise<void> =>
|
||||
entriesAreVisible(FILE_EXPLORER_ENTRIES_SELECTOR, page);
|
||||
|
||||
export const sendToTerminal = async (
|
||||
{ page }: TestProps,
|
||||
text: string
|
||||
): Promise<void> => {
|
||||
const terminal = page.locator(TERMINAL_SELECTOR);
|
||||
|
||||
await terminal.pressSequentially(text);
|
||||
await terminal.press("Enter");
|
||||
};
|
||||
|
||||
export const taskbarEntriesAreVisible = async ({
|
||||
page,
|
||||
}: TestProps): Promise<void> => entriesAreVisible(TASKBAR_ENTRY_SELECTOR, page);
|
||||
|
||||
export const terminalHasText = async (
|
||||
{ page }: TestProps,
|
||||
text: string
|
||||
): Promise<void> =>
|
||||
expect(page.locator(TERMINAL_ROWS_SELECTOR).getByText(text)).toBeVisible();
|
||||
|
||||
export const terminalDirectoryMatchesPublicFolder = async (
|
||||
{ page }: TestProps,
|
||||
directory: string
|
||||
): Promise<void> => {
|
||||
await sendToTerminal({ page }, `dir ${directory}`);
|
||||
|
||||
const publicDirectory = join(ROOT_PUBLIC_FOLDER, directory);
|
||||
const dirContents = readdirSync(publicDirectory);
|
||||
const fileCount = dirContents.filter((entry) =>
|
||||
statSync(join(publicDirectory, entry)).isFile()
|
||||
).length;
|
||||
const dirCount = dirContents.length - fileCount;
|
||||
|
||||
await expect(async () => {
|
||||
await terminalHasText({ page }, `${fileCount} File(s)`);
|
||||
await terminalHasText({ page }, `${dirCount} Dir(s)`);
|
||||
}).toPass();
|
||||
};
|
||||
|
||||
export const terminalHasRows = async ({ page }: TestProps): Promise<void> =>
|
||||
expect(async () =>
|
||||
expect(await page.locator(TERMINAL_ROWS_SELECTOR).count()).toBeGreaterThan(
|
||||
0
|
||||
)
|
||||
).toPass();
|
||||
|
||||
export const windowsAreVisible = async ({ page }: TestProps): Promise<void> =>
|
||||
entriesAreVisible(WINDOW_SELECTOR, page);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user