Add mobile Chromatic tests (#7222)

* Add mobile story tests

* add layout stories

* add changeset

* configure viewports

* formatting

* Remove tablet stories + add plot story

* add changeset

* add mobile tests to layout stories

* fix story

* fix story

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
Co-authored-by: pngwn <hello@pngwn.io>
This commit is contained in:
Hannah 2024-02-02 14:21:48 +00:00 committed by GitHub
parent fdd15213c2
commit 5181957706
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 336 additions and 105 deletions

View File

@ -0,0 +1,7 @@
---
"@gradio/plot": minor
"@gradio/storybook": minor
"gradio": minor
---
feat:Add mobile Chromatic tests

View File

@ -0,0 +1,27 @@
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Accordion from "./Index.svelte";
import Button from "../button/shared/Button.svelte";
import { allModes } from "../storybook/modes";
export const meta = {
title: "Layout Elements/Accordion",
component: Accordion,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<Accordion {...args} label="Open Me!" open={false}>
<Button elem_id="btn" size="lg">test</Button>
</Accordion>
</Template>
<Story name="Accordion Layout" />

View File

@ -1,9 +1,21 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Audio from "./Index.svelte";
</script>
import { allModes } from "../storybook/modes";
<Meta title="Components/Audio" component={Audio} />
export const meta = {
title: "Components/Audio",
component: Audio,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<Audio value="Audio" {...args} />

View File

@ -1,31 +1,40 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Chatbot from "./Index.svelte";
</script>
import { allModes } from "../storybook/modes";
<Meta
title="Components/Chatbot"
component={Chatbot}
argTypes={{
label: {
control: "text",
description: "The textbox label",
name: "label"
export const meta = {
title: "Components/Chatbot",
component: Chatbot,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
},
show_label: {
options: [true, false],
description: "Whether to show the label",
control: { type: "boolean" },
defaultValue: true
},
rtl: {
options: [true, false],
description: "Whether to render right-to-left",
control: { type: "boolean" },
defaultValue: false
argTypes: {
label: {
control: "text",
description: "The textbox label",
name: "label"
},
show_label: {
options: [true, false],
description: "Whether to show the label",
control: { type: "boolean" },
defaultValue: true
},
rtl: {
options: [true, false],
description: "Whether to render right-to-left",
control: { type: "boolean" },
defaultValue: false
}
}
}}
/>
};
</script>
<Template let:args>
<Chatbot

View File

@ -0,0 +1,28 @@
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Column from "./Index.svelte";
import Button from "../button/shared/Button.svelte";
import { allModes } from "../storybook/modes";
export const meta = {
title: "Layout Elements/Column",
component: Column,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<Column {...args}>
<Button elem_id="btn" size="lg">test</Button>
<Button elem_id="btn" size="lg">test</Button>
</Column>
</Template>
<Story name="Column Layout" />

View File

@ -1,68 +1,77 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Gallery from "./Index.svelte";
</script>
import { allModes } from "../storybook/modes";
<Meta
title="Components/Gallery"
component={Gallery}
argTypes={{
label: {
control: "text",
description: "The gallery label",
name: "label",
value: "Gradio Button"
export const meta = {
title: "Components/Gallery",
component: Gallery,
argTypes: {
label: {
control: "text",
description: "The gallery label",
name: "label",
value: "Gradio Button"
},
show_label: {
options: [true, false],
description: "Whether to show the label",
control: { type: "boolean" },
defaultValue: true
},
columns: {
options: [1, 2, 3, 4],
description: "The number of columns to show in grid",
control: { type: "select" },
defaultValue: 2
},
rows: {
options: [1, 2, 3, 4],
description: "The number of rows to show in grid",
control: { type: "select" },
defaultValue: 2
},
height: {
options: ["auto", 500, 600],
description: "The height of the grid",
control: { type: "select" },
defaultValue: "auto"
},
preview: {
options: [true, false],
description: "Whether to start the gallery in preview mode",
control: { type: "boolean" },
defaultValue: true
},
allow_preview: {
options: [true, false],
description: "Whether to allow a preview mode in the gallery",
control: { type: "boolean" },
defaultValue: true
},
object_fit: {
options: ["contain", "cover", "fill", "none", "scale-down"],
description: "How to display each indivial image in the grid",
control: { type: "select" },
defaultValue: "contain"
},
show_share_button: {
options: [true, false],
description: "Whether to show the share button in the gallery",
control: { type: "boolean" },
defaultValue: false
}
},
show_label: {
options: [true, false],
description: "Whether to show the label",
control: { type: "boolean" },
defaultValue: true
},
columns: {
options: [1, 2, 3, 4],
description: "The number of columns to show in grid",
control: { type: "select" },
defaultValue: 2
},
rows: {
options: [1, 2, 3, 4],
description: "The number of rows to show in grid",
control: { type: "select" },
defaultValue: 2
},
height: {
options: ["auto", 500, 600],
description: "The height of the grid",
control: { type: "select" },
defaultValue: "auto"
},
preview: {
options: [true, false],
description: "Whether to start the gallery in preview mode",
control: { type: "boolean" },
defaultValue: true
},
allow_preview: {
options: [true, false],
description: "Whether to allow a preview mode in the gallery",
control: { type: "boolean" },
defaultValue: true
},
object_fit: {
options: ["contain", "cover", "fill", "none", "scale-down"],
description: "How to display each indivial image in the grid",
control: { type: "select" },
defaultValue: "contain"
},
show_share_button: {
options: [true, false],
description: "Whether to show the share button in the gallery",
control: { type: "boolean" },
defaultValue: false
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
}}
/>
};
</script>
<Template let:args>
<Gallery

View File

@ -0,0 +1,28 @@
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Group from "./Index.svelte";
import Button from "../button/shared/Button.svelte";
import { allModes } from "../storybook/modes";
export const meta = {
title: "Layout Elements/Group",
component: Group,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<Group {...args}>
<Button elem_id="btn" size="lg">test</Button>
<Button elem_id="btn" size="lg">test</Button>
</Group>
</Template>
<Story name="Group Layout" />

View File

@ -1,10 +1,22 @@
<script lang="ts">
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import StaticImage from "./Index.svelte";
import { userEvent, within } from "@storybook/testing-library";
</script>
import { allModes } from "../storybook/modes";
<Meta title="Components/Image" component={Image} />
export const meta = {
title: "Components/Image",
component: StaticImage,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<div

View File

@ -1,12 +1,24 @@
<script lang="ts">
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import ImageEditor from "./Index.svelte";
import { format } from "svelte-i18n";
import { get } from "svelte/store";
import { userEvent, within } from "@storybook/testing-library";
</script>
import { allModes } from "../storybook/modes";
<Meta title="Components/Image Editor" component={ImageEditor} />
export const meta = {
title: "Components/Audio",
component: Audio,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<div

View File

@ -0,0 +1,38 @@
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import PlotComponent from "./Index.svelte";
import { allModes } from "../storybook/modes";
import { test_plot } from "./testplot";
export const meta = {
title: "Components/Plot",
component: PlotComponent,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<PlotComponent value="Plot" {...args} />
</Template>
<Story
name="with value"
args={{
value: test_plot,
label: "Plot"
}}
/>
<Story
name="with no value"
args={{
label: "Plot"
}}
/>

4
js/plot/testplot.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,22 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Row from "./Index.svelte";
import Button from "../button/shared/Button.svelte";
</script>
import { allModes } from "../storybook/modes";
<Meta title="Layout Elements/Row" component={Row} />
export const meta = {
title: "Layout Elements/Row",
component: Row,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<Template let:args>
<Row {...args}>

11
js/storybook/modes.js Normal file
View File

@ -0,0 +1,11 @@
export const allModes = {
mobile: {
viewport: "mobile"
},
tablet: {
viewport: "tablet"
},
desktop: {
viewport: "desktop"
}
};

View File

@ -41,6 +41,16 @@ const preview: Preview = {
storySort: {
order: ["Design System", "Components"]
}
},
viewport: {
viewports: {
mobile: { name: "mobile", styles: { width: "320px", height: "400px" } },
tablet: { name: "tablet", styles: { width: "640px", height: "800px" } },
desktop: {
name: "desktop",
styles: { width: "1024px", height: "1000px" }
}
}
}
}
};

View File

@ -1,12 +1,24 @@
<script>
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
<script context="module">
import { Template, Story } from "@storybook/addon-svelte-csf";
import Video from "./Index.svelte";
import { format } from "svelte-i18n";
import { get } from "svelte/store";
import { userEvent, within } from "@storybook/testing-library";
</script>
import { allModes } from "../storybook/modes";
<Meta title="Components/Video" component={Video} />
export const meta = {
title: "Components/Video",
component: Video,
parameters: {
chromatic: {
modes: {
desktop: allModes["desktop"],
mobile: allModes["mobile"]
}
}
}
};
</script>
<div>
<Template let:args>