forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material/list): add test harnesses for list components (angular#…
- Loading branch information
Showing
24 changed files
with
1,477 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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.