@trackunit/iris-app-playwright 0.2.96 → 0.2.99-alpha-965e4725884.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,6 +2,31 @@ import { type CachedStorageState } from "./hydrateStorageState";
|
|
|
2
2
|
import { type AuthCredentials, type ResolveCredentialsOptions } from "./resolveCredentials";
|
|
3
3
|
export type { AuthCredentials };
|
|
4
4
|
export type LoginOptions = ResolveCredentialsOptions;
|
|
5
|
+
/** Matches HostLayout's `hideMenuForUrls` — routes where MainMenu is not rendered. */
|
|
6
|
+
export declare const HIDE_MENU_URL_FRAGMENTS: readonly ["/marketplace", "/auth/", "/terms"];
|
|
7
|
+
export declare const MAIN_MENU_READY_TIMEOUT_MS = 180000;
|
|
8
|
+
export declare const MAIN_MENU_READY_SELECTOR = "[data-testid=\"mainMenu\"]:not(:has([data-testid=\"mainMenuItems-skeleton\"], [data-testid=\"menu-items-skeleton\"]))";
|
|
9
|
+
type MainMenuReadinessInput = {
|
|
10
|
+
readonly selector: string;
|
|
11
|
+
readonly fragments: ReadonlyArray<string>;
|
|
12
|
+
};
|
|
13
|
+
type MainMenuWaitPage = {
|
|
14
|
+
waitForFunction: (pageFunction: (input: MainMenuReadinessInput) => boolean, input: MainMenuReadinessInput, options?: {
|
|
15
|
+
timeout?: number;
|
|
16
|
+
}) => Promise<unknown>;
|
|
17
|
+
};
|
|
18
|
+
type TestTimeoutInfo = {
|
|
19
|
+
timeout: number;
|
|
20
|
+
setTimeout: (timeout: number) => void;
|
|
21
|
+
};
|
|
22
|
+
/** Returns whether the main menu is ready or intentionally hidden for the current route. */
|
|
23
|
+
export declare const isMainMenuReady: ({ selector, fragments }: MainMenuReadinessInput) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Waits until Manager's main menu is rendered without a loading skeleton, or
|
|
26
|
+
* until the browser is on a HostLayout hide-menu route (marketplace / auth /
|
|
27
|
+
* terms) where the menu is intentionally absent.
|
|
28
|
+
*/
|
|
29
|
+
export declare const waitForMainMenuReady: (page: MainMenuWaitPage, testInfo?: TestTimeoutInfo) => Promise<void>;
|
|
5
30
|
export interface TrackunitBaseFixtures {
|
|
6
31
|
login: (options?: LoginOptions) => Promise<void>;
|
|
7
32
|
}
|
|
@@ -1,10 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expect = exports.test = void 0;
|
|
3
|
+
exports.expect = exports.test = exports.waitForMainMenuReady = exports.isMainMenuReady = exports.MAIN_MENU_READY_SELECTOR = exports.MAIN_MENU_READY_TIMEOUT_MS = exports.HIDE_MENU_URL_FRAGMENTS = void 0;
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
5
|
const hydrateStorageState_1 = require("./hydrateStorageState");
|
|
6
6
|
const loginCacheKey_1 = require("./loginCacheKey");
|
|
7
7
|
const resolveCredentials_1 = require("./resolveCredentials");
|
|
8
|
+
/** Matches HostLayout's `hideMenuForUrls` — routes where MainMenu is not rendered. */
|
|
9
|
+
exports.HIDE_MENU_URL_FRAGMENTS = ["/marketplace", "/auth/", "/terms"];
|
|
10
|
+
exports.MAIN_MENU_READY_TIMEOUT_MS = 180000;
|
|
11
|
+
exports.MAIN_MENU_READY_SELECTOR = '[data-testid="mainMenu"]:not(:has([data-testid="mainMenuItems-skeleton"], [data-testid="menu-items-skeleton"]))';
|
|
12
|
+
/** Returns whether the main menu is ready or intentionally hidden for the current route. */
|
|
13
|
+
const isMainMenuReady = ({ selector, fragments }) => {
|
|
14
|
+
if (document.querySelector(selector) !== null) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return fragments.some(fragment => window.location.pathname.includes(fragment));
|
|
18
|
+
};
|
|
19
|
+
exports.isMainMenuReady = isMainMenuReady;
|
|
20
|
+
/**
|
|
21
|
+
* Waits until Manager's main menu is rendered without a loading skeleton, or
|
|
22
|
+
* until the browser is on a HostLayout hide-menu route (marketplace / auth /
|
|
23
|
+
* terms) where the menu is intentionally absent.
|
|
24
|
+
*/
|
|
25
|
+
const waitForMainMenuReady = async (page, testInfo) => {
|
|
26
|
+
if (testInfo !== undefined && testInfo.timeout !== 0) {
|
|
27
|
+
testInfo.setTimeout(testInfo.timeout + exports.MAIN_MENU_READY_TIMEOUT_MS);
|
|
28
|
+
}
|
|
29
|
+
await page.waitForFunction(exports.isMainMenuReady, { selector: exports.MAIN_MENU_READY_SELECTOR, fragments: exports.HIDE_MENU_URL_FRAGMENTS }, { timeout: exports.MAIN_MENU_READY_TIMEOUT_MS });
|
|
30
|
+
};
|
|
31
|
+
exports.waitForMainMenuReady = waitForMainMenuReady;
|
|
8
32
|
/**
|
|
9
33
|
* Each worker is its own Node process, so a `Map` is sufficient — no
|
|
10
34
|
* cross-worker sharing concerns, no disk I/O, no cleanup needed. The cache
|
|
@@ -18,21 +42,26 @@ exports.test = test_1.test.extend({
|
|
|
18
42
|
},
|
|
19
43
|
{ scope: "worker" },
|
|
20
44
|
],
|
|
21
|
-
login: async ({ page, baseURL, _loginCache }, provide) => {
|
|
45
|
+
login: async ({ page, baseURL, _loginCache }, provide, testInfo) => {
|
|
22
46
|
const loginFn = async (options) => {
|
|
23
47
|
const credentials = await (0, resolveCredentials_1.resolveCredentials)(options);
|
|
24
48
|
const cacheKey = (0, loginCacheKey_1.buildLoginCacheKey)(baseURL, credentials);
|
|
25
49
|
const cached = _loginCache.get(cacheKey);
|
|
26
50
|
if (cached !== undefined) {
|
|
51
|
+
let cachedSessionRestored = false;
|
|
27
52
|
try {
|
|
28
53
|
await (0, hydrateStorageState_1.hydrateStorageState)(page.context(), cached);
|
|
29
54
|
await page.goto("/");
|
|
30
55
|
await page.locator("#host-layout-content").waitFor({ state: "visible", timeout: 15000 });
|
|
31
|
-
|
|
56
|
+
cachedSessionRestored = true;
|
|
32
57
|
}
|
|
33
58
|
catch {
|
|
34
59
|
_loginCache.delete(cacheKey);
|
|
35
60
|
}
|
|
61
|
+
if (cachedSessionRestored) {
|
|
62
|
+
await (0, exports.waitForMainMenuReady)(page, testInfo);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
36
65
|
}
|
|
37
66
|
await performOktaLogin({ page, baseURL, credentials });
|
|
38
67
|
// Capture the fully-authenticated state for reuse by later tests in
|
|
@@ -46,6 +75,7 @@ exports.test = test_1.test.extend({
|
|
|
46
75
|
catch {
|
|
47
76
|
/* Snapshot capture is best-effort; failing here is non-fatal. */
|
|
48
77
|
}
|
|
78
|
+
await (0, exports.waitForMainMenuReady)(page, testInfo);
|
|
49
79
|
};
|
|
50
80
|
await provide(loginFn);
|
|
51
81
|
},
|