Skip to content

Commit

Permalink
Refactors src/addons fixtures and handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
allanlasser committed Mar 26, 2024
1 parent 4c4fac6 commit c700308
Show file tree
Hide file tree
Showing 42 changed files with 3,298 additions and 3,844 deletions.
11 changes: 1 addition & 10 deletions src/addons/browser/AddOnList.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<script lang="ts" context="module">
import type { AddOnListItem } from "../types.ts";
export interface AddOnList {
items?: AddOnListItem[];
loading: boolean;
error?: string | null;
}
</script>

<script lang="ts">
import { _ } from "svelte-i18n";
import Button from "../../common/Button.svelte";
Expand All @@ -16,6 +6,7 @@
import Loader from "../../common/Loader.svelte";
import ListItem from "./AddOnListItem.svelte";
import { AddOnListItem } from "../types";
export let items: AddOnListItem[];
export let loading: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/addons/browser/stories/AddOnList.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="ts" context="module">
import { Story, Template } from "@storybook/addon-svelte-csf";
import defaultAddons from "../../fixtures/addons.json";
import { addonsList } from "../../../test/fixtures/addons";
import AddOnList from "../AddOnList.svelte";
const args = {
items: defaultAddons,
items: addonsList.results,
loading: false,
error: null,
};
Expand Down
2 changes: 1 addition & 1 deletion src/addons/browser/stories/Browser.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Browser from "../Browser.svelte";
const args = { visible: true };
import { addons } from "./mockData";
import { addons } from "../../../test/handlers/addons";
export const meta = {
title: "Add-Ons / Browser",
Expand Down
21 changes: 0 additions & 21 deletions src/addons/browser/stories/mockData.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/addons/dispatch/Dispatch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import { onMount, tick } from "svelte";
import { _ } from "svelte-i18n";
import type { AddOnListItem } from "../types.ts";
import type { Event } from "../runs/ScheduledEvent.svelte";
import type { AddOnListItem, Event } from "../types.ts";
import Button from "../../common/Button.svelte";
import Drawer from "../../common/Drawer.svelte";
Expand Down
9 changes: 2 additions & 7 deletions src/addons/dispatch/Form.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<script context="module" lang="ts">
import type { Event } from "../runs/ScheduledEvent.svelte";
import { writable } from "svelte/store";
export const values = writable({ event: "disabled", selection: null });
export interface eventOptions {
name: string;
events: string[];
}
</script>

<script lang="ts">
Expand All @@ -16,11 +10,12 @@
import { _ } from "svelte-i18n";
import { autofield } from "./fields/index.js";
import type { Event, EventOptions } from "../types";
import Button from "../../common/Button.svelte";
export let properties: any = {};
export let required = [];
export let eventOptions: eventOptions;
export let eventOptions: EventOptions;
export let event: Event = null;
const ajv = new Ajv();
Expand Down
4 changes: 2 additions & 2 deletions src/addons/dispatch/ScheduledInset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { _ } from "svelte-i18n";
import { onMount } from "svelte";
import type { AddOnListItem } from "../types.ts";
import ScheduledEvent, { type Event } from "../runs/ScheduledEvent.svelte";
import type { AddOnListItem, Event } from "../types.ts";
import ScheduledEvent from "../runs/ScheduledEvent.svelte";
import { baseApiUrl } from "../../api/base.js";
Expand Down
57 changes: 15 additions & 42 deletions src/addons/dispatch/stories/Dispatch.stories.svelte
Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
<script lang="ts" context="module">
import { rest } from "msw";
import { Story, Template } from "@storybook/addon-svelte-csf";
import Dispatch from "../Dispatch.svelte";
import addons from "../../fixtures/addons.json";
import * as eventFixture from "../../fixtures/event.json";
import { baseApiUrl } from "../../../api/base";
import {
addonsList,
event as eventFixture,
scheduled as klaxon,
} from "../../../test/fixtures/addons";
import { schedule, send, pin } from "../../../test/handlers/addons";
const { addon: klaxon, ...event } = eventFixture;
const mockScheduleUrl = new URL(
"/api/addon_events/:event",
baseApiUrl,
).toString();
const scheduleSuccess = rest.all(mockScheduleUrl, (req, res, ctx) =>
res(ctx.json({})),
);
const scheduleLoading = rest.all(mockScheduleUrl, (req, res, ctx) =>
res(ctx.delay("infinite")),
);
const scheduleError = rest.all(mockScheduleUrl, (req, res, ctx) =>
res(ctx.status(400, "Something went wrong")),
);
const mockSendUrl = new URL("/api/addon_runs/", baseApiUrl).toString();
const sendSuccess = rest.all(mockSendUrl, (req, res, ctx) =>
res(ctx.json({})),
);
const sendLoading = rest.all(mockSendUrl, (req, res, ctx) =>
res(ctx.delay("infinite")),
);
const sendError = rest.all(mockSendUrl, (req, res, ctx) =>
res(ctx.status(400, "Something went wrong")),
);
const mockPinUrl = new URL("/api/addons/:id", baseApiUrl).toString();
const pinSuccess = rest.all(mockPinUrl, (req, res, ctx) => res(ctx.json({})));
const pinLoading = rest.all(mockPinUrl, (req, res, ctx) =>
res(ctx.delay("infinite")),
);
const pinError = rest.all(mockPinUrl, (req, res, ctx) =>
res(ctx.status(400, "Something went wrong")),
);
const { addon: scheduled, ...event } = eventFixture;
const addons = addonsList.results;
let args = {
visible: true,
Expand All @@ -63,17 +32,21 @@
<Story
name="Success"
args={{ visible: true, addon: klaxon, event }}
parameters={{ msw: { handlers: [scheduleSuccess, sendSuccess, pinSuccess] } }}
parameters={{
msw: { handlers: [schedule.success, send.success, pin.success] },
}}
/>
<Story
name="Error"
args={{ visible: true, addon: klaxon, event }}
parameters={{ msw: { handlers: [scheduleError, sendError, pinError] } }}
parameters={{ msw: { handlers: [schedule.error, send.error, pin.error] } }}
/>
<Story
name="Loading"
args={{ visible: true, addon: klaxon, event }}
parameters={{ msw: { handlers: [scheduleLoading, sendLoading, pinLoading] } }}
parameters={{
msw: { handlers: [schedule.loading, send.loading, pin.loading] },
}}
/>

<Story name="Klaxon" args={{ visible: true, addon: klaxon, event }} />
Expand Down
4 changes: 3 additions & 1 deletion src/addons/dispatch/stories/Form.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import Form, { values } from "../Form.svelte";
import * as addons from "../../fixtures/addons.json";
import { addonsList } from "../../../test/fixtures/addons";
const addons = addonsList.results;
export const meta = {
title: "Add-Ons / Dispatch / Form",
Expand Down
4 changes: 3 additions & 1 deletion src/addons/dispatch/stories/Header.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import Header from "../Header.svelte";
import * as addons from "../../fixtures/addons.json";
import { addonsList } from "../../../test/fixtures/addons";
const addons = addonsList.results;
export const meta = {
title: "Add-Ons / Dispatch / Header",
Expand Down
4 changes: 3 additions & 1 deletion src/addons/dispatch/stories/Premium.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import Premium from "../Premium.svelte";
import addons from "../../fixtures/addons.json";
import { addonsList } from "../../../test/fixtures/addons";
const addons = addonsList.results;
const individualOrg = {
id: 4,
Expand Down
3 changes: 1 addition & 2 deletions src/addons/dispatch/stories/ScheduledInset.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Story, Template } from "@storybook/addon-svelte-csf";
import ScheduledInset from "../ScheduledInset.svelte";
import addon from "../../fixtures/addon.json";
import klaxon from "../../fixtures/klaxon-scheduled.json";
import { addon, scheduled as klaxon } from "../../../test/fixtures/addons";
export const meta = {
title: "Add-Ons / Dispatch / Scheduled Inset",
Expand Down
Loading

0 comments on commit c700308

Please sign in to comment.