-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathDateSeparatorView.stories.tsx
More file actions
92 lines (81 loc) · 3.2 KB
/
DateSeparatorView.stories.tsx
File metadata and controls
92 lines (81 loc) · 3.2 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
/*
* 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 JSX } from "react";
import { expect, userEvent, within } from "storybook/test";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { DateSeparatorView, type DateSeparatorViewSnapshot, type DateSeparatorViewActions } from "./DateSeparatorView";
import { useMockedViewModel } from "../../../core/viewmodel/useMockedViewModel";
import { withViewDocs } from "../../../../.storybook/withViewDocs";
type DateSeparatorProps = DateSeparatorViewSnapshot & DateSeparatorViewActions;
const DateSeparatorViewWrapperImpl = ({
onLastWeekPicked,
onLastMonthPicked,
onBeginningPicked,
onDatePicked,
className,
...rest
}: DateSeparatorProps & { className?: string }): JSX.Element => {
const vm = useMockedViewModel(rest, { onLastWeekPicked, onLastMonthPicked, onBeginningPicked, onDatePicked });
return <DateSeparatorView vm={vm} className={className} />;
};
const DateSeparatorViewWrapper = withViewDocs(DateSeparatorViewWrapperImpl, DateSeparatorView);
const meta = {
title: "Timeline/Timeline Meta/DateSeparatorView",
component: DateSeparatorViewWrapper,
tags: ["autodocs"],
argTypes: {
jumpToEnabled: { control: "boolean" },
jumpFromDate: { control: "text" },
className: { control: "text" },
},
args: {
label: "Today",
},
} satisfies Meta<typeof DateSeparatorViewWrapper>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {};
export const HasExtraClassNames: Story = {
args: {
className: "extra_class_1 extra_class_2",
},
};
export const WithJumpToTooltip: Story = {
args: {
jumpToEnabled: true,
jumpFromDate: "2025-01-15",
onLastWeekPicked: () => console.log("onLastWeekPicked"),
onLastMonthPicked: () => console.log("onLastMonthPicked"),
onBeginningPicked: () => console.log("onBeginningPicked"),
onDatePicked: () => console.log("onDatePicked"),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.hover(canvas.getByText("Today"));
await expect(within(canvasElement.ownerDocument.body).findByRole("tooltip")).resolves.toBeInTheDocument();
},
};
export const WithJumpToDatePicker: Story = {
args: {
jumpToEnabled: true,
jumpFromDate: "2025-01-15",
onLastWeekPicked: () => console.log("onLastWeekPicked"),
onLastMonthPicked: () => console.log("onLastMonthPicked"),
onBeginningPicked: () => console.log("onBeginningPicked"),
onDatePicked: () => console.log("onDatePicked"),
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.click(canvas.getByText("Today"));
await expect(within(canvasElement.ownerDocument.body).findByText("Jump to date")).resolves.toBeInTheDocument();
},
};
export const LongLocalizedLabel: Story = {
args: {
label: "Wednesday, December 17, 2025 at 11:59 PM Coordinated Universal Time",
},
};