Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,48 @@ import {
describe,
it,
expect,
vi,
} from "vitest";
import { fastAnimations } from "../../../common/test-utils/browser";
import template from "../index.marko";
import * as mock from "./mock";
import * as scrollTransitionModule from "../utils/scroll-transition";

beforeAll(() => fastAnimations.start());
afterAll(() => fastAnimations.stop());
afterEach(cleanup);

beforeEach(() => {
vi.useFakeTimers({
toFake: [
"setTimeout",
"clearTimeout",
"setImmediate",
"clearImmediate",
"setInterval",
"clearInterval",
"requestAnimationFrame",
"cancelAnimationFrame",
],
shouldAdvanceTime: true,
});

vi.mock("../utils/scroll-transition", { spy: true });

vi.mocked(scrollTransitionModule.scrollTransition).mockImplementation(
(el, to, fn) => {
el.scrollLeft = to;
fn();
return () => {};
},
);
});

afterEach(() => {
vi.clearAllTimers();
vi.resetAllMocks();
});

/** @type import("@marko/testing-library").RenderResult */
let component;

Expand Down Expand Up @@ -650,7 +684,7 @@ describe("given a discrete carousel", () => {
await component.rerender(
Object.assign({}, input, { paused: true }),
);
await new Promise((resolve) => setTimeout(resolve, 600));
vi.advanceTimersByTime(600);
});

it("then it did not emit any updates", () => {
Expand All @@ -666,7 +700,7 @@ describe("given a discrete carousel", () => {
});

it("then the autoplay does not run", async () => {
await new Promise((resolve) => setTimeout(resolve, 600));
vi.advanceTimersByTime(600);
expect(component.emitted("move")).has.length(0);
});

Expand Down Expand Up @@ -711,6 +745,8 @@ function doesNotEventuallyScroll() {
window.removeEventListener("scroll", handleScroll);
reject(err);
}

vi.advanceTimersByTime(400);
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/ebayui-core/src/components/ebay-table/index.marko
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ $ const isLoading = bodyState === "loading";
} else if (sortOrder) {
sortEleAttr = {
type: "button",
tabindex: isLoading ? -1 : null,
disabled: isLoading,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Seller
Expand Down Expand Up @@ -1905,6 +1906,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Item
Expand Down Expand Up @@ -1935,6 +1937,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Status
Expand All @@ -1955,6 +1958,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
List Price
Expand All @@ -1975,6 +1979,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Quantity Available
Expand All @@ -1995,6 +2000,7 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Orders
Expand All @@ -2015,23 +2021,15 @@ exports[`ebay-table > renders with anchors loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Watchers
 
<svg
aria-hidden="true"
class="icon icon--12"
focusable="false"
>
<use
href="#icon-sort-12"
/>
</svg>
</button>
</th>
<th
class="table-cell table-c..."
focusab..."
`;

exports[`ebay-table > renders with columns client side loading 1`] = `
Expand Down Expand Up @@ -2067,6 +2065,7 @@ exports[`ebay-table > renders with columns client side loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
List Price
Expand Down Expand Up @@ -2097,6 +2096,7 @@ exports[`ebay-table > renders with columns client side loading 1`] = `
>
<button
disabled=""
tabindex="-1"
type="button"
>
Quantity Available
Expand Down Expand Up @@ -2229,10 +2229,7 @@ exports[`ebay-table > renders with columns client side loading 1`] = `
class="table-cell table-cell--numeric"
>
45
</td>
<td
class="table-cell"
>[3..."
</td>[39..."
`;

exports[`ebay-table > renders with frozen header 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,44 +77,39 @@ describe("given table with actions with loading", () => {

describe("all interactive elements should be disabled and have tabindex -1", () => {
it("should have all buttons disabled", async () => {
component
.getAllByRole("button", { hidden: true })
.forEach(async (button) => {
await waitFor(() => {
expect(button).toHaveAttribute("disabled", "");
expect(button).toHaveAttribute("tabindex", "-1");
});
});
});
it("should have all links disabled", async () => {
component
.getAllByRole("link", { hidden: true })
.forEach(async (button) => {
await waitFor(() => {
expect(button).toHaveAttribute("disabled", "");
expect(button).toHaveAttribute("tabindex", "-1");
});
for (const button of component.getAllByRole("button", {
hidden: true,
})) {
await waitFor(() => {
expect(button).toHaveAttribute("disabled", "true");
expect(button).toHaveAttribute("tabindex", "-1");
});
}
});
});
it("should have all links disabled", async () => {
for (const button of component.getAllByRole("link", { hidden: true })) {
await waitFor(() => {
expect(button).not.toHaveAttribute("href");
expect(button).toHaveAttribute("tabindex", "-1");
});
}
});
describe("When table is rerendered without loading", () => {
beforeEach(async () => {
await component.rerender({ bodyState: "default" });
});

describe("all interactive elements should be enabled", () => {
it("should have all buttons disabled", async () => {
component
.getAllByRole("button", { hidden: true })
.forEach(async (button) => {
await waitFor(() => {
expect(button).not.toHaveAttribute("disabled", "");
expect(button).not.toHaveAttribute(
"tabindex",
"-1",
);
});
for (const button of component.getAllByRole("button", {
hidden: true,
})) {
await waitFor(() => {
expect(button).not.toHaveAttribute("disabled", "");
expect(button).not.toHaveAttribute("tabindex", "-1");
});
}
});
});
});
Expand All @@ -130,14 +125,14 @@ describe("given table with header actions with loading", () => {

describe("all interactive elements should be disabled and have tabindex -1", () => {
it("should have all buttons disabled", async () => {
component
.getAllByRole("button", { hidden: true })
.forEach(async (button) => {
await waitFor(() => {
expect(button).toHaveAttribute("disabled", "");
expect(button).toHaveAttribute("tabindex", "-1");
});
for (const button of component.getAllByRole("button", {
hidden: true,
})) {
await waitFor(() => {
expect(button).toHaveAttribute("disabled", "");
expect(button).toHaveAttribute("tabindex", "-1");
});
}
});
});
describe("When table is rerendered without loading", () => {
Expand All @@ -147,12 +142,14 @@ describe("given table with header actions with loading", () => {

describe("all interactive elements should be enabled", () => {
it("should have all buttons disabled", async () => {
component.getAllByRole("button").forEach(async (button) => {
for (const button of component.getAllByRole("button", {
hidden: true,
})) {
await waitFor(() => {
expect(button).not.toHaveAttribute("disabled", "");
expect(button).not.toHaveAttribute("tabindex", "-1");
});
});
}
});
});
});
Expand Down
Loading