-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material-experimental): add test harness for mat-tooltip #16676
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("@io_bazel_rules_sass//:defs.bzl", "sass_binary", "sass_library") | ||
load("//tools:defaults.bzl", "ng_e2e_test_library", "ng_module", "ng_test_library", "ng_web_test_suite", "ts_library") | ||
load("//src/e2e-app:test_suite.bzl", "e2e_test_suite") | ||
|
||
ng_module( | ||
name = "mdc-tooltip", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = [ | ||
"**/*.spec.ts", | ||
"harness/**", | ||
], | ||
), | ||
assets = [ | ||
# TODO: include scss assets | ||
] + glob(["**/*.html"]), | ||
module_name = "@angular/material-experimental/mdc-tooltip", | ||
deps = [ | ||
"//src/material/core", | ||
], | ||
) | ||
|
||
ts_library( | ||
name = "harness", | ||
srcs = glob( | ||
["harness/**/*.ts"], | ||
exclude = ["**/*.spec.ts"], | ||
), | ||
deps = [ | ||
"//src/cdk-experimental/testing", | ||
"//src/cdk/private/testing", | ||
], | ||
) | ||
|
||
sass_library( | ||
name = "mdc_tooltip_scss_lib", | ||
srcs = glob(["**/_*.scss"]), | ||
deps = [ | ||
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib", | ||
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib", | ||
"//src/material/core:core_scss_lib", | ||
], | ||
) | ||
|
||
sass_binary( | ||
name = "tooltip_scss", | ||
src = "tooltip.scss", | ||
include_paths = [ | ||
"external/npm/node_modules", | ||
], | ||
deps = [ | ||
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib", | ||
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib", | ||
"//src/material/core:all_themes", | ||
], | ||
) | ||
|
||
ng_test_library( | ||
name = "tooltip_tests_lib", | ||
srcs = [ | ||
"harness/tooltip-harness.spec.ts", | ||
], | ||
deps = [ | ||
":harness", | ||
":mdc-tooltip", | ||
"//src/cdk-experimental/testing", | ||
"//src/cdk-experimental/testing/testbed", | ||
"//src/cdk/testing", | ||
"//src/material/tooltip", | ||
"@npm//@angular/platform-browser", | ||
], | ||
) | ||
|
||
ng_web_test_suite( | ||
name = "unit_tests", | ||
deps = [ | ||
":tooltip_tests_lib", | ||
"//src/material-experimental:mdc_require_config.js", | ||
], | ||
) | ||
|
||
ng_e2e_test_library( | ||
name = "e2e_test_sources", | ||
srcs = glob(["**/*.e2e.spec.ts"]), | ||
deps = [ | ||
"//src/cdk/private/testing/e2e", | ||
], | ||
) | ||
|
||
e2e_test_suite( | ||
name = "e2e_tests", | ||
deps = [ | ||
":e2e_test_sources", | ||
"//src/cdk/private/testing/e2e", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<!-- TODO --> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@import '../mdc-helpers/mdc-helpers'; | ||
|
||
@mixin mat-tooltip-theme-mdc($theme) { | ||
@include mat-using-mdc-theme($theme) { | ||
// TODO: implement MDC-based tooltip. | ||
} | ||
} | ||
|
||
@mixin mat-tooltip-typography-mdc($config) { | ||
@include mat-using-mdc-typography($config) { | ||
// TODO: implement MDC-based tooltip. | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @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} from '@angular/cdk-experimental/testing'; | ||
|
||
|
||
/** | ||
* Harness for interacting with a MDC-based mat-tooltip in tests. | ||
* @dynamic | ||
*/ | ||
export class MatTooltipHarness extends ComponentHarness { | ||
// TODO: implement once MDC tooltip is done. | ||
} |
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.io/license | ||
*/ | ||
|
||
export type TooltipHarnessFilters = { | ||
id?: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import {HarnessLoader} from '@angular/cdk-experimental/testing'; | ||
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed'; | ||
import {Component} from '@angular/core'; | ||
import {ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {MatTooltipModule} from '@angular/material/tooltip'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
import {MatTooltipModule as MatMdcTooltipModule} from '../index'; | ||
import {MatTooltipHarness} from './tooltip-harness'; | ||
import {MatTooltipHarness as MatMdcTooltipHarness} from './mdc-tooltip-harness'; | ||
|
||
let fixture: ComponentFixture<TooltipHarnessTest>; | ||
let loader: HarnessLoader; | ||
let harness: typeof MatTooltipHarness; | ||
|
||
describe('MatTooltipHarness', () => { | ||
describe('non-MDC-based', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MatTooltipModule, NoopAnimationsModule], | ||
declarations: [TooltipHarnessTest], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TooltipHarnessTest); | ||
fixture.detectChanges(); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
harness = MatTooltipHarness; | ||
}); | ||
|
||
runTests(); | ||
}); | ||
|
||
describe('MDC-based', () => { | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [MatMdcTooltipModule, NoopAnimationsModule], | ||
declarations: [TooltipHarnessTest], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TooltipHarnessTest); | ||
fixture.detectChanges(); | ||
loader = TestbedHarnessEnvironment.loader(fixture); | ||
// Public APIs are the same as MatTooltipHarness, but cast | ||
// is necessary because of different private fields. | ||
harness = MatMdcTooltipHarness as any; | ||
}); | ||
|
||
// TODO: enable after MDC tooltip is implemented | ||
// runTests(); | ||
}); | ||
}); | ||
|
||
/** Shared tests to run on both the original and MDC-based tooltip. */ | ||
function runTests() { | ||
it('should load all tooltip harnesses', async () => { | ||
const tooltips = await loader.getAllHarnesses(harness); | ||
expect(tooltips.length).toBe(2); | ||
}); | ||
|
||
it('should be able to open a tooltip', async () => { | ||
const tooltip = await loader.getHarness(harness.with({id: 'one'})); | ||
expect(await tooltip.isOpen()).toBe(false); | ||
await tooltip.open(); | ||
expect(await tooltip.isOpen()).toBe(true); | ||
}); | ||
|
||
// TODO(crisbeto): this fails because we have a setTimeout inside the tooltip which | ||
// can't be flushed. Talk to Miles about how we should approach this in harnesses. | ||
// it('should be able to close a tooltip', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mmalerba In the tooltip's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had something like this: function wait(time: number) {
return new Promise(resolve => {
setTimeout(resolve, time);
});
} Then I had |
||
// const tooltip = await loader.getHarness(harness.with({id: 'one'})); | ||
// expect(await tooltip.isOpen()).toBe(false); | ||
// await tooltip.open(); | ||
// expect(await tooltip.isOpen()).toBe(true); | ||
// await tooltip.close(); | ||
// expect(await tooltip.isOpen()).toBe(false); | ||
// }); | ||
|
||
it('should be able to get the text of a tooltip', async () => { | ||
const tooltip = await loader.getHarness(harness.with({id: 'one'})); | ||
await tooltip.open(); | ||
expect(await tooltip.getTooltipText()).toBe('Tooltip message'); | ||
}); | ||
|
||
it('should return empty when getting the tooltip text while closed', async () => { | ||
const tooltip = await loader.getHarness(harness.with({id: 'one'})); | ||
expect(await tooltip.getTooltipText()).toBe(''); | ||
}); | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<button [matTooltip]="message" id="one">Trigger 1</button> | ||
<button matTooltip="Static message" id="two">Trigger 2</button> | ||
` | ||
}) | ||
class TooltipHarnessTest { | ||
message = 'Tooltip message'; | ||
} | ||
|
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.
triggerId
?