-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathFileBodyView.stories.tsx
More file actions
156 lines (138 loc) · 4.32 KB
/
FileBodyView.stories.tsx
File metadata and controls
156 lines (138 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import React, { type ReactNode } from "react";
import { expect, userEvent, within } from "storybook/test";
import type { Meta, StoryObj } from "@storybook/react-vite";
import {
FileBodyView,
FileBodyViewInfoIcon,
FileBodyViewState,
type FileBodyViewActions,
type FileBodyViewSnapshot,
} from "./FileBodyView";
import { useMockedViewModel } from "../../../../../core/viewmodel/useMockedViewModel";
import { withViewDocs } from "../../../../../../.storybook/withViewDocs";
type FileBodyViewProps = FileBodyViewSnapshot & FileBodyViewActions;
const FileBodyViewWrapperImpl = ({
onInfoClick,
onDownloadClick,
onDownloadLinkClick,
onDownloadIframeLoad,
className,
...snapshotProps
}: FileBodyViewProps & { className?: string }): ReactNode => {
const vm = useMockedViewModel(snapshotProps, {
onInfoClick,
onDownloadClick,
onDownloadLinkClick,
onDownloadIframeLoad,
});
return <FileBodyView vm={vm} className={className} />;
};
const FileBodyViewWrapper = withViewDocs(FileBodyViewWrapperImpl, FileBodyView);
const meta = {
title: "Timeline/Timeline Body/FileBodyView",
component: FileBodyViewWrapper,
tags: ["autodocs"],
argTypes: {
state: {
options: Object.entries(FileBodyViewState)
.filter(([key, value]) => key === value)
.map(([key]) => key),
control: { type: "select" },
},
infoIcon: {
options: Object.entries(FileBodyViewInfoIcon)
.filter(([key, value]) => key === value)
.map(([key]) => key),
control: { type: "select" },
},
showInfo: { control: "boolean" },
showDownload: { control: "boolean" },
className: { control: "text" },
},
args: {
state: FileBodyViewState.UNENCRYPTED,
showInfo: true,
infoLabel: "spec.pdf",
infoTooltip: "spec.pdf (22 KB)",
infoIcon: FileBodyViewInfoIcon.ATTACHMENT,
infoHref: "https://example.org/spec.pdf",
showDownload: true,
downloadLabel: "Download file",
downloadTitle: "Download title",
downloadHref: "https://example.org/download/spec.pdf",
className: undefined,
},
} satisfies Meta<typeof FileBodyViewWrapper>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {};
export const Export: Story = {
args: {
state: FileBodyViewState.EXPORT,
},
};
export const Invalid: Story = {
args: {
state: FileBodyViewState.INVALID,
},
};
export const LongFilenameInfo: Story = {
args: {
showDownload: false,
infoLabel: "a very long filename to show ellipsis.pdf",
infoTooltip: "a very long filename to show ellipsis.pdf (12 kB)",
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.hover(canvas.getByText("a very long filename to show ellipsis.pdf"));
await expect(
within(canvasElement.ownerDocument.body).findByText("a very long filename to show ellipsis.pdf (12 kB)"),
).resolves.toBeInTheDocument();
},
};
export const AudioInfo: Story = {
args: {
showDownload: false,
infoIcon: FileBodyViewInfoIcon.AUDIO,
infoLabel: "voice-message.ogg",
},
};
export const VideoInfo: Story = {
args: {
showDownload: false,
infoIcon: FileBodyViewInfoIcon.VIDEO,
infoLabel: "clip.mp4",
},
};
export const UnencryptedDownload: Story = {
args: {
state: FileBodyViewState.UNENCRYPTED,
showInfo: false,
},
};
export const EncryptedIframeDownload: Story = {
args: {
state: FileBodyViewState.ENCRYPTED,
showInfo: false,
},
};
export const DecryptionPendingDownload: Story = {
args: {
state: FileBodyViewState.DECRYPTION_PENDING,
showInfo: false,
},
};
export const LongFilenameDownload: Story = {
args: {
state: FileBodyViewState.UNENCRYPTED,
showInfo: false,
showDownload: true,
downloadLabel: "a very long filename that show no ellipsis.pdf",
},
};