Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(material/tree): Add test harness for MatTree #20018

Closed
wants to merge 4 commits into from

Conversation

annieyw
Copy link
Contributor

@annieyw annieyw commented Jul 17, 2020

No description provided.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 17, 2020
@annieyw annieyw marked this pull request as ready for review July 17, 2020 21:02
@annieyw annieyw requested a review from mmalerba July 17, 2020 21:02
src/material/tree/testing/node-harness.ts Outdated Show resolved Hide resolved
}

/** Gets the tree node's text. */
async getText(): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the nested tree node this will get the text of the node and everything under it, you might want to have separate implementations of this method for the different subclasses

src/material/tree/testing/node-harness.ts Outdated Show resolved Hide resolved
src/material/tree/testing/tree-harness-filters.ts Outdated Show resolved Hide resolved
}

/** Gets all of the nodes in the tree. */
async getNodes(filter: TreeNodeHarnessFilters = {}): Promise<MatTreeNodeHarness[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jelbourn @andrewseguin thoughts on whether we should have 2 methods or just a single getNodes method regardless of the type of node? It feels to me like we should just have 1 method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these two methods does seem a bit confusing. If we can guarantee that we can operate the same API for both types of node, I think it's fine to combine them under one method.

} from '@angular/material/tree/testing';

/** Harness for interacting with a standard mat-tree in tests. */
export class MatTreeHarness extends ComponentHarness {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add an additional method to get the text as some type of structured data. I think @andrewseguin did something similar for table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see (in a follow-up) adding a harness method here like prettyPrint() that just prints out the text of the tree in a human-readable form for debugging. Table doesn't have something like this, but maybe it could.

The table harness (implemented by Kristiyan) does have convenience method for getting cell text strings, which we could do here too (also in a follow-up)

} from '@angular/material/tree/testing';

/** Harness for interacting with a standard mat-tree in tests. */
export class MatTreeHarness extends ComponentHarness {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could maybe be a followup PR, but I think both the tree and the node harness should implement HarnessLoader

/** The selector of the host element of a `MatTreeNode` instance. */
static hostSelector = '.mat-tree-node';

_toggle = this.locatorForOptional('[matTreeNodeToggle]');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW the intent is that this directive is just one way someone could add a toggle for a node. We may want to make the harness more flexible in terms of how expand/collapse works.

} else if (role === 'treeitem') {
return true
} else {
throw new Error('Invalid node role');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error('Invalid node role');
throw Error('Invalid node role');

You don't actually need new with Error (this is different from code written inside Google where new is required just for consistency)

/** Whether the node is a leaf node. */
async isLeaf(): Promise<boolean> {
const role = await (await this.host()).getAttribute('role');
if (role === 'group') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the way we use role="group" now is probably wrong and they should all be treeitem (related #17818).

}

/** Gets the level of the tree node.. */
async getLevel(): Promise<number> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be clear about whether this is zero-based or one-based (see comments on #17818)

} from '@angular/material/tree/testing';

/** Harness for interacting with a standard mat-tree in tests. */
export class MatTreeHarness extends ComponentHarness {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could see (in a follow-up) adding a harness method here like prettyPrint() that just prints out the text of the tree in a human-readable form for debugging. Table doesn't have something like this, but maybe it could.

The table harness (implemented by Kristiyan) does have convenience method for getting cell text strings, which we could do here too (also in a follow-up)

}

/** Gets all of the nodes in the tree. */
async getNodes(filter: TreeNodeHarnessFilters = {}): Promise<MatTreeNodeHarness[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these two methods does seem a bit confusing. If we can guarantee that we can operate the same API for both types of node, I think it's fine to combine them under one method.

@jelbourn
Copy link
Member

Also the commit message prefix should be feat(material/tree):

@annieyw annieyw changed the title feat(tree/testing): Add test harness for MatTree feat(material/tree): Add test harness for MatTree Jul 21, 2020
@annieyw annieyw closed this Aug 19, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 19, 2020
@annieyw annieyw deleted the tree-harness branch November 9, 2020 19:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants