Skip to content

Commit

Permalink
moving mocks to a central area
Browse files Browse the repository at this point in the history
  • Loading branch information
devinvillarosa committed Jan 2, 2025
1 parent 38b8c11 commit 7b1e792
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 252 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
createFakeGlobalConcurrencyLimit,
reactQueryDecorator,
} from "@/storybook/utils";
import { createFakeGlobalConcurrencyLimit } from "@/mocks";
import { reactQueryDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { GlobalConcurrencyLimitsCreateOrEditDialog } from "./global-concurrency-limits-create-or-edit-dialog";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
createFakeGlobalConcurrencyLimit,
reactQueryDecorator,
toastDecorator,
} from "@/storybook/utils";
import { createFakeGlobalConcurrencyLimit } from "@/mocks";
import { reactQueryDecorator, toastDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { Table as GlobalConcurrencyLimitsDataTable } from "./global-concurrency-limits-data-table";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
createFakeGlobalConcurrencyLimit,
reactQueryDecorator,
} from "@/storybook/utils";
import { createFakeGlobalConcurrencyLimit } from "@/mocks";
import { reactQueryDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { GlobalConcurrencyLimitsDeleteDialog } from "./global-concurrency-limits-delete-dialog";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { createFakeFlow, createFakeFlowRun, createFakeTaskRun } from "@/mocks";
import { routerDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";

import {
createFakeFlow,
createFakeFlowRun,
createFakeTaskRun,
routerDecorator,
} from "@/storybook/utils";

import { TaskRunConcurrencyLimitActiveTaskRuns } from "./task-run-concurrency-limit-active-task-runs";

const MOCK_DATA = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createFakeTaskRunConcurrencyLimit } from "@/storybook/utils";
import { createFakeTaskRunConcurrencyLimit } from "@/mocks";
import type { Meta, StoryObj } from "@storybook/react";

import { TaskRunConcurrencyLimitDetails } from "./task-run-concurrency-limit-details";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
createFakeTaskRunConcurrencyLimit,
routerDecorator,
toastDecorator,
} from "@/storybook/utils";
import { createFakeTaskRunConcurrencyLimit } from "@/mocks";
import { routerDecorator, toastDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";

import { fn } from "@storybook/test";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import {
createFakeTaskRunConcurrencyLimit,
routerDecorator,
toastDecorator,
} from "@/storybook/utils";
import { createFakeTaskRunConcurrencyLimit } from "@/mocks";
import { routerDecorator, toastDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { Table as TaskRunConcurrencyLimitsDataTable } from "./task-run-concurrency-limits-data-table";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
createFakeTaskRunConcurrencyLimit,
reactQueryDecorator,
} from "@/storybook/utils";
import { createFakeTaskRunConcurrencyLimit } from "@/mocks";
import { reactQueryDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { TaskRunConcurrencyLimitsDeleteDialog } from "./task-run-concurrency-limits-delete-dialog";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
createFakeTaskRunConcurrencyLimit,
reactQueryDecorator,
} from "@/storybook/utils";
import { createFakeTaskRunConcurrencyLimit } from "@/mocks";
import { reactQueryDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";
import { fn } from "@storybook/test";
import { TaskRunConcurrencyLimitsResetDialog } from "./task-run-concurrency-limits-reset-dialog";
Expand Down
10 changes: 2 additions & 8 deletions ui-v2/src/components/ui/run-card/run-card.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { createFakeFlow, createFakeFlowRun, createFakeTaskRun } from "@/mocks";
import { routerDecorator } from "@/storybook/utils";
import type { Meta, StoryObj } from "@storybook/react";

import {
createFakeFlow,
createFakeFlowRun,
createFakeTaskRun,
routerDecorator,
} from "@/storybook/utils";

import { RunCard } from "./run-card";

const meta: Meta<typeof RunCard> = {
Expand Down
52 changes: 15 additions & 37 deletions ui-v2/src/hooks/global-concurrency-limits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createWrapper, server } from "@tests/utils";
import { http, HttpResponse } from "msw";
import { describe, expect, it } from "vitest";

import { createFakeGlobalConcurrencyLimit } from "@/mocks";
import {
type GlobalConcurrencyLimit,
queryKeyFactory,
Expand All @@ -14,18 +15,10 @@ import {
} from "./global-concurrency-limits";

describe("global concurrency limits hooks", () => {
const seedGlobalConcurrencyLimits = () => [
{
id: "0",
created: "2021-01-01T00:00:00Z",
updated: "2021-01-01T00:00:00Z",
active: false,
name: "global concurrency limit 0",
limit: 0,
active_slots: 0,
slot_decay_per_second: 0,
},
];
const MOCK_DATA = createFakeGlobalConcurrencyLimit({
id: "0",
});
const seedData = () => [MOCK_DATA];

const mockFetchGlobalConcurrencyLimitsAPI = (
globalConcurrencyLimits: Array<GlobalConcurrencyLimit>,
Expand All @@ -50,7 +43,7 @@ describe("global concurrency limits hooks", () => {
*/
it("is stores list data into the appropriate list query when using useQuery()", async () => {
// ------------ Mock API requests when cache is empty
const mockList = seedGlobalConcurrencyLimits();
const mockList = seedData();
mockFetchGlobalConcurrencyLimitsAPI(mockList);

// ------------ Initialize hooks to test
Expand All @@ -73,16 +66,11 @@ describe("global concurrency limits hooks", () => {
const queryClient = new QueryClient();

// ------------ Mock API requests after queries are invalidated
const mockData = seedGlobalConcurrencyLimits().filter(
(limit) => limit.id !== ID_TO_DELETE,
);
const mockData = seedData().filter((limit) => limit.id !== ID_TO_DELETE);
mockFetchGlobalConcurrencyLimitsAPI(mockData);

// ------------ Initialize cache
queryClient.setQueryData(
queryKeyFactory.list(filter),
seedGlobalConcurrencyLimits(),
);
queryClient.setQueryData(queryKeyFactory.list(filter), seedData());

// ------------ Initialize hooks to test
const { result: useListGlobalConcurrencyLimitsResult } = renderHook(
Expand Down Expand Up @@ -129,23 +117,16 @@ describe("global concurrency limits hooks", () => {
};

// ------------ Mock API requests after queries are invalidated
const NEW_LIMIT_DATA = {
...MOCK_NEW_LIMIT,
const NEW_LIMIT_DATA = createFakeGlobalConcurrencyLimit({
id: MOCK_NEW_LIMIT_ID,
created: "2021-01-01T00:00:00Z",
updated: "2021-01-01T00:00:00Z",
active_slots: 0,
slot_decay_per_second: 0,
};
...MOCK_NEW_LIMIT,
});

const mockData = [...seedGlobalConcurrencyLimits(), NEW_LIMIT_DATA];
const mockData = [...seedData(), NEW_LIMIT_DATA];
mockFetchGlobalConcurrencyLimitsAPI(mockData);

// ------------ Initialize cache
queryClient.setQueryData(
queryKeyFactory.list(filter),
seedGlobalConcurrencyLimits(),
);
queryClient.setQueryData(queryKeyFactory.list(filter), seedData());

// ------------ Initialize hooks to test
const { result: useListGlobalConcurrencyLimitsResult } = renderHook(
Expand Down Expand Up @@ -201,17 +182,14 @@ describe("global concurrency limits hooks", () => {
};

// ------------ Mock API requests after queries are invalidated
const mockData = seedGlobalConcurrencyLimits().map((limit) =>
const mockData = seedData().map((limit) =>
limit.id === MOCK_UPDATE_LIMIT_ID ? UPDATED_LIMIT : limit,
);
mockFetchGlobalConcurrencyLimitsAPI(mockData);

// ------------ Initialize cache

queryClient.setQueryData(
queryKeyFactory.list(filter),
seedGlobalConcurrencyLimits(),
);
queryClient.setQueryData(queryKeyFactory.list(filter), seedData());

// ------------ Initialize hooks to test
const { result: useListGlobalConcurrencyLimitsResult } = renderHook(
Expand Down
Loading

0 comments on commit 7b1e792

Please sign in to comment.