-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material/list): add test harnesses for list components. #17859
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9eed124
feat(material/list): add test harnesses for list components.
mmalerba a909189
fix lint and tests
mmalerba 97f254e
address comments
mmalerba 99406a3
rearrange files
mmalerba c6b1bbc
fix lint and test
mmalerba 2a6c91a
address comments
mmalerba ca807bc
fix typo
mmalerba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_test_library", "ng_web_test_suite", "ts_library") | ||
|
||
ts_library( | ||
name = "testing", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/material/divider/testing", | ||
deps = [ | ||
"//src/cdk/testing", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob(["**/*.ts"]), | ||
) | ||
|
||
ng_test_library( | ||
name = "harness_tests_lib", | ||
srcs = ["shared.spec.ts"], | ||
deps = [ | ||
":testing", | ||
"//src/cdk/testing", | ||
"//src/cdk/testing/testbed", | ||
"//src/material/divider", | ||
"@npm//@angular/platform-browser", | ||
], | ||
) | ||
|
||
ng_test_library( | ||
name = "unit_tests_lib", | ||
srcs = glob( | ||
["**/*.spec.ts"], | ||
exclude = ["shared.spec.ts"], | ||
), | ||
deps = [ | ||
":harness_tests_lib", | ||
":testing", | ||
"//src/material/divider", | ||
], | ||
) | ||
|
||
ng_web_test_suite( | ||
name = "unit_tests", | ||
deps = [":unit_tests_lib"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import {BaseHarnessFilters} from '@angular/cdk/testing'; | ||
|
||
export interface DividerHarnessFilters extends BaseHarnessFilters { | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {MatDividerModule} from '@angular/material/divider'; | ||
import {MatDividerHarness} from './divider-harness'; | ||
import {runHarnessTests} from './shared.spec'; | ||
|
||
describe('Non-MDC-based MatButtonHarness', () => { | ||
runHarnessTests(MatDividerModule, MatDividerHarness); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing'; | ||
import {DividerHarnessFilters} from './divider-harness-filters'; | ||
|
||
/** | ||
* Harness for interacting with a `mat-divider`. | ||
* @dynamic | ||
*/ | ||
export class MatDividerHarness extends ComponentHarness { | ||
static hostSelector = 'mat-divider'; | ||
|
||
static with(options: DividerHarnessFilters = {}) { | ||
return new HarnessPredicate(MatDividerHarness, options); | ||
} | ||
|
||
async getOrientation(): Promise<'horizontal' | 'vertical'> { | ||
return (await this.host()).getAttribute('aria-orientation') as | ||
Promise<'horizontal' | 'vertical'>; | ||
} | ||
|
||
async isInset(): Promise<boolean> { | ||
return (await this.host()).hasClass('mat-divider-inset'); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.io/license | ||
*/ | ||
|
||
export * from './public-api'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
export * from './divider-harness'; | ||
export * from './divider-harness-filters'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {HarnessLoader} from '@angular/cdk/testing'; | ||
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; | ||
import {Component} from '@angular/core'; | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {MatDividerModule} from '@angular/material/divider'; | ||
import {MatDividerHarness} from './divider-harness'; | ||
|
||
/** Shared tests to run on both the original and MDC-based dividers. */ | ||
export function runHarnessTests( | ||
dividerModule: typeof MatDividerModule, dividerHarness: typeof MatDividerHarness) { | ||
let fixture: ComponentFixture<DividerHarnessTest>; | ||
let loader: HarnessLoader; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [dividerModule], | ||
declarations: [DividerHarnessTest], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(DividerHarnessTest); | ||
fixture.detectChanges(); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
}); | ||
|
||
it('should load all divider harnesses', async () => { | ||
const dividers = await loader.getAllHarnesses(dividerHarness); | ||
expect(dividers.length).toBe(2); | ||
}); | ||
|
||
it('should check if divider is inset', async () => { | ||
const dividers = await loader.getAllHarnesses(dividerHarness); | ||
expect(await dividers[0].isInset()).toBe(false); | ||
expect(await dividers[1].isInset()).toBe(true); | ||
}); | ||
|
||
it('should get divider orientation', async () => { | ||
const dividers = await loader.getAllHarnesses(dividerHarness); | ||
expect(await dividers[0].getOrientation()).toBe('horizontal'); | ||
expect(await dividers[1].getOrientation()).toBe('vertical'); | ||
}); | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<mat-divider></mat-divider> | ||
<mat-divider inset vertical></mat-divider> | ||
` | ||
}) | ||
class DividerHarnessTest {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_test_library", "ng_web_test_suite", "ts_library") | ||
|
||
ts_library( | ||
name = "testing", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
module_name = "@angular/material/list/testing", | ||
deps = [ | ||
"//src/cdk/coercion", | ||
"//src/cdk/testing", | ||
"//src/material/divider/testing", | ||
], | ||
) | ||
|
||
filegroup( | ||
name = "source-files", | ||
srcs = glob(["**/*.ts"]), | ||
) | ||
|
||
ng_test_library( | ||
name = "harness_tests_lib", | ||
srcs = ["shared.spec.ts"], | ||
deps = [ | ||
":testing", | ||
"//src/cdk/testing", | ||
"//src/cdk/testing/testbed", | ||
"//src/material/divider/testing", | ||
"//src/material/list", | ||
"@npm//@angular/platform-browser", | ||
], | ||
) | ||
|
||
ng_test_library( | ||
name = "unit_tests_lib", | ||
srcs = glob( | ||
["**/*.spec.ts"], | ||
exclude = ["shared.spec.ts"], | ||
), | ||
deps = [ | ||
":harness_tests_lib", | ||
":testing", | ||
"//src/material/divider/testing", | ||
"//src/material/list", | ||
], | ||
) | ||
|
||
ng_web_test_suite( | ||
name = "unit_tests", | ||
deps = [":unit_tests_lib"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
|
||
import {HarnessPredicate} from '@angular/cdk/testing'; | ||
import {MatListHarnessBase} from './list-harness-base'; | ||
import {ActionListHarnessFilters, ActionListItemHarnessFilters} from './list-harness-filters'; | ||
import {getListItemPredicate, MatListItemHarnessBase} from './list-item-harness-base'; | ||
|
||
/** Harness for interacting with a standard mat-action-list in tests. */ | ||
export class MatActionListHarness extends MatListHarnessBase< | ||
typeof MatActionListItemHarness, MatActionListItemHarness, ActionListItemHarnessFilters> { | ||
/** The selector for the host element of a `MatActionList` instance. */ | ||
static hostSelector = 'mat-action-list'; | ||
|
||
/** | ||
* Gets a `HarnessPredicate` that can be used to search for a `MatActionListHarness` that meets | ||
* certain criteria. | ||
* @param options Options for filtering which action list instances are considered a match. | ||
* @return a `HarnessPredicate` configured with the given options. | ||
*/ | ||
static with(options: ActionListHarnessFilters = {}): HarnessPredicate<MatActionListHarness> { | ||
return new HarnessPredicate(MatActionListHarness, options); | ||
} | ||
|
||
_itemHarness = MatActionListItemHarness; | ||
} | ||
|
||
/** Harness for interacting with an action list item. */ | ||
export class MatActionListItemHarness extends MatListItemHarnessBase { | ||
/** The selector for the host element of a `MatListItem` instance. */ | ||
static hostSelector = ['mat-list-item', 'a[mat-list-item]', 'button[mat-list-item]'] | ||
.map(selector => `${MatActionListHarness.hostSelector} ${selector}`) | ||
.join(','); | ||
|
||
/** | ||
* Gets a `HarnessPredicate` that can be used to search for a `MatActionListItemHarness` that | ||
* meets certain criteria. | ||
* @param options Options for filtering which action list item instances are considered a match. | ||
* @return a `HarnessPredicate` configured with the given options. | ||
*/ | ||
static with(options: ActionListItemHarnessFilters = {}): | ||
HarnessPredicate<MatActionListItemHarness> { | ||
return getListItemPredicate(MatActionListItemHarness, options); | ||
} | ||
|
||
/** Clicks on the action list item. */ | ||
async click(): Promise<void> { | ||
return (await this.host()).click(); | ||
} | ||
|
||
/** Focuses the action list item. */ | ||
async focus(): Promise<void> { | ||
return (await this.host()).focus(); | ||
} | ||
|
||
/** Blurs the action list item. */ | ||
async blur(): Promise<void> { | ||
return (await this.host()).blur(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.io/license | ||
*/ | ||
|
||
export * from './public-api'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's consistent, but it feels a little silly to have a test harness for what is basically a
div
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah its a little silly, but there are actually couple methods on it, and just having the selector encapsulated in a harness is kind of nice