@sit-onyx/playwright-utils 1.0.0-beta.2 → 1.0.0-beta.3

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/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  <div align="center" style="text-align: center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-light.svg">
4
- <source media="(prefers-color-scheme: light)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg">
5
- <img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg" width="160px">
6
- </picture>
2
+ <img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo.svg" height="96px">
7
3
  </div>
8
4
 
9
5
  <br>
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("playwright/jsx-runtime"),x=require("@playwright/experimental-ct-vue"),l=e=>e.replace(/\W/g,"-"),L=e=>{const o=()=>{const t=[`"blank ${e.columns.map(m=>`column-${l(m)}`).join(" ")}"`];return e.rows.forEach(m=>{t.push(`"row-${l(m)} ${e.columns.map(s=>`${l(m)}-${l(s)}`).join(" ")}"`)}),t.join(`
2
- `)};return c.jsxs("div",{style:{width:"max-content",fontFamily:"Arial, sans-serif"},children:[c.jsxs("div",{style:{marginBottom:"2rem"},children:[c.jsxs("h1",{style:{fontSize:"1.25rem",lineHeight:"1.75rem",margin:"0"},children:["Screenshot test: ",e.name]}),c.jsxs("div",{children:["Browser: ",e.browserName]})]}),c.jsxs("div",{style:{display:"grid",gap:"2rem",gridTemplateRows:"auto",width:"max-content",alignItems:"center",justifyContent:"center",gridTemplateColumns:`auto repeat(${e.columns.length}, 1fr)`,gridTemplateAreas:o()},children:[c.jsx("div",{style:{gridArea:"blank"}}),e.children]})]})},z=({defaults:e})=>({executeMatrixScreenshotTest:async t=>{x.test(`${t.name}`,async({mount:m,page:s,browserName:P,context:b})=>{x.test.setTimeout(t.columns.length*t.rows.length*25e3);const M=async(n,r,i)=>{var u,S,w,v,g,T,y,A;await s.getByRole("document").focus(),await s.getByRole("document").hover({position:{x:0,y:0},force:!0}),await s.mouse.up();const a=await m(n);await((S=(u=e==null?void 0:e.hooks)==null?void 0:u.beforeEach)==null?void 0:S.call(u,a,s,r,i,t.context)),await((v=(w=t.hooks)==null?void 0:w.beforeEach)==null?void 0:v.call(w,a,s,r,i,t.context));const h=await a.screenshot({animations:"disabled"}),d=await a.boundingBox(),H=`${l(i)}-${l(r)}`;return await((T=(g=e==null?void 0:e.hooks)==null?void 0:g.afterEach)==null?void 0:T.call(g,a,s,r,i,t.context)),await((A=(y=t.hooks)==null?void 0:y.afterEach)==null?void 0:A.call(y,a,s,r,i,t.context)),{box:d,id:H,screenshot:h}},$=new Map;for(const n of t.rows)for(const r of t.columns){const i=t.component(r,n),a=t.removePadding??(e==null?void 0:e.removePadding),d=await M(c.jsx("div",{style:{display:"grid",width:"max-content",padding:a?void 0:"1rem"},children:i}),r,n);$.set(d.id,d)}const j="/_playwright-matrix-screenshot";await b.route(`${j}*`,(n,r)=>{var h;const a=new URL(r.url()).searchParams.get("id")??"";return n.fulfill({status:200,contentType:"image/png",body:(h=$.get(a))==null?void 0:h.screenshot})});const R=Array.from($.values()).map(({box:n,id:r})=>c.jsx("img",{width:n==null?void 0:n.width,height:n==null?void 0:n.height,style:{gridArea:r},src:`${j}?id=${r}`,alt:r})),f=t.rows.map(n=>E({name:n,type:"row"})),k=t.columns.map(n=>E({name:n,type:"column"})),B=L({columns:t.columns,rows:t.rows,name:t.name,browserName:P,children:[...R,...f,...k]}),C=await m(B);await x.expect(C).toHaveScreenshot(`${t.name}.png`),await s.unroute(`${j}*`)})}}),G=async e=>{await x.expect(e).toBeVisible(),await e.evaluate(o=>{o.style.height=`${o.scrollHeight}px`,o.style.width=`${o.scrollWidth}px`})},E=e=>c.jsx("div",{style:{textAlign:"center",gridArea:`${e.type}-${l(e.name)}`},children:e.name});exports.adjustSizeToAbsolutePosition=G;exports.useMatrixScreenshotTest=z;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("playwright/jsx-runtime"),h=require("@playwright/experimental-ct-vue"),d=t=>t.replace(/\W/g,"-"),E=t=>{const o=()=>{const e=[`"blank ${t.columns.map(r=>`column-${d(r)}`).join(" ")}"`];return t.rows.forEach(r=>{e.push(`"row-${d(r)} ${t.columns.map(n=>`${d(r)}-${d(n)}`).join(" ")}"`)}),e.join(`
2
+ `)};return i.jsxs("div",{style:{width:"max-content",fontFamily:"Arial, sans-serif"},children:[i.jsxs("div",{style:{marginBottom:"2rem"},children:[i.jsxs("h1",{style:{fontSize:"1.25rem",lineHeight:"1.75rem",margin:"0"},children:["Screenshot test: ",t.name]}),i.jsxs("div",{children:["Browser: ",t.browserName]})]}),i.jsxs("div",{style:{display:"grid",gap:"2rem",gridTemplateRows:"auto",width:"max-content",alignItems:"center",justifyContent:"center",gridTemplateColumns:`auto repeat(${t.columns.length}, 1fr)`,gridTemplateAreas:o()},children:[i.jsx("div",{style:{gridArea:"blank"}}),t.children]})]})},k=({defaults:t})=>({executeMatrixScreenshotTest:async e=>{h.test(`${e.name}`,async({mount:r,page:n,browserName:g,context:f})=>{h.test.setTimeout(e.columns.length*e.rows.length*25e3);const b=async(a,s,l)=>{await n.getByRole("document").focus(),await n.getByRole("document").hover({position:{x:0,y:0},force:!0}),await n.mouse.up();const c=await r(a);await t?.hooks?.beforeEach?.(c,n,s,l,e.context),await e.hooks?.beforeEach?.(c,n,s,l,e.context);const x=await c.screenshot({animations:"disabled"}),m=await c.boundingBox(),A=`${d(l)}-${d(s)}`;return await t?.hooks?.afterEach?.(c,n,s,l,e.context),await e.hooks?.afterEach?.(c,n,s,l,e.context),{box:m,id:A,screenshot:x}},u=new Map;for(const a of e.rows)for(const s of e.columns){const l=e.component(s,a),c=e.removePadding??t?.removePadding,m=await b(i.jsx("div",{style:{display:"grid",width:"max-content",padding:c?void 0:"1rem"},children:l}),s,a);u.set(m.id,m)}const w="/_playwright-matrix-screenshot";await f.route(`${w}*`,(a,s)=>{const c=new URL(s.url()).searchParams.get("id")??"";return a.fulfill({status:200,contentType:"image/png",body:u.get(c)?.screenshot})});const v=Array.from(u.values()).map(({box:a,id:s})=>i.jsx("img",{width:a?.width,height:a?.height,style:{gridArea:s},src:`${w}?id=${s}`,alt:s})),S=e.rows.map(a=>y({name:a,type:"row"})),$=e.columns.map(a=>y({name:a,type:"column"})),j=E({columns:e.columns,rows:e.rows,name:e.name,browserName:g,children:[...v,...S,...$]}),T=await r(j);await h.expect(T).toHaveScreenshot(`${e.name}.png`),await n.unroute(`${w}*`)})}}),P=async t=>{await h.expect(t).toBeVisible(),await t.evaluate(o=>{o.style.height=`${o.scrollHeight}px`,o.style.width=`${o.scrollWidth}px`})},y=t=>i.jsx("div",{style:{textAlign:"center",gridArea:`${t.type}-${d(t.name)}`},children:t.name}),M=async({component:t,page:o,state:e})=>{if(e==="hover"&&await t.hover(),e==="focus-visible"&&await o.keyboard.press("Tab"),e==="active"){const r=await t.boundingBox(),n={x:r.x+r.width/2,y:r.y+r.height/2};await o.mouse.move(n.x,n.y),await o.mouse.down()}};exports.adjustSizeToAbsolutePosition=P;exports.useFocusStateHooks=M;exports.useMatrixScreenshotTest=k;
package/dist/index.js CHANGED
@@ -1,29 +1,29 @@
1
- import { jsxs as l, jsx as $ } from "playwright/jsx-runtime";
2
- import { expect as P, test as j } from "@playwright/experimental-ct-vue";
3
- const m = (e) => e.replace(/\W/g, "-"), N = (e) => {
4
- const i = () => {
5
- const t = [
6
- `"blank ${e.columns.map((o) => `column-${m(o)}`).join(" ")}"`
1
+ import { jsxs as m, jsx as d } from "playwright/jsx-runtime";
2
+ import { expect as f, test as g } from "@playwright/experimental-ct-vue";
3
+ const l = (t) => t.replace(/\W/g, "-"), B = (t) => {
4
+ const o = () => {
5
+ const e = [
6
+ `"blank ${t.columns.map((s) => `column-${l(s)}`).join(" ")}"`
7
7
  ];
8
- return e.rows.forEach((o) => {
9
- t.push(
10
- `"row-${m(o)} ${e.columns.map((a) => `${m(o)}-${m(a)}`).join(" ")}"`
8
+ return t.rows.forEach((s) => {
9
+ e.push(
10
+ `"row-${l(s)} ${t.columns.map((n) => `${l(s)}-${l(n)}`).join(" ")}"`
11
11
  );
12
- }), t.join(`
12
+ }), e.join(`
13
13
  `);
14
14
  };
15
- return /* @__PURE__ */ l("div", { style: { width: "max-content", fontFamily: "Arial, sans-serif" }, children: [
16
- /* @__PURE__ */ l("div", { style: { marginBottom: "2rem" }, children: [
17
- /* @__PURE__ */ l("h1", { style: { fontSize: "1.25rem", lineHeight: "1.75rem", margin: "0" }, children: [
15
+ return /* @__PURE__ */ m("div", { style: { width: "max-content", fontFamily: "Arial, sans-serif" }, children: [
16
+ /* @__PURE__ */ m("div", { style: { marginBottom: "2rem" }, children: [
17
+ /* @__PURE__ */ m("h1", { style: { fontSize: "1.25rem", lineHeight: "1.75rem", margin: "0" }, children: [
18
18
  "Screenshot test: ",
19
- e.name
19
+ t.name
20
20
  ] }),
21
- /* @__PURE__ */ l("div", { children: [
21
+ /* @__PURE__ */ m("div", { children: [
22
22
  "Browser: ",
23
- e.browserName
23
+ t.browserName
24
24
  ] })
25
25
  ] }),
26
- /* @__PURE__ */ l(
26
+ /* @__PURE__ */ m(
27
27
  "div",
28
28
  {
29
29
  style: {
@@ -33,36 +33,35 @@ const m = (e) => e.replace(/\W/g, "-"), N = (e) => {
33
33
  width: "max-content",
34
34
  alignItems: "center",
35
35
  justifyContent: "center",
36
- gridTemplateColumns: `auto repeat(${e.columns.length}, 1fr)`,
37
- gridTemplateAreas: i()
36
+ gridTemplateColumns: `auto repeat(${t.columns.length}, 1fr)`,
37
+ gridTemplateAreas: o()
38
38
  },
39
39
  children: [
40
- /* @__PURE__ */ $("div", { style: { gridArea: "blank" } }),
41
- e.children
40
+ /* @__PURE__ */ d("div", { style: { gridArea: "blank" } }),
41
+ t.children
42
42
  ]
43
43
  }
44
44
  )
45
45
  ] });
46
- }, U = ({
47
- defaults: e
46
+ }, H = ({
47
+ defaults: t
48
48
  }) => ({
49
49
  /**
50
50
  * Creates a single matrix screenshot that includes the screenshots for every column-row combination.
51
51
  */
52
- executeMatrixScreenshotTest: async (t) => {
53
- j(`${t.name}`, async ({ mount: o, page: a, browserName: k, context: B }) => {
54
- j.setTimeout(t.columns.length * t.rows.length * 25e3);
55
- const M = async (n, r, s) => {
56
- var w, S, g, T, u, E, y, A;
57
- await a.getByRole("document").focus(), await a.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await a.mouse.up();
58
- const c = await o(n);
59
- await ((S = (w = e == null ? void 0 : e.hooks) == null ? void 0 : w.beforeEach) == null ? void 0 : S.call(w, c, a, r, s, t.context)), await ((T = (g = t.hooks) == null ? void 0 : g.beforeEach) == null ? void 0 : T.call(g, c, a, r, s, t.context));
60
- const h = await c.screenshot({ animations: "disabled" }), d = await c.boundingBox(), G = `${m(s)}-${m(r)}`;
61
- return await ((E = (u = e == null ? void 0 : e.hooks) == null ? void 0 : u.afterEach) == null ? void 0 : E.call(u, c, a, r, s, t.context)), await ((A = (y = t.hooks) == null ? void 0 : y.afterEach) == null ? void 0 : A.call(y, c, a, r, s, t.context)), { box: d, id: G, screenshot: h };
62
- }, x = /* @__PURE__ */ new Map();
63
- for (const n of t.rows)
64
- for (const r of t.columns) {
65
- const s = t.component(r, n), c = t.removePadding ?? (e == null ? void 0 : e.removePadding), d = await M(/* @__PURE__ */ $(
52
+ executeMatrixScreenshotTest: async (e) => {
53
+ g(`${e.name}`, async ({ mount: s, page: n, browserName: v, context: $ }) => {
54
+ g.setTimeout(e.columns.length * e.rows.length * 25e3);
55
+ const b = async (r, a, i) => {
56
+ await n.getByRole("document").focus(), await n.getByRole("document").hover({ position: { x: 0, y: 0 }, force: !0 }), await n.mouse.up();
57
+ const c = await s(r);
58
+ await t?.hooks?.beforeEach?.(c, n, a, i, e.context), await e.hooks?.beforeEach?.(c, n, a, i, e.context);
59
+ const y = await c.screenshot({ animations: "disabled" }), h = await c.boundingBox(), k = `${l(i)}-${l(a)}`;
60
+ return await t?.hooks?.afterEach?.(c, n, a, i, e.context), await e.hooks?.afterEach?.(c, n, a, i, e.context), { box: h, id: k, screenshot: y };
61
+ }, u = /* @__PURE__ */ new Map();
62
+ for (const r of e.rows)
63
+ for (const a of e.columns) {
64
+ const i = e.component(a, r), c = e.removePadding ?? t?.removePadding, h = await b(/* @__PURE__ */ d(
66
65
  "div",
67
66
  {
68
67
  style: {
@@ -70,54 +69,59 @@ const m = (e) => e.replace(/\W/g, "-"), N = (e) => {
70
69
  width: "max-content",
71
70
  padding: c ? void 0 : "1rem"
72
71
  },
73
- children: s
72
+ children: i
74
73
  }
75
- ), r, n);
76
- x.set(d.id, d);
74
+ ), a, r);
75
+ u.set(h.id, h);
77
76
  }
78
- const v = "/_playwright-matrix-screenshot";
79
- await B.route(`${v}*`, (n, r) => {
80
- var h;
81
- const c = new URL(r.url()).searchParams.get("id") ?? "";
82
- return n.fulfill({
77
+ const w = "/_playwright-matrix-screenshot";
78
+ await $.route(`${w}*`, (r, a) => {
79
+ const c = new URL(a.url()).searchParams.get("id") ?? "";
80
+ return r.fulfill({
83
81
  status: 200,
84
82
  contentType: "image/png",
85
- body: (h = x.get(c)) == null ? void 0 : h.screenshot
83
+ body: u.get(c)?.screenshot
86
84
  });
87
85
  });
88
- const R = Array.from(x.values()).map(({ box: n, id: r }) => /* @__PURE__ */ $(
86
+ const S = Array.from(u.values()).map(({ box: r, id: a }) => /* @__PURE__ */ d(
89
87
  "img",
90
88
  {
91
- width: n == null ? void 0 : n.width,
92
- height: n == null ? void 0 : n.height,
93
- style: { gridArea: r },
94
- src: `${v}?id=${r}`,
95
- alt: r
89
+ width: r?.width,
90
+ height: r?.height,
91
+ style: { gridArea: a },
92
+ src: `${w}?id=${a}`,
93
+ alt: a
96
94
  }
97
- )), b = t.rows.map((n) => f({ name: n, type: "row" })), H = t.columns.map(
98
- (n) => f({ name: n, type: "column" })
99
- ), L = N({
100
- columns: t.columns,
101
- rows: t.rows,
102
- name: t.name,
103
- browserName: k,
104
- children: [...R, ...b, ...H]
105
- }), C = await o(L);
106
- await P(C).toHaveScreenshot(`${t.name}.png`), await a.unroute(`${v}*`);
95
+ )), T = e.rows.map((r) => x({ name: r, type: "row" })), E = e.columns.map(
96
+ (r) => x({ name: r, type: "column" })
97
+ ), A = B({
98
+ columns: e.columns,
99
+ rows: e.rows,
100
+ name: e.name,
101
+ browserName: v,
102
+ children: [...S, ...T, ...E]
103
+ }), j = await s(A);
104
+ await f(j).toHaveScreenshot(`${e.name}.png`), await n.unroute(`${w}*`);
107
105
  });
108
106
  }
109
- }), W = async (e) => {
110
- await P(e).toBeVisible(), await e.evaluate((i) => {
111
- i.style.height = `${i.scrollHeight}px`, i.style.width = `${i.scrollWidth}px`;
107
+ }), L = async (t) => {
108
+ await f(t).toBeVisible(), await t.evaluate((o) => {
109
+ o.style.height = `${o.scrollHeight}px`, o.style.width = `${o.scrollWidth}px`;
112
110
  });
113
- }, f = (e) => /* @__PURE__ */ $(
111
+ }, x = (t) => /* @__PURE__ */ d(
114
112
  "div",
115
113
  {
116
- style: { textAlign: "center", gridArea: `${e.type}-${m(e.name)}` },
117
- children: e.name
114
+ style: { textAlign: "center", gridArea: `${t.type}-${l(t.name)}` },
115
+ children: t.name
118
116
  }
119
- );
117
+ ), C = async ({ component: t, page: o, state: e }) => {
118
+ if (e === "hover" && await t.hover(), e === "focus-visible" && await o.keyboard.press("Tab"), e === "active") {
119
+ const s = await t.boundingBox(), n = { x: s.x + s.width / 2, y: s.y + s.height / 2 };
120
+ await o.mouse.move(n.x, n.y), await o.mouse.down();
121
+ }
122
+ };
120
123
  export {
121
- W as adjustSizeToAbsolutePosition,
122
- U as useMatrixScreenshotTest
124
+ L as adjustSizeToAbsolutePosition,
125
+ C as useFocusStateHooks,
126
+ H as useMatrixScreenshotTest
123
127
  };
@@ -1,4 +1,4 @@
1
- import type { Locator } from "@playwright/test";
1
+ import type { Locator, Page } from "@playwright/test";
2
2
  import type { HookContext, MatrixScreenshotTestOptions, UseMatrixScreenshotTestOptions } from "./types";
3
3
  /**
4
4
  * Creates a screenshot utility that can be used to capture matrix screenshots.
@@ -17,3 +17,26 @@ export declare const useMatrixScreenshotTest: <TContext extends HookContext = Ho
17
17
  * Will wait for the component to be visible.
18
18
  */
19
19
  export declare const adjustSizeToAbsolutePosition: (component: Locator) => Promise<void>;
20
+ export type UseFocusStateHooksOptions = {
21
+ /**
22
+ * Component to apply the focus to.
23
+ */
24
+ component: Locator;
25
+ /**
26
+ * Current Playwright test page.
27
+ */
28
+ page: Page;
29
+ /**
30
+ * States to apply the focus to. One of: "hover", "active", "focus-visible".
31
+ */
32
+ state: string;
33
+ };
34
+ /**
35
+ * Utility hook for screenshot tests to capture the component in hover, active and focus-visible state.
36
+ *
37
+ * States:
38
+ * - hover: will hover the center of the component
39
+ * - active: will hold the mouse down on the center of the component
40
+ * - focus-visible: press Tab key to focus component
41
+ */
42
+ export declare const useFocusStateHooks: ({ component, page, state }: UseFocusStateHooksOptions) => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sit-onyx/playwright-utils",
3
3
  "description": "Utilities for Vue component testing with Playwright",
4
- "version": "1.0.0-beta.2",
4
+ "version": "1.0.0-beta.3",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -30,9 +30,9 @@
30
30
  "vue": ">= 3"
31
31
  },
32
32
  "devDependencies": {
33
- "typescript": "5.6.3",
34
- "vite": "5.4.11",
35
- "@sit-onyx/shared": "0.0.1-beta.0"
33
+ "typescript": "5.8.3",
34
+ "vite": "7.0.0",
35
+ "@sit-onyx/shared": "1.0.0-beta.3"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "vite build && vue-tsc --emitDeclarationOnly"