Skip to content

Commit

Permalink
chore: updated tooltip test
Browse files Browse the repository at this point in the history
  • Loading branch information
agliga committed Oct 31, 2024
1 parent 93ac6a2 commit 86d24f8
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions src/components/ebay-tooltip/test/test.browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
import { afterEach, beforeEach, describe, it, expect } from "vitest";
import { composeStories } from "@storybook/marko";
import { render, fireEvent, cleanup, waitFor } from "@marko/testing-library";
import * as stories from "../tooltip.stories";
Expand All @@ -12,16 +12,11 @@ let component;

const renderBodyText = "View options";

describe("given the default tooltip", () => {
describe("default tooltip", () => {
beforeEach(async () => {
vi.useFakeTimers();
component = await render(Standard);
});

afterEach(() => {
vi.useRealTimers();
});

describe("when the host element is hovered", () => {
beforeEach(async () => {
await fireEvent.mouseEnter(component.getByText(renderBodyText));
Expand All @@ -33,32 +28,46 @@ describe("given the default tooltip", () => {
);
});

describe("when the host element loses hover", () => {
describe("when the escape key is pressed", () => {
it("then it emits the collapse event", async () => {
await fireEvent.mouseLeave(
component.getByText(renderBodyText).parentElement,
);
await fireEvent.keyDown(document, {
key: "Escape",
keyCode: 27,
});

await vi.advanceTimersByTimeAsync(500);
await waitFor(
() => expect(component.emitted("collapse")).has.length(1),
2000,
await waitFor(() =>
expect(component.emitted("collapse")).has.length(1),
);
});
});
});
});

describe("when the escape key is pressed", () => {
describe("default tooltip", () => {
beforeEach(async () => {
component = await render(Standard);
});

describe("when the host element is hovered", () => {
beforeEach(async () => {
await fireEvent.focus(component.getByText(renderBodyText));
});

it("then it emits the expand event", async () => {
await waitFor(() =>
expect(component.emitted("expand")).has.length(1),
);
});

describe("when it loses focus", () => {
it("then it emits the collapse event", async () => {
await fireEvent.keyDown(
await fireEvent.mouseLeave(
component.getByText(renderBodyText).parentElement,
{
key: "Escape",
keyCode: 27,
},
);

await waitFor(() =>
expect(component.emitted("collapse")).has.length(1),
await waitFor(
() => expect(component.emitted("collapse")).has.length(1),

Check failure on line 69 in src/components/ebay-tooltip/test/test.browser.js

View workflow job for this annotation

GitHub Actions / build

src/components/ebay-tooltip/test/test.browser.js > default tooltip > when the host element is hovered > when it loses focus > then it emits the collapse event

AssertionError: expected [] to have a length of 1 but got +0 Ignored nodes: comments, script, style <html lang="en" > <head> <meta charset="UTF-8" /> <link href="/__vitest__/favicon.svg" rel="icon" type="image/svg+xml" /> <meta content="width=device-width, initial-scale=1.0" name="viewport" /> <title> Vitest Browser Tester </title> <link crossorigin="" href="/__vitest_browser__/utils-CUwLt_eT.js" rel="modulepreload" /> </head> <body> <div> <span> <span> <span class="tooltip tooltip--expanded" id="nid-nli-3" > <a aria-controls="c0-overlay" aria-describedby="c0-overlay" aria-expanded="true" class="tooltip__host" href="https://www.ebay.com" > View options </a> <span class="tooltip__overlay" id="c0-overlay" role="tooltip" style="left: 0px; top: 23px;" > <span class="tooltip__pointer" style="left: 38.1953px; top: -4px;" /> <span class="tooltip__mask" > <span class="tooltip__cell" > <span class="tooltip__content" > <p> Use Access Key 'S' to display settings. </p> </span> </span> </span> </span> </span> </span> </span> </div> </body> </html>... - Expected + Received - 1 + 0 ❯ waitFor.timeout src/components/ebay-tooltip/test/test.browser.js:69:68
{ timeout: 2000 },
);
});
});
Expand Down

0 comments on commit 86d24f8

Please sign in to comment.