Skip to content

test(tooltip/testing): disable tests on touch devices #19447

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 1 commit into from
May 26, 2020
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
1 change: 1 addition & 0 deletions src/material/tooltip/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ng_test_library(
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/platform",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/tooltip",
Expand Down
28 changes: 28 additions & 0 deletions src/material/tooltip/testing/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatTooltipHarness} from '@angular/material/tooltip/testing/tooltip-harness';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {Platform} from '@angular/cdk/platform';

/** Shared tests to run on both the original and MDC-based tooltips. */
export function runHarnessTests(
tooltipModule: typeof MatTooltipModule, tooltipHarness: typeof MatTooltipHarness) {
// TODO(COMP-322): whether the current test device is supported by the harness. At the time of
// writing, we have to skip these tests on touch devices, because we don't have a way of
// simulating touch events. This variable should be removed once the issue is resolved.
let isSupported: boolean;
let fixture: ComponentFixture<TooltipHarnessTest>;
let loader: HarnessLoader;

Expand All @@ -21,21 +26,36 @@ export function runHarnessTests(
fixture = TestBed.createComponent(TooltipHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);

const platform = TestBed.inject(Platform);
isSupported = !platform.IOS && !platform.ANDROID;
});

it('should load all tooltip harnesses', async () => {
if (!isSupported) {
return;
}

const tooltips = await loader.getAllHarnesses(tooltipHarness);
expect(tooltips.length).toBe(2);
});

it('should be able to show a tooltip', async () => {
if (!isSupported) {
return;
}

const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
expect(await tooltip.isOpen()).toBe(false);
await tooltip.show();
expect(await tooltip.isOpen()).toBe(true);
});

it('should be able to hide a tooltip', async () => {
if (!isSupported) {
return;
}

const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
expect(await tooltip.isOpen()).toBe(false);
await tooltip.show();
Expand All @@ -45,12 +65,20 @@ export function runHarnessTests(
});

it('should be able to get the text of a tooltip', async () => {
if (!isSupported) {
return;
}

const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
await tooltip.show();
expect(await tooltip.getTooltipText()).toBe('Tooltip message');
});

it('should return empty when getting the tooltip text while closed', async () => {
if (!isSupported) {
return;
}

const tooltip = await loader.getHarness(tooltipHarness.with({selector: '#one'}));
expect(await tooltip.getTooltipText()).toBe('');
});
Expand Down