@ember-joinery/test-support 1.0.1 → 1.1.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/dist/page.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<Page>` from `@ember-joinery/ember`: reads its title and description, and reaches
4
+ * its parts.
5
+ *
6
+ * const page = new PageHarness('contacts') // <Page @name="contacts">
7
+ * assert.strictEqual(page.title, 'Contacts')
8
+ * await page.find(ButtonHarness, 'add').click()
9
+ *
10
+ * A page wraps a screen's content, so the parts inside it still belong to the components around
11
+ * them; its own parts are found by their `data-jn-page-*` attributes. A page object can extend
12
+ * this class and declare the screen's components with `@child`.
13
+ */
14
+ export declare class PageHarness extends Harness {
15
+ #private;
16
+ static component: string;
17
+ /** Its `@variant`: `panel` or `settings`. */
18
+ get variant(): string | null;
19
+ /** Its title's text, or `''` without one. */
20
+ get title(): string;
21
+ /** Its description's text, or `''` without one. */
22
+ get description(): string;
23
+ /** Whether its header stays at the top while the body scrolls. */
24
+ get isHeaderSticky(): boolean;
25
+ /** The header. Throws when it has none. */
26
+ get header(): HTMLElement;
27
+ /** The nav, before the title. Throws when it has none. */
28
+ get nav(): HTMLElement;
29
+ /** The title's element. Throws when it has none. */
30
+ get titleElement(): HTMLElement;
31
+ /** The actions' container. Throws when it has none. */
32
+ get actions(): HTMLElement;
33
+ /** The row under the header's text. Throws when it has none. */
34
+ get headerFooter(): HTMLElement;
35
+ /** The body. Throws when it has none. */
36
+ get body(): HTMLElement;
37
+ }
38
+ //# sourceMappingURL=page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.d.ts","sourceRoot":"","sources":["../src/page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAMtC;;;;;;;;;;;GAWG;AACH,qBAAa,WAAY,SAAQ,OAAO;;IACtC,OAAgB,SAAS,SAAS;IAclC,6CAA6C;IAC7C,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,6CAA6C;IAC7C,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,mDAAmD;IACnD,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,kEAAkE;IAClE,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,2CAA2C;IAC3C,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,0DAA0D;IAC1D,IAAI,GAAG,IAAI,WAAW,CAErB;IAED,oDAAoD;IACpD,IAAI,YAAY,IAAI,WAAW,CAE9B;IAED,uDAAuD;IACvD,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,gEAAgE;IAChE,IAAI,YAAY,IAAI,WAAW,CAE9B;IAED,yCAAyC;IACzC,IAAI,IAAI,IAAI,WAAW,CAEtB;CACF"}
package/dist/page.js ADDED
@@ -0,0 +1,68 @@
1
+ import { Harness } from "./harness.js";
2
+ function text(element) {
3
+ return (element?.textContent ?? '').replace(/\s+/g, ' ').trim();
4
+ }
5
+ /**
6
+ * Drives a `<Page>` from `@ember-joinery/ember`: reads its title and description, and reaches
7
+ * its parts.
8
+ *
9
+ * const page = new PageHarness('contacts') // <Page @name="contacts">
10
+ * assert.strictEqual(page.title, 'Contacts')
11
+ * await page.find(ButtonHarness, 'add').click()
12
+ *
13
+ * A page wraps a screen's content, so the parts inside it still belong to the components around
14
+ * them; its own parts are found by their `data-jn-page-*` attributes. A page object can extend
15
+ * this class and declare the screen's components with `@child`.
16
+ */
17
+ export class PageHarness extends Harness {
18
+ static component = 'page';
19
+ #query(part) {
20
+ return this.element.querySelector(`:scope > [data-jn-page-${part}], :scope > [data-jn-page-header] > [data-jn-page-${part}]`);
21
+ }
22
+ #part(part) {
23
+ const element = this.#query(part);
24
+ if (!element)
25
+ throw new Error(`Joinery harness: no ${part} in ${this}`);
26
+ return element;
27
+ }
28
+ /** Its `@variant`: `panel` or `settings`. */
29
+ get variant() {
30
+ return this.element.getAttribute('data-variant');
31
+ }
32
+ /** Its title's text, or `''` without one. */
33
+ get title() {
34
+ return text(this.#query('title'));
35
+ }
36
+ /** Its description's text, or `''` without one. */
37
+ get description() {
38
+ return text(this.#query('description'));
39
+ }
40
+ /** Whether its header stays at the top while the body scrolls. */
41
+ get isHeaderSticky() {
42
+ return this.#query('header')?.hasAttribute('data-sticky') ?? false;
43
+ }
44
+ /** The header. Throws when it has none. */
45
+ get header() {
46
+ return this.#part('header');
47
+ }
48
+ /** The nav, before the title. Throws when it has none. */
49
+ get nav() {
50
+ return this.#part('nav');
51
+ }
52
+ /** The title's element. Throws when it has none. */
53
+ get titleElement() {
54
+ return this.#part('title');
55
+ }
56
+ /** The actions' container. Throws when it has none. */
57
+ get actions() {
58
+ return this.#part('actions');
59
+ }
60
+ /** The row under the header's text. Throws when it has none. */
61
+ get headerFooter() {
62
+ return this.#part('header-footer');
63
+ }
64
+ /** The body. Throws when it has none. */
65
+ get body() {
66
+ return this.#part('body');
67
+ }
68
+ }
@@ -0,0 +1,40 @@
1
+ import { Harness } from './harness.ts';
2
+ /** How a pull goes. */
3
+ export interface PullOptions {
4
+ /** `touch` (the default), `pen` or `mouse`. A mouse does not pull. */
5
+ pointerType?: 'touch' | 'pen' | 'mouse';
6
+ }
7
+ /**
8
+ * Drives a `<PullToRefresh>` from `@ember-joinery/ember`: reads its state and what it announces,
9
+ * and pulls it as a finger does.
10
+ *
11
+ * const feed = new PullToRefreshHarness('feed') // <PullToRefresh @name="feed">
12
+ * await feed.refresh()
13
+ * assert.true(feed.isRefreshing)
14
+ * assert.strictEqual(feed.announcement, 'Refreshing')
15
+ *
16
+ * It wraps the content, so the parts inside it still belong to the components around them; its
17
+ * own elements are found by their `data-jn-pull-to-refresh-*` attributes.
18
+ */
19
+ export declare class PullToRefreshHarness extends Harness {
20
+ #private;
21
+ static component: string;
22
+ /** Its state: `idle`, `pulling`, `armed` or `refreshing`. */
23
+ get state(): string | null;
24
+ /** Whether a refresh is in progress. */
25
+ get isRefreshing(): boolean;
26
+ /** What its live region says: `Refreshing`, then `Updated`, or `''`. */
27
+ get announcement(): string;
28
+ /** The indicator at the top. */
29
+ get indicator(): HTMLElement;
30
+ /** The live region. */
31
+ get status(): HTMLElement;
32
+ /**
33
+ * Pulls it down by `distance` pixels of finger movement, then releases. The indicator moves
34
+ * half as far, so a pull refreshes when `distance` is twice the threshold or more.
35
+ */
36
+ pull(distance: number, { pointerType }?: PullOptions): Promise<void>;
37
+ /** Pulls it far enough to refresh. */
38
+ refresh(): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=pull-to-refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-to-refresh.d.ts","sourceRoot":"","sources":["../src/pull-to-refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC,uBAAuB;AACvB,MAAM,WAAW,WAAW;IAC1B,sEAAsE;IACtE,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,OAAO,CAAA;CACxC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;;IAC/C,OAAgB,SAAS,SAAoB;IAU7C,6DAA6D;IAC7D,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,wCAAwC;IACxC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,wEAAwE;IACxE,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,gCAAgC;IAChC,IAAI,SAAS,IAAI,WAAW,CAE3B;IAED,uBAAuB;IACvB,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;OAGG;IACG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,WAAqB,EAAE,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAexF,sCAAsC;IAChC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
@@ -0,0 +1,65 @@
1
+ import { Harness } from "./harness.js";
2
+ import { sendPointer } from "./send-pointer.js";
3
+ /**
4
+ * Drives a `<PullToRefresh>` from `@ember-joinery/ember`: reads its state and what it announces,
5
+ * and pulls it as a finger does.
6
+ *
7
+ * const feed = new PullToRefreshHarness('feed') // <PullToRefresh @name="feed">
8
+ * await feed.refresh()
9
+ * assert.true(feed.isRefreshing)
10
+ * assert.strictEqual(feed.announcement, 'Refreshing')
11
+ *
12
+ * It wraps the content, so the parts inside it still belong to the components around them; its
13
+ * own elements are found by their `data-jn-pull-to-refresh-*` attributes.
14
+ */
15
+ export class PullToRefreshHarness extends Harness {
16
+ static component = 'pull-to-refresh';
17
+ #own(name) {
18
+ const element = this.element.querySelector(`:scope > [data-jn-pull-to-refresh-${name}]`);
19
+ if (!element)
20
+ throw new Error(`Joinery harness: no ${name} in ${this}`);
21
+ return element;
22
+ }
23
+ /** Its state: `idle`, `pulling`, `armed` or `refreshing`. */
24
+ get state() {
25
+ return this.element.getAttribute('data-state');
26
+ }
27
+ /** Whether a refresh is in progress. */
28
+ get isRefreshing() {
29
+ return this.state === 'refreshing';
30
+ }
31
+ /** What its live region says: `Refreshing`, then `Updated`, or `''`. */
32
+ get announcement() {
33
+ return (this.status.textContent ?? '').trim();
34
+ }
35
+ /** The indicator at the top. */
36
+ get indicator() {
37
+ return this.#own('indicator');
38
+ }
39
+ /** The live region. */
40
+ get status() {
41
+ return this.#own('status');
42
+ }
43
+ /**
44
+ * Pulls it down by `distance` pixels of finger movement, then releases. The indicator moves
45
+ * half as far, so a pull refreshes when `distance` is twice the threshold or more.
46
+ */
47
+ async pull(distance, { pointerType = 'touch' } = {}) {
48
+ const target = this.element;
49
+ const rect = target.getBoundingClientRect();
50
+ const clientX = rect.left + rect.width / 2;
51
+ const at = (moved) => ({
52
+ clientX,
53
+ clientY: rect.top + 1 + moved,
54
+ pointerType,
55
+ });
56
+ await sendPointer(target, 'pointerdown', at(0));
57
+ await sendPointer(target, 'pointermove', at(distance / 2));
58
+ await sendPointer(target, 'pointermove', at(distance));
59
+ await sendPointer(target, 'pointerup', { ...at(distance), buttons: 0 });
60
+ }
61
+ /** Pulls it far enough to refresh. */
62
+ async refresh() {
63
+ await this.pull(1000);
64
+ }
65
+ }
@@ -0,0 +1,77 @@
1
+ import { Harness } from './harness.ts';
2
+ import { type KeyModifiers } from './focus.ts';
3
+ /** A column of a split view. */
4
+ type Column = 'sidebar' | 'content' | 'detail';
5
+ /**
6
+ * Drives a `<SplitView>` from `@ember-joinery/ember`: reaches its columns and separators, reads
7
+ * which columns it shows, and uses its sidebar toggle and its back button.
8
+ *
9
+ * const view = new SplitViewHarness('mail') // <SplitView @name="mail">
10
+ * await view.toggleSidebar()
11
+ * assert.strictEqual(view.visibility, 'double-column')
12
+ * await view.pressSeparator(0, 'ArrowRight')
13
+ *
14
+ * The view wraps the app, so the parts inside it still belong to the components around them;
15
+ * its own elements are found by their `data-jn-split-view-*` attributes. A page object can
16
+ * extend this class and declare the app's components with `@child`.
17
+ */
18
+ export declare class SplitViewHarness extends Harness {
19
+ #private;
20
+ static component: string;
21
+ /** The columns it shows now, in order. A narrow view shows one. */
22
+ get columns(): HTMLElement[];
23
+ /** The names of the columns it shows now, in order. */
24
+ get columnNames(): string[];
25
+ /** Whether it shows the column now. */
26
+ has(column: Column): boolean;
27
+ /** A column that it shows now. Throws when it does not show the column. */
28
+ column(name: Column): HTMLElement;
29
+ /** The sidebar, the first column. Throws when it is not shown. */
30
+ get sidebar(): HTMLElement;
31
+ /** The content, the middle column. Throws when it is not shown. */
32
+ get content(): HTMLElement;
33
+ /** The detail, the last column. Throws when it is not shown. */
34
+ get detail(): HTMLElement;
35
+ /** A shown column's width in CSS pixels. */
36
+ widthOf(column: Column): number;
37
+ /** Which columns a wide view shows: `all`, `double-column` or `detail-only`. */
38
+ get visibility(): string | null;
39
+ /** Its `@mode`: `tile`, `overlay` or `displace`. */
40
+ get mode(): string | null;
41
+ /**
42
+ * How a wide view shows its sidebar now: `tiled`, `overlaid`, `displaced` or `hidden`. `null`
43
+ * in a narrow view.
44
+ */
45
+ get sidebarLayout(): string | null;
46
+ /** Whether it is narrower than its `@compactBreakpoint`, and shows one column at a time. */
47
+ get isCompact(): boolean;
48
+ /** The column a narrow view shows: `sidebar`, `content` or `detail`. */
49
+ get compactColumn(): string | null;
50
+ /** The separators between the columns it shows, in order. */
51
+ get separators(): HTMLElement[];
52
+ /** The backdrop behind an overlaid sidebar, or `null`. */
53
+ get backdrop(): HTMLElement | null;
54
+ /** The sidebar toggle, or `null` (a narrow view has none). */
55
+ get sidebarToggle(): HTMLElement | null;
56
+ /**
57
+ * The back button, or `null` (only a narrow view past its first column has one). A narrow
58
+ * view renders every column and hides all but one, so it is the button that shows: the one
59
+ * in the column on screen. A button in a hidden column is not one the user can press.
60
+ */
61
+ get backButton(): HTMLElement | null;
62
+ /** Clicks the sidebar toggle. Throws when the view has none. */
63
+ toggleSidebar(): Promise<void>;
64
+ /** Clicks the back button. Throws when the view has none. */
65
+ back(): Promise<void>;
66
+ /**
67
+ * Shows a column of a narrow view, as the app does when it calls `showColumn()`. It sends the
68
+ * `joinery:show-column` event, which the view listens for.
69
+ */
70
+ showColumn(column: Column): Promise<void>;
71
+ /** Clicks the backdrop of an overlaid sidebar, which closes the sidebar. */
72
+ pressBackdrop(): Promise<void>;
73
+ /** Focuses a separator and presses a key on it: an arrow key, `Home` or `End`. */
74
+ pressSeparator(index: number, key: string, modifiers?: KeyModifiers): Promise<void>;
75
+ }
76
+ export {};
77
+ //# sourceMappingURL=split-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-view.d.ts","sourceRoot":"","sources":["../src/split-view.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAY,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAExD,gCAAgC;AAChC,KAAK,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAI9C;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,SAAQ,OAAO;;IAC3C,OAAgB,SAAS,SAAe;IAUxC,mEAAmE;IACnE,IAAI,OAAO,IAAI,WAAW,EAAE,CAI3B;IAED,uDAAuD;IACvD,IAAI,WAAW,IAAI,MAAM,EAAE,CAE1B;IAED,uCAAuC;IACvC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B,2EAA2E;IAC3E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAQjC,kEAAkE;IAClE,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,mEAAmE;IACnE,IAAI,OAAO,IAAI,WAAW,CAEzB;IAED,gEAAgE;IAChE,IAAI,MAAM,IAAI,WAAW,CAExB;IAED,4CAA4C;IAC5C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI/B,gFAAgF;IAChF,IAAI,UAAU,IAAI,MAAM,GAAG,IAAI,CAE9B;IAED,oDAAoD;IACpD,IAAI,IAAI,IAAI,MAAM,GAAG,IAAI,CAExB;IAED;;;OAGG;IACH,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAED,4FAA4F;IAC5F,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,wEAAwE;IACxE,IAAI,aAAa,IAAI,MAAM,GAAG,IAAI,CAEjC;IAED,6DAA6D;IAC7D,IAAI,UAAU,IAAI,WAAW,EAAE,CAI9B;IAED,0DAA0D;IAC1D,IAAI,QAAQ,IAAI,WAAW,GAAG,IAAI,CAEjC;IAED,8DAA8D;IAC9D,IAAI,aAAa,IAAI,WAAW,GAAG,IAAI,CAEtC;IAED;;;;OAIG;IACH,IAAI,UAAU,IAAI,WAAW,GAAG,IAAI,CAGnC;IAED,gEAAgE;IAC1D,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAMpC,6DAA6D;IACvD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B;;;OAGG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK/C,4EAA4E;IACtE,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAMpC,kFAAkF;IAC5E,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,YAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;CAM9F"}
@@ -0,0 +1,145 @@
1
+ import { click, focus, settled } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { pressKey } from "./focus.js";
4
+ const GROUP = ':scope > [data-jn-split-view-group]';
5
+ /**
6
+ * Drives a `<SplitView>` from `@ember-joinery/ember`: reaches its columns and separators, reads
7
+ * which columns it shows, and uses its sidebar toggle and its back button.
8
+ *
9
+ * const view = new SplitViewHarness('mail') // <SplitView @name="mail">
10
+ * await view.toggleSidebar()
11
+ * assert.strictEqual(view.visibility, 'double-column')
12
+ * await view.pressSeparator(0, 'ArrowRight')
13
+ *
14
+ * The view wraps the app, so the parts inside it still belong to the components around them;
15
+ * its own elements are found by their `data-jn-split-view-*` attributes. A page object can
16
+ * extend this class and declare the app's components with `@child`.
17
+ */
18
+ export class SplitViewHarness extends Harness {
19
+ static component = 'split-view';
20
+ /** Its own elements that match, in order: not those of a split view inside it. */
21
+ #own(selector) {
22
+ const root = this.element;
23
+ return [...root.querySelectorAll(selector)].filter(element => element.closest('[data-jn-split-view]') === root);
24
+ }
25
+ /** The columns it shows now, in order. A narrow view shows one. */
26
+ get columns() {
27
+ return [
28
+ ...this.element.querySelectorAll(`${GROUP} > [data-jn-split-view-column]`),
29
+ ].filter(column => getComputedStyle(column).display !== 'none');
30
+ }
31
+ /** The names of the columns it shows now, in order. */
32
+ get columnNames() {
33
+ return this.columns.map(column => column.getAttribute('data-jn-split-view-column'));
34
+ }
35
+ /** Whether it shows the column now. */
36
+ has(column) {
37
+ return this.columnNames.includes(column);
38
+ }
39
+ /** A column that it shows now. Throws when it does not show the column. */
40
+ column(name) {
41
+ const column = this.columns.find(element => element.getAttribute('data-jn-split-view-column') === name);
42
+ if (!column)
43
+ throw new Error(`Joinery harness: no ${name} column shown in ${this}`);
44
+ return column;
45
+ }
46
+ /** The sidebar, the first column. Throws when it is not shown. */
47
+ get sidebar() {
48
+ return this.column('sidebar');
49
+ }
50
+ /** The content, the middle column. Throws when it is not shown. */
51
+ get content() {
52
+ return this.column('content');
53
+ }
54
+ /** The detail, the last column. Throws when it is not shown. */
55
+ get detail() {
56
+ return this.column('detail');
57
+ }
58
+ /** A shown column's width in CSS pixels. */
59
+ widthOf(column) {
60
+ return this.column(column).offsetWidth;
61
+ }
62
+ /** Which columns a wide view shows: `all`, `double-column` or `detail-only`. */
63
+ get visibility() {
64
+ return this.element.getAttribute('data-visibility');
65
+ }
66
+ /** Its `@mode`: `tile`, `overlay` or `displace`. */
67
+ get mode() {
68
+ return this.element.getAttribute('data-mode');
69
+ }
70
+ /**
71
+ * How a wide view shows its sidebar now: `tiled`, `overlaid`, `displaced` or `hidden`. `null`
72
+ * in a narrow view.
73
+ */
74
+ get sidebarLayout() {
75
+ return this.element.getAttribute('data-sidebar');
76
+ }
77
+ /** Whether it is narrower than its `@compactBreakpoint`, and shows one column at a time. */
78
+ get isCompact() {
79
+ return this.element.hasAttribute('data-compact');
80
+ }
81
+ /** The column a narrow view shows: `sidebar`, `content` or `detail`. */
82
+ get compactColumn() {
83
+ return this.element.getAttribute('data-compact-column');
84
+ }
85
+ /** The separators between the columns it shows, in order. */
86
+ get separators() {
87
+ return [
88
+ ...this.element.querySelectorAll(`${GROUP} > [data-jn-split-view-separator]`),
89
+ ].filter(separator => getComputedStyle(separator).display !== 'none');
90
+ }
91
+ /** The backdrop behind an overlaid sidebar, or `null`. */
92
+ get backdrop() {
93
+ return this.element.querySelector(':scope > [data-jn-split-view-backdrop]');
94
+ }
95
+ /** The sidebar toggle, or `null` (a narrow view has none). */
96
+ get sidebarToggle() {
97
+ return this.#own('[data-jn-split-view-toggle]')[0] ?? null;
98
+ }
99
+ /**
100
+ * The back button, or `null` (only a narrow view past its first column has one). A narrow
101
+ * view renders every column and hides all but one, so it is the button that shows: the one
102
+ * in the column on screen. A button in a hidden column is not one the user can press.
103
+ */
104
+ get backButton() {
105
+ const buttons = this.#own('[data-jn-split-view-back]');
106
+ return buttons.find(button => button.getClientRects().length > 0) ?? null;
107
+ }
108
+ /** Clicks the sidebar toggle. Throws when the view has none. */
109
+ async toggleSidebar() {
110
+ const toggle = this.sidebarToggle;
111
+ if (!toggle)
112
+ throw new Error(`Joinery harness: no sidebar toggle in ${this}`);
113
+ await click(toggle);
114
+ }
115
+ /** Clicks the back button. Throws when the view has none. */
116
+ async back() {
117
+ const button = this.backButton;
118
+ if (!button)
119
+ throw new Error(`Joinery harness: no back button in ${this}`);
120
+ await click(button);
121
+ }
122
+ /**
123
+ * Shows a column of a narrow view, as the app does when it calls `showColumn()`. It sends the
124
+ * `joinery:show-column` event, which the view listens for.
125
+ */
126
+ async showColumn(column) {
127
+ this.element.dispatchEvent(new CustomEvent('joinery:show-column', { detail: column }));
128
+ await settled();
129
+ }
130
+ /** Clicks the backdrop of an overlaid sidebar, which closes the sidebar. */
131
+ async pressBackdrop() {
132
+ const backdrop = this.backdrop;
133
+ if (!backdrop)
134
+ throw new Error(`Joinery harness: no backdrop in ${this}`);
135
+ await click(backdrop);
136
+ }
137
+ /** Focuses a separator and presses a key on it: an arrow key, `Home` or `End`. */
138
+ async pressSeparator(index, key, modifiers = {}) {
139
+ const separator = this.separators[index];
140
+ if (!separator)
141
+ throw new Error(`Joinery harness: no separator #${index} in ${this}`);
142
+ await focus(separator);
143
+ await pressKey(key, modifiers);
144
+ }
145
+ }
@@ -0,0 +1,25 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Reads a `<StatusBar>` from `@ember-joinery/ember`: its items and its parts.
4
+ *
5
+ * const bar = new StatusBarHarness('status') // <StatusBar @name="status">
6
+ * assert.deepEqual(bar.items, ['main', 'Saved'])
7
+ * assert.strictEqual(bar.liveText, 'Saved')
8
+ */
9
+ export declare class StatusBarHarness extends Harness {
10
+ #private;
11
+ static component: string;
12
+ /** Each item's element, in order. */
13
+ get itemElements(): HTMLElement[];
14
+ /** Each item's text, in order. */
15
+ get items(): string[];
16
+ /** The text of its live items (`role="status"`), which assistive technology announces. */
17
+ get liveText(): string;
18
+ /** The `Leading` part, or `null`. */
19
+ get leading(): HTMLElement | null;
20
+ /** The `Center` part, or `null`. */
21
+ get center(): HTMLElement | null;
22
+ /** The `Trailing` part, or `null`. */
23
+ get trailing(): HTMLElement | null;
24
+ }
25
+ //# sourceMappingURL=status-bar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-bar.d.ts","sourceRoot":"","sources":["../src/status-bar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAGtC;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,OAAO;;IAC3C,OAAgB,SAAS,SAAe;IAMxC,qCAAqC;IACrC,IAAI,YAAY,IAAI,WAAW,EAAE,CAEhC;IAED,kCAAkC;IAClC,IAAI,KAAK,IAAI,MAAM,EAAE,CAEpB;IAED,0FAA0F;IAC1F,IAAI,QAAQ,IAAI,MAAM,CAKrB;IAED,qCAAqC;IACrC,IAAI,OAAO,IAAI,WAAW,GAAG,IAAI,CAEhC;IAED,oCAAoC;IACpC,IAAI,MAAM,IAAI,WAAW,GAAG,IAAI,CAE/B;IAED,sCAAsC;IACtC,IAAI,QAAQ,IAAI,WAAW,GAAG,IAAI,CAEjC;CACF"}
@@ -0,0 +1,42 @@
1
+ import { Harness } from "./harness.js";
2
+ import { textOf } from "./-private/checkable.js";
3
+ /**
4
+ * Reads a `<StatusBar>` from `@ember-joinery/ember`: its items and its parts.
5
+ *
6
+ * const bar = new StatusBarHarness('status') // <StatusBar @name="status">
7
+ * assert.deepEqual(bar.items, ['main', 'Saved'])
8
+ * assert.strictEqual(bar.liveText, 'Saved')
9
+ */
10
+ export class StatusBarHarness extends Harness {
11
+ static component = 'status-bar';
12
+ #query(part) {
13
+ return this.element.querySelector(`[data-jn-status-bar-${part}]`);
14
+ }
15
+ /** Each item's element, in order. */
16
+ get itemElements() {
17
+ return [...this.element.querySelectorAll('[data-jn-status-bar-item]')];
18
+ }
19
+ /** Each item's text, in order. */
20
+ get items() {
21
+ return this.itemElements.map(textOf);
22
+ }
23
+ /** The text of its live items (`role="status"`), which assistive technology announces. */
24
+ get liveText() {
25
+ return this.itemElements
26
+ .filter(item => item.getAttribute('role') === 'status')
27
+ .map(textOf)
28
+ .join(' ');
29
+ }
30
+ /** The `Leading` part, or `null`. */
31
+ get leading() {
32
+ return this.#query('leading');
33
+ }
34
+ /** The `Center` part, or `null`. */
35
+ get center() {
36
+ return this.#query('center');
37
+ }
38
+ /** The `Trailing` part, or `null`. */
39
+ get trailing() {
40
+ return this.#query('trailing');
41
+ }
42
+ }
@@ -0,0 +1,38 @@
1
+ import { Harness } from './harness.ts';
2
+ /**
3
+ * Drives a `<TabBar>` from `@ember-joinery/ember`: reads its items, the current one and their
4
+ * badges, and follows an item.
5
+ *
6
+ * const tabs = new TabBarHarness('main') // <TabBar @name="main">
7
+ * assert.deepEqual(tabs.labels, ['Home', 'Inbox', 'Settings'])
8
+ * await tabs.select('Inbox')
9
+ * assert.strictEqual(tabs.badgeOf('Inbox'), '3')
10
+ */
11
+ export declare class TabBarHarness extends Harness {
12
+ static component: string;
13
+ /** The name of the `<nav>`: its `aria-label`. */
14
+ get label(): string;
15
+ /** Its variant: `bar` or `floating`. A `top` bar is always `floating`. */
16
+ get variant(): string | null;
17
+ /** Its placement: `bottom` or `top`. */
18
+ get placement(): string | null;
19
+ /** Whether it is minimized. */
20
+ get isMinimized(): boolean;
21
+ /** Its items, in order. The search is not one of them. */
22
+ get items(): HTMLElement[];
23
+ /** The label of each item, in order, without its badge. */
24
+ get labels(): string[];
25
+ /** The label of the current item (`aria-current="page"` or the `active` class), or `null`. */
26
+ get current(): string | null;
27
+ /** The search item, or `null`. */
28
+ get search(): HTMLElement | null;
29
+ /** The accessory, or `null`. */
30
+ get accessory(): HTMLElement | null;
31
+ /** The item with this label. Throws when there is none. */
32
+ item(label: string): HTMLElement;
33
+ /** The text of an item's badge: `''` for a dot, `null` when the item has no badge. */
34
+ badgeOf(label: string): string | null;
35
+ /** Clicks the item with this label. */
36
+ select(label: string): Promise<void>;
37
+ }
38
+ //# sourceMappingURL=tab-bar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tab-bar.d.ts","sourceRoot":"","sources":["../src/tab-bar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAgBtC;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,OAAO;IACxC,OAAgB,SAAS,SAAY;IAErC,iDAAiD;IACjD,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,0EAA0E;IAC1E,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAE3B;IAED,wCAAwC;IACxC,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,CAE7B;IAED,+BAA+B;IAC/B,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,0DAA0D;IAC1D,IAAI,KAAK,IAAI,WAAW,EAAE,CAEzB;IAED,2DAA2D;IAC3D,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAED,8FAA8F;IAC9F,IAAI,OAAO,IAAI,MAAM,GAAG,IAAI,CAG3B;IAED,kCAAkC;IAClC,IAAI,MAAM,IAAI,WAAW,GAAG,IAAI,CAE/B;IAED,gCAAgC;IAChC,IAAI,SAAS,IAAI,WAAW,GAAG,IAAI,CAElC;IAED,2DAA2D;IAC3D,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAMhC,sFAAsF;IACtF,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKrC,uCAAuC;IACjC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
@@ -0,0 +1,78 @@
1
+ import { click } from '@ember/test-helpers';
2
+ import { Harness } from "./harness.js";
3
+ import { accessibleName } from "./-private/checkable.js";
4
+ /** An item's label: its text without its badge. */
5
+ function labelOf(item) {
6
+ return [...item.childNodes]
7
+ .filter(node => !node.hasAttribute?.('data-test-jn-part'))
8
+ .map(node => node.textContent ?? '')
9
+ .join(' ')
10
+ .replace(/\s+/g, ' ')
11
+ .trim();
12
+ }
13
+ const isCurrent = (item) => item.getAttribute('aria-current') === 'page' || item.classList.contains('active');
14
+ /**
15
+ * Drives a `<TabBar>` from `@ember-joinery/ember`: reads its items, the current one and their
16
+ * badges, and follows an item.
17
+ *
18
+ * const tabs = new TabBarHarness('main') // <TabBar @name="main">
19
+ * assert.deepEqual(tabs.labels, ['Home', 'Inbox', 'Settings'])
20
+ * await tabs.select('Inbox')
21
+ * assert.strictEqual(tabs.badgeOf('Inbox'), '3')
22
+ */
23
+ export class TabBarHarness extends Harness {
24
+ static component = 'tab-bar';
25
+ /** The name of the `<nav>`: its `aria-label`. */
26
+ get label() {
27
+ return accessibleName(this.element);
28
+ }
29
+ /** Its variant: `bar` or `floating`. A `top` bar is always `floating`. */
30
+ get variant() {
31
+ return this.element.getAttribute('data-variant');
32
+ }
33
+ /** Its placement: `bottom` or `top`. */
34
+ get placement() {
35
+ return this.element.getAttribute('data-placement');
36
+ }
37
+ /** Whether it is minimized. */
38
+ get isMinimized() {
39
+ return this.element.hasAttribute('data-minimized');
40
+ }
41
+ /** Its items, in order. The search is not one of them. */
42
+ get items() {
43
+ return this.parts('item');
44
+ }
45
+ /** The label of each item, in order, without its badge. */
46
+ get labels() {
47
+ return this.items.map(labelOf);
48
+ }
49
+ /** The label of the current item (`aria-current="page"` or the `active` class), or `null`. */
50
+ get current() {
51
+ const item = this.items.find(isCurrent);
52
+ return item ? labelOf(item) : null;
53
+ }
54
+ /** The search item, or `null`. */
55
+ get search() {
56
+ return this.parts('search')[0] ?? null;
57
+ }
58
+ /** The accessory, or `null`. */
59
+ get accessory() {
60
+ return this.parts('accessory')[0] ?? null;
61
+ }
62
+ /** The item with this label. Throws when there is none. */
63
+ item(label) {
64
+ const item = this.items.find(candidate => labelOf(candidate) === label);
65
+ if (!item)
66
+ throw new Error(`Joinery harness: no item "${label}" in ${this}`);
67
+ return item;
68
+ }
69
+ /** The text of an item's badge: `''` for a dot, `null` when the item has no badge. */
70
+ badgeOf(label) {
71
+ const badge = this.item(label).querySelector('[data-test-jn-part="badge"]');
72
+ return badge ? (badge.textContent ?? '').trim() : null;
73
+ }
74
+ /** Clicks the item with this label. */
75
+ async select(label) {
76
+ await click(this.item(label));
77
+ }
78
+ }