Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions goldens/aria/tree/testing/index.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## API Report File for "@angular/aria_tree_testing"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import { BaseHarnessFilters } from '@angular/cdk/testing';
import { ComponentHarness } from '@angular/cdk/testing';
import { ContentContainerComponentHarness } from '@angular/cdk/testing';
import { HarnessPredicate } from '@angular/cdk/testing';

// @public (undocumented)
export interface TextTree {
// (undocumented)
children?: TextTree[];
// (undocumented)
text?: string;
}

// @public
export class TreeHarness extends ComponentHarness {
getItems(filter?: TreeItemHarnessFilters): Promise<TreeItemHarness[]>;
getTreeStructure(): Promise<TextTree>;
// (undocumented)
static hostSelector: string;
static with(options?: TreeHarnessFilters): HarnessPredicate<TreeHarness>;
}

// @public
export interface TreeHarnessFilters extends BaseHarnessFilters {
}

// @public
export class TreeItemHarness extends ContentContainerComponentHarness<string> {
click(): Promise<void>;
getLevel(): Promise<number>;
getText(): Promise<string>;
// (undocumented)
static hostSelector: string;
isDisabled(): Promise<boolean>;
isExpanded(): Promise<boolean>;
isSelected(): Promise<boolean>;
static with(options?: TreeItemHarnessFilters): HarnessPredicate<TreeItemHarness>;
}

// @public
export interface TreeItemHarnessFilters extends BaseHarnessFilters {
disabled?: boolean;
expanded?: boolean;
level?: number;
selected?: boolean;
text?: string | RegExp;
}

// (No @packageDocumentation comment for this package)

```
1 change: 1 addition & 0 deletions src/aria/config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ARIA_ENTRYPOINTS = [
"tabs",
"toolbar",
"tree",
"tree/testing",
"private",
]

Expand Down
38 changes: 38 additions & 0 deletions src/aria/tree/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
load("//tools:defaults.bzl", "ng_project", "ng_web_test_suite", "ts_project")

package(default_visibility = ["//visibility:public"])

ts_project(
name = "testing",
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
deps = [
"//src/cdk/testing",
],
)

filegroup(
name = "source-files",
srcs = glob(["**/*.ts"]),
)

ng_project(
name = "unit_tests_lib",
testonly = True,
srcs = glob(["**/*.spec.ts"]),
deps = [
":testing",
"//:node_modules/@angular/common",
"//:node_modules/@angular/core",
"//src/aria/tree",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
],
)

ng_web_test_suite(
name = "unit_tests",
deps = [":unit_tests_lib"],
)
9 changes: 9 additions & 0 deletions src/aria/tree/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

export * from './public-api';
82 changes: 82 additions & 0 deletions src/aria/tree/testing/item-harness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import {ContentContainerComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
import {TreeItemHarnessFilters} from './tree-harness-filters';

/** Harness for interacting with an Aria tree item. */
export class TreeItemHarness extends ContentContainerComponentHarness<string> {
static hostSelector = '[ngTreeItem]';

/**
* Gets a `HarnessPredicate` that can be used to search for a tree item with specific attributes.
* @param options Options for narrowing the search
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options: TreeItemHarnessFilters = {}): HarnessPredicate<TreeItemHarness> {
return new HarnessPredicate(TreeItemHarness, options)
.addOption('text', options.text, (harness, text) =>
HarnessPredicate.stringMatches(harness.getText(), text),
)
.addOption(
'disabled',
options.disabled,
async (harness, disabled) => (await harness.isDisabled()) === disabled,
)
.addOption(
'expanded',
options.expanded,
async (harness, expanded) => (await harness.isExpanded()) === expanded,
)
.addOption(
'selected',
options.selected,
async (harness, selected) => (await harness.isSelected()) === selected,
)
.addOption(
'level',
options.level,
async (harness, level) => (await harness.getLevel()) === level,
);
}

/** Whether the tree item is expanded. */
async isExpanded(): Promise<boolean> {
return (await this._getHostAttribute('aria-expanded')) === 'true';
}

/** Whether the tree item is disabled. */
async isDisabled(): Promise<boolean> {
return (await this._getHostAttribute('aria-disabled')) === 'true';
}

/** Whether the tree item is selected. */
async isSelected(): Promise<boolean> {
return (await this._getHostAttribute('aria-selected')) === 'true';
}

/** Gets the level of the tree item. Note that this gets the aria-level and is 1 indexed. */
async getLevel(): Promise<number> {
const level = (await this._getHostAttribute('aria-level')) ?? '1';
return parseInt(level);
}

/** Gets the tree item's text. */
async getText(): Promise<string> {
return (await this.host()).text({exclude: '[ngTreeItem], [ngTreeItemGroup]'});
}

/** Clicks the tree item. */
async click(): Promise<void> {
return (await this.host()).click();
}

private async _getHostAttribute(attributeName: string): Promise<string | null> {
return (await this.host()).getAttribute(attributeName);
}
}
11 changes: 11 additions & 0 deletions src/aria/tree/testing/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

export * from './item-harness';
export * from './tree-harness';
export * from './tree-harness-filters';
30 changes: 30 additions & 0 deletions src/aria/tree/testing/tree-harness-filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

import {BaseHarnessFilters} from '@angular/cdk/testing';

/** A set of criteria that can be used to filter a list of tree harness instances */
export interface TreeHarnessFilters extends BaseHarnessFilters {}

/** A set of criteria that can be used to filter a list of tree item harness instances. */
export interface TreeItemHarnessFilters extends BaseHarnessFilters {
/** Only find instances whose text matches the given value. */
text?: string | RegExp;

/** Only find instances whose disabled state matches the given value. */
disabled?: boolean;

/** Only find instances whose expansion state matches the given value. */
expanded?: boolean;

/** Only find instances whose selection state matches the given value. */
selected?: boolean;

/** Only find instances whose level matches the given value. */
level?: number;
}
Loading
Loading