Skip to content

Commit

Permalink
refactor: create a common resource to store debounce consts
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijbet committed Jul 22, 2024
1 parent bacbd2e commit f97ca1f
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
t9n,
} from "../../tests/commonTests";
import { getFocusedElementProp } from "../../tests/utils";
import { overflowActionsDebounceInMs, overflowActionsDebounceInMsExtended } from "../../utils/debounceValues";
import { CSS, SLOTS } from "./resources";
import { overflowActionsDebounceInMs } from "./utils";

describe("calcite-action-bar", () => {
describe("renders", () => {
Expand Down Expand Up @@ -423,7 +423,7 @@ describe("calcite-action-bar", () => {
<calcite-action text="Table" icon="table"></calcite-action>`,
);
});
await page.waitForTimeout(overflowActionsDebounceInMs + 10);
await page.waitForTimeout(overflowActionsDebounceInMsExtended);
await page.waitForChanges();

expect(await page.findAll(dynamicGroupActionsSelector)).toHaveLength(8);
Expand Down Expand Up @@ -454,15 +454,15 @@ describe("calcite-action-bar", () => {
</div>`,
);
await page.waitForChanges();
await page.waitForTimeout(overflowActionsDebounceInMs + 10);
await page.waitForTimeout(overflowActionsDebounceInMsExtended);

expect(await page.findAll(dynamicGroupActionsSelector)).toHaveLength(8);
expect(await page.findAll(slottedActionsSelector)).toHaveLength(0);

const actionBar = await page.find("calcite-action-bar");
actionBar.setProperty("overflowActionsDisabled", false);
await page.waitForChanges();
await page.waitForTimeout(overflowActionsDebounceInMs + 10);
await page.waitForTimeout(overflowActionsDebounceInMsExtended);

expect(await page.findAll(dynamicGroupActionsSelector)).toHaveLength(8);
expect(await page.findAll(slottedActionsSelector)).toHaveLength(7);
Expand Down Expand Up @@ -490,7 +490,7 @@ describe("calcite-action-bar", () => {
</calcite-action-bar>
</div>`,
});
await page.waitForTimeout(overflowActionsDebounceInMs + 10);
await page.waitForTimeout(overflowActionsDebounceInMsExtended);

expect(await page.findAll(dynamicGroupActionsSelector)).toHaveLength(8);
expect(await page.findAll(slottedActionsSelector)).toHaveLength(7);
Expand All @@ -499,7 +499,7 @@ describe("calcite-action-bar", () => {
element.style.height = "550px";
});

await page.waitForTimeout(overflowActionsDebounceInMs + 10);
await page.waitForTimeout(overflowActionsDebounceInMsExtended);
await page.waitForChanges();

expect(await page.findAll(dynamicGroupActionsSelector)).toHaveLength(8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ import {
import { ExpandToggle, toggleChildActionText } from "../functional/ExpandToggle";
import { Layout, Position, Scale } from "../interfaces";
import { OverlayPositioning } from "../../utils/floating-ui";
import { overflowActionsDebounceInMs } from "../../utils/debounceValues";
import { ActionBarMessages } from "./assets/action-bar/t9n";
import { CSS, SLOTS } from "./resources";
import {
geActionDimensions,
getOverflowCount,
overflowActions,
overflowActionsDebounceInMs,
queryActions,
} from "./utils";
import { geActionDimensions, getOverflowCount, overflowActions, queryActions } from "./utils";

/**
* @slot - A slot for adding `calcite-action`s that will appear at the top of the component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SLOTS as ACTION_GROUP_SLOTS } from "../action-group/resources";
import { SLOTS as ACTION_MENU_SLOTS } from "../action-menu/resources";
import { Layout } from "../interfaces";

export const overflowActionsDebounceInMs = 150;
const groupBufferPx = 2;

const getAverage = (arr: number[]) => arr.reduce((p, c) => p + c, 0) / arr.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
import { connectLocalized, disconnectLocalized } from "../../utils/locale";
import { createObserver } from "../../utils/observers";
import { onToggleOpenCloseComponent, OpenCloseComponent } from "../../utils/openCloseComponent";
import { comboboxFilterDebounceInMs } from "../../utils/debounceValues";
import {
connectMessages,
disconnectMessages,
Expand Down Expand Up @@ -1129,7 +1130,7 @@ export class Combobox
if (emit) {
this.calciteComboboxFilterChange.emit();
}
}, 100);
}, comboboxFilterDebounceInMs);
})();

internalComboboxChangeEvent = (): void => {
Expand Down
10 changes: 5 additions & 5 deletions packages/calcite-components/src/components/filter/filter.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { E2EPage, newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, disabled, focusable, hidden, reflects, renders, t9n } from "../../tests/commonTests";
import { CSS as INPUT_CSS } from "../input/resources";
import { DEBOUNCE_TIMEOUT } from "./resources";
import { filterDebounceInMs } from "../../utils/debounceValues";

describe("calcite-filter", () => {
describe("renders", () => {
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("calcite-filter", () => {
it("updates filtered items after filtering", async () => {
const filter = await page.find("calcite-filter");
const filterChangeSpy = await page.spyOnEvent("calciteFilterChange");
await page.waitForTimeout(DEBOUNCE_TIMEOUT);
await page.waitForTimeout(filterDebounceInMs);
await page.waitForChanges();

expect(filterChangeSpy).toHaveReceivedEventTimes(0);
Expand All @@ -215,7 +215,7 @@ describe("calcite-filter", () => {
await page.$eval("calcite-filter", (filter: HTMLCalciteFilterElement): void => {
filter.items = filter.items.slice(3);
});
await page.waitForTimeout(DEBOUNCE_TIMEOUT);
await page.waitForTimeout(filterDebounceInMs);
await page.waitForChanges();

assertMatchingItems(await filter.getProperty("filteredItems"), ["jon"]);
Expand Down Expand Up @@ -274,15 +274,15 @@ describe("calcite-filter", () => {

it("should return matching value", async () => {
const filter = await page.find("calcite-filter");
await page.waitForTimeout(DEBOUNCE_TIMEOUT);
await page.waitForTimeout(filterDebounceInMs);
assertMatchingItems(await filter.getProperty("filteredItems"), ["harry"]);
});

it("should return no matching values", async () => {
const filter = await page.find("calcite-filter");
filter.setProperty("filterProps", ["description"]);
await page.waitForChanges();
await page.waitForTimeout(DEBOUNCE_TIMEOUT);
await page.waitForTimeout(filterDebounceInMs);
assertMatchingItems(await filter.getProperty("filteredItems"), []);
});
});
Expand Down
5 changes: 3 additions & 2 deletions packages/calcite-components/src/components/filter/filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ import {
updateMessages,
} from "../../utils/t9n";
import { Scale } from "../interfaces";
import { filterDebounceInMs } from "../../utils/debounceValues";
import { FilterMessages } from "./assets/filter/t9n";
import { CSS, DEBOUNCE_TIMEOUT, ICONS } from "./resources";
import { CSS, ICONS } from "./resources";

@Component({
tag: "calcite-filter",
Expand Down Expand Up @@ -235,7 +236,7 @@ export class Filter
(value: string, emit = false, onFilter?: () => void): void =>
this.items.length &&
this.updateFiltered(filter(this.items, value, this.filterProps), emit, onFilter),
DEBOUNCE_TIMEOUT,
filterDebounceInMs,
);

inputHandler = (event: CustomEvent): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ export const ICONS = {
search: "search",
close: "x",
} as const;

export const DEBOUNCE_TIMEOUT = 250;
Loading

0 comments on commit f97ca1f

Please sign in to comment.