@estiva-app/ui 0.98.1 → 0.100.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/README.md +4 -2
  2. package/dist/AppProvider.d.ts +6 -3
  3. package/dist/AppProvider.d.ts.map +1 -1
  4. package/dist/ArchiveDialog.d.ts +35 -0
  5. package/dist/ArchiveDialog.d.ts.map +1 -0
  6. package/dist/AttachedCard.d.ts +13 -2
  7. package/dist/AttachedCard.d.ts.map +1 -1
  8. package/dist/Card.d.ts +6 -1
  9. package/dist/Card.d.ts.map +1 -1
  10. package/dist/ChipInput.d.ts +3 -1
  11. package/dist/ChipInput.d.ts.map +1 -1
  12. package/dist/CollapsibleSection.d.ts +27 -2
  13. package/dist/CollapsibleSection.d.ts.map +1 -1
  14. package/dist/CommentBox.d.ts +2 -2
  15. package/dist/CommentBox.d.ts.map +1 -1
  16. package/dist/ConfirmDialog.d.ts +15 -2
  17. package/dist/ConfirmDialog.d.ts.map +1 -1
  18. package/dist/ConversationCard.d.ts +12 -1
  19. package/dist/ConversationCard.d.ts.map +1 -1
  20. package/dist/ConversationLayout.d.ts +20 -5
  21. package/dist/ConversationLayout.d.ts.map +1 -1
  22. package/dist/ConversationMenu.d.ts +5 -1
  23. package/dist/ConversationMenu.d.ts.map +1 -1
  24. package/dist/ConversationPlace.d.ts +17 -0
  25. package/dist/ConversationPlace.d.ts.map +1 -0
  26. package/dist/DocumentEditor.d.ts +38 -0
  27. package/dist/DocumentEditor.d.ts.map +1 -1
  28. package/dist/DocumentField.d.ts +50 -0
  29. package/dist/DocumentField.d.ts.map +1 -0
  30. package/dist/EditableText.d.ts +38 -4
  31. package/dist/EditableText.d.ts.map +1 -1
  32. package/dist/EmptyState.d.ts +10 -5
  33. package/dist/EmptyState.d.ts.map +1 -1
  34. package/dist/FormDialog.d.ts +38 -0
  35. package/dist/FormDialog.d.ts.map +1 -0
  36. package/dist/InlineText.d.ts.map +1 -1
  37. package/dist/Menu.d.ts +11 -3
  38. package/dist/Menu.d.ts.map +1 -1
  39. package/dist/MoveDialog.d.ts +64 -0
  40. package/dist/MoveDialog.d.ts.map +1 -0
  41. package/dist/NavItem.d.ts +9 -2
  42. package/dist/NavItem.d.ts.map +1 -1
  43. package/dist/NavTree.d.ts +16 -3
  44. package/dist/NavTree.d.ts.map +1 -1
  45. package/dist/PinnedComment.d.ts +3 -1
  46. package/dist/PinnedComment.d.ts.map +1 -1
  47. package/dist/ReactionHorizon.d.ts +3 -1
  48. package/dist/ReactionHorizon.d.ts.map +1 -1
  49. package/dist/RepliesRow.d.ts +5 -3
  50. package/dist/RepliesRow.d.ts.map +1 -1
  51. package/dist/ResolveDialog.d.ts +3 -1
  52. package/dist/ResolveDialog.d.ts.map +1 -1
  53. package/dist/SelectionToolbar.d.ts +2 -2
  54. package/dist/Thread.d.ts +6 -3
  55. package/dist/Thread.d.ts.map +1 -1
  56. package/dist/commentBoxFrame.d.ts.map +1 -1
  57. package/dist/conversation.examples.d.ts +4 -1
  58. package/dist/conversation.examples.d.ts.map +1 -1
  59. package/dist/conversationScroll.d.ts +80 -0
  60. package/dist/conversationScroll.d.ts.map +1 -0
  61. package/dist/editor.d.ts +1 -0
  62. package/dist/editor.d.ts.map +1 -1
  63. package/dist/editor.js +228 -69
  64. package/dist/editor.js.map +4 -4
  65. package/dist/eslint/index.js +2 -2
  66. package/dist/eslint/index.js.map +2 -2
  67. package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
  68. package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
  69. package/dist/eslint/no-native-title.d.ts +1 -1
  70. package/dist/eslint/no-native-title.d.ts.map +1 -1
  71. package/dist/formBusy.d.ts +5 -2
  72. package/dist/formBusy.d.ts.map +1 -1
  73. package/dist/index.d.ts +14 -6
  74. package/dist/index.d.ts.map +1 -1
  75. package/dist/index.js +2242 -1471
  76. package/dist/index.js.map +4 -4
  77. package/dist/looks.d.ts +8 -0
  78. package/dist/looks.d.ts.map +1 -1
  79. package/dist/seenOnScreen.d.ts +27 -0
  80. package/dist/seenOnScreen.d.ts.map +1 -0
  81. package/dist/showInConversation.d.ts +31 -0
  82. package/dist/showInConversation.d.ts.map +1 -0
  83. package/dist/threadCard.d.ts +13 -0
  84. package/dist/threadCard.d.ts.map +1 -1
  85. package/package.json +1 -1
  86. package/registry.json +953 -126
  87. package/src/AppProvider.mdx +4 -0
  88. package/src/AppProvider.test.tsx +34 -2
  89. package/src/AppProvider.tsx +17 -6
  90. package/src/ArchiveDialog.mdx +70 -0
  91. package/src/ArchiveDialog.stories.tsx +64 -0
  92. package/src/ArchiveDialog.test.tsx +90 -0
  93. package/src/ArchiveDialog.tsx +70 -0
  94. package/src/AttachedCard.mdx +6 -0
  95. package/src/AttachedCard.stories.tsx +9 -1
  96. package/src/AttachedCard.test.tsx +111 -2
  97. package/src/AttachedCard.tsx +77 -7
  98. package/src/Card.mdx +20 -1
  99. package/src/Card.stories.tsx +20 -0
  100. package/src/Card.test.tsx +87 -1
  101. package/src/Card.tsx +51 -3
  102. package/src/ChipInput.mdx +7 -1
  103. package/src/ChipInput.stories.tsx +9 -0
  104. package/src/ChipInput.test.tsx +42 -0
  105. package/src/ChipInput.tsx +7 -3
  106. package/src/CollapsibleSection.mdx +20 -1
  107. package/src/CollapsibleSection.stories.tsx +19 -1
  108. package/src/CollapsibleSection.test.tsx +85 -2
  109. package/src/CollapsibleSection.tsx +54 -15
  110. package/src/CommentBox.mdx +2 -1
  111. package/src/CommentBox.test.tsx +81 -1
  112. package/src/CommentBox.tsx +32 -11
  113. package/src/ConfirmDialog.mdx +25 -3
  114. package/src/ConfirmDialog.stories.tsx +27 -0
  115. package/src/ConfirmDialog.test.tsx +87 -1
  116. package/src/ConfirmDialog.tsx +39 -8
  117. package/src/ConversationCard.mdx +7 -0
  118. package/src/ConversationCard.states.test.tsx +67 -0
  119. package/src/ConversationCard.stories.tsx +27 -1
  120. package/src/ConversationCard.test.tsx +76 -0
  121. package/src/ConversationCard.tsx +65 -53
  122. package/src/ConversationLayout.mdx +34 -4
  123. package/src/ConversationLayout.scroll.test.tsx +411 -0
  124. package/src/ConversationLayout.stories.tsx +107 -1
  125. package/src/ConversationLayout.test.tsx +133 -0
  126. package/src/ConversationLayout.tsx +141 -16
  127. package/src/ConversationMenu.mdx +3 -0
  128. package/src/ConversationMenu.stories.tsx +12 -0
  129. package/src/ConversationMenu.test.tsx +17 -0
  130. package/src/ConversationMenu.tsx +7 -3
  131. package/src/ConversationPlace.mdx +53 -0
  132. package/src/ConversationPlace.stories.tsx +48 -0
  133. package/src/ConversationPlace.test.tsx +51 -0
  134. package/src/ConversationPlace.tsx +30 -0
  135. package/src/DocumentEditor.mdx +2 -1
  136. package/src/DocumentEditor.tsx +118 -64
  137. package/src/DocumentField.mdx +83 -0
  138. package/src/DocumentField.stories.tsx +110 -0
  139. package/src/DocumentField.test.tsx +281 -0
  140. package/src/DocumentField.tsx +199 -0
  141. package/src/EditableText.buttons.test.tsx +318 -0
  142. package/src/EditableText.mdx +50 -2
  143. package/src/EditableText.stories.tsx +96 -2
  144. package/src/EditableText.tsx +189 -5
  145. package/src/EmptyState.mdx +33 -8
  146. package/src/EmptyState.stories.tsx +26 -1
  147. package/src/EmptyState.test.tsx +63 -2
  148. package/src/EmptyState.tsx +28 -6
  149. package/src/Form.mdx +3 -1
  150. package/src/FormDialog.mdx +78 -0
  151. package/src/FormDialog.stories.tsx +90 -0
  152. package/src/FormDialog.test.tsx +183 -0
  153. package/src/FormDialog.tsx +93 -0
  154. package/src/InlineText.mdx +1 -0
  155. package/src/InlineText.tsx +2 -1
  156. package/src/Menu.test.tsx +80 -0
  157. package/src/Menu.tsx +35 -14
  158. package/src/MenuItem.mdx +12 -0
  159. package/src/MenuItem.stories.tsx +39 -1
  160. package/src/MoveDialog.mdx +85 -0
  161. package/src/MoveDialog.stories.tsx +134 -0
  162. package/src/MoveDialog.test.tsx +239 -0
  163. package/src/MoveDialog.tsx +186 -0
  164. package/src/NavItem.mdx +15 -0
  165. package/src/NavItem.stories.tsx +15 -0
  166. package/src/NavItem.test.tsx +64 -1
  167. package/src/NavItem.tsx +10 -2
  168. package/src/NavTree.mdx +26 -4
  169. package/src/NavTree.stories.tsx +59 -0
  170. package/src/NavTree.test.tsx +232 -2
  171. package/src/NavTree.tsx +93 -43
  172. package/src/PinnedComment.mdx +6 -1
  173. package/src/PinnedComment.stories.tsx +11 -1
  174. package/src/PinnedComment.tsx +15 -2
  175. package/src/ReactionHorizon.mdx +2 -0
  176. package/src/ReactionHorizon.stories.tsx +3 -0
  177. package/src/ReactionHorizon.test.tsx +32 -0
  178. package/src/ReactionHorizon.tsx +28 -11
  179. package/src/RepliesRow.mdx +6 -3
  180. package/src/RepliesRow.stories.tsx +3 -0
  181. package/src/RepliesRow.test.tsx +24 -0
  182. package/src/RepliesRow.tsx +12 -6
  183. package/src/ReplyCard.mdx +8 -0
  184. package/src/ReplyCard.stories.tsx +45 -1
  185. package/src/ResolveDialog.mdx +2 -0
  186. package/src/ResolveDialog.test.tsx +21 -0
  187. package/src/ResolveDialog.tsx +11 -39
  188. package/src/SelectionToolbar.tsx +2 -2
  189. package/src/Textarea.mdx +1 -0
  190. package/src/Thread.mdx +20 -1
  191. package/src/Thread.stories.tsx +94 -3
  192. package/src/Thread.test.tsx +11 -0
  193. package/src/Thread.tsx +56 -12
  194. package/src/commentBoxFrame.tsx +2 -2
  195. package/src/conversation.examples.tsx +10 -2
  196. package/src/conversationScroll.ts +155 -0
  197. package/src/editor.ts +1 -0
  198. package/src/editorSelection.test.tsx +53 -0
  199. package/src/eslint/no-field-outside-a-form.test.ts +4 -0
  200. package/src/eslint/no-field-outside-a-form.ts +2 -2
  201. package/src/eslint/no-native-title.ts +1 -1
  202. package/src/formBusy.ts +5 -2
  203. package/src/index.ts +16 -6
  204. package/src/looks.ts +10 -0
  205. package/src/registry/registry.test.ts +12 -6
  206. package/src/seenOnScreen.test.tsx +241 -0
  207. package/src/seenOnScreen.ts +146 -0
  208. package/src/showInConversation.test.tsx +168 -0
  209. package/src/showInConversation.ts +93 -0
  210. package/src/threadCard.ts +16 -0
  211. package/stories/Choosing.mdx +8 -3
  212. package/tailwind-preset.js +7 -0
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { IconCopy, IconHash, IconPin, IconTrash } from '@tabler/icons-react'
2
+ import { IconArchive, IconCopy, IconHash, IconPin, IconTrash } from '@tabler/icons-react'
3
+ import { userEvent, within } from 'storybook/test'
3
4
  import { Avatar } from './Avatar'
4
5
  import { useRef, useState } from 'react'
5
6
  import { Button } from './Button'
@@ -99,6 +100,43 @@ export const Destructive: Story = {
99
100
  args: { label: 'Delete', destructive: true, leading: <IconTrash size={16} stroke={1.5} className="text-error-default" /> },
100
101
  }
101
102
 
103
+ /** Shown but shut, with why: its words and its icon in the disabled colour, no fill, and the reason under the pointer. The story points at it. */
104
+ export const Shut: Story = {
105
+ name: 'Shut, saying why',
106
+ args: {
107
+ label: 'Archive',
108
+ leading: <IconArchive size={16} stroke={1.5} className="text-text-secondary" />,
109
+ disabledReason: 'Shut for now, and this says why, in the app’s words.',
110
+ },
111
+ play: async ({ canvasElement }) => {
112
+ await userEvent.hover(within(canvasElement).getByRole('button', { name: 'Archive' }))
113
+ },
114
+ }
115
+
116
+ /**
117
+ * Shut in a live menu: the arrow keys still reach it, its reason shows there as under the pointer, and a press runs
118
+ * nothing and leaves the menu open. The story opens the menu and points at the shut row.
119
+ */
120
+ export const ShutInAMenu: Story = {
121
+ name: 'Shut, in a menu',
122
+ parameters: { controls: { disable: true } },
123
+ decorators: [(Story) => <Story />],
124
+ render: () => (
125
+ <div className="flex min-h-[220px] w-full items-start justify-center pt-12">
126
+ <Menu trigger={<Button variant="outlined">Open the menu</Button>}>
127
+ <MenuItem label="Rename" onClick={() => {}} />
128
+ <MenuItem label="Archive" leading={<IconArchive size={16} stroke={1.5} className="text-text-secondary" />} disabledReason="Shut for now, and this says why, in the app’s words." onClick={() => {}} />
129
+ <Divider className="my-1" />
130
+ <MenuItem label="Delete" destructive onClick={() => {}} />
131
+ </Menu>
132
+ </div>
133
+ ),
134
+ play: async ({ canvasElement }) => {
135
+ await userEvent.click(within(canvasElement).getByRole('button', { name: 'Open the menu' }))
136
+ await userEvent.hover(await within(canvasElement.ownerDocument.body).findByRole('menuitem', { name: 'Archive' }))
137
+ },
138
+ }
139
+
102
140
  /** Every shape on one canvas. */
103
141
  export const AllVariants: Story = {
104
142
  parameters: { controls: { disable: true } },
@@ -0,0 +1,85 @@
1
+ import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks'
2
+ import * as MoveDialogStories from './MoveDialog.stories'
3
+
4
+ <Meta of={MoveDialogStories} />
5
+
6
+ # MoveDialog
7
+
8
+ Move a file to another Folder, under another file there, or both: the Folder
9
+ first, then what it goes under, read when the Folder is picked.
10
+
11
+ <Canvas of={MoveDialogStories.Topic} />
12
+
13
+ ## When
14
+
15
+ - Moving any file, from its menu, its row or its Folder. A file that may sit
16
+ under another passes `placesIn`; one that nests under nothing passes none, and
17
+ is asked only for the Folder.
18
+ - A file that may sit at the top of any Folder: `startAtTop`, so the top is
19
+ chosen for the person. Otherwise Move waits for a pick: a preselected place is
20
+ a move nobody chose.
21
+ - A file not listed in exactly one Folder: `from=""`, and no Folder is held
22
+ back. Listed in none; or in two after a move that half-worked, where moving
23
+ into either takes it out of the other, so Move again is the retry. Nothing is
24
+ chosen for the person even so; `startIn` opens it on one.
25
+
26
+ <Canvas of={MoveDialogStories.ListedTwice} />
27
+
28
+ <Canvas of={MoveDialogStories.Project} />
29
+
30
+ ## When not
31
+
32
+ - Renaming, or choosing a Folder for something new → **FormDialog** with a **Select**.
33
+ - One value from a list on a page, not a move → **Select**.
34
+
35
+ ## How
36
+
37
+ ```tsx
38
+ import { MoveDialog } from '@estiva-app/ui'
39
+
40
+ <MoveDialog
41
+ title="Notes"
42
+ description="Everyone who can read it now still can."
43
+ from={folder}
44
+ folders={folders}
45
+ places={placesHere}
46
+ placesIn={(id) => readPlaces(id)}
47
+ startAtTop
48
+ onMove={({ folder, parent }) => move(folder, parent)}
49
+ onClose={close}
50
+ />
51
+ ```
52
+
53
+ - A place is `{ id, path }`: `id` is what it goes under, its address, and `''`
54
+ for the top; `path` is its breadcrumb, drawn as "Brief › Notes".
55
+ - `placesIn` is called once per Folder, when it is picked; a rejection is said as
56
+ the section's empty line, with **Try again**. `places` are the ones in `from`,
57
+ already read; without them the Folder it opens on is read at once.
58
+ - `onMove` gets `{ folder }`, and `parent` too when it nests (`''` for the top).
59
+ Answer `false` to keep it open once you have said why.
60
+ - `folders` undefined while they are read: the list says "Reading…".
61
+ - `heading`, `folderLabel`, `noFolder` and `topLabel` are for your app's words;
62
+ `startIn` opens it on another Folder than the one it is in. An app that
63
+ chooses one for the person holds its `startIn` steady while the dialog is
64
+ open: a refusal that changes where the file is listed must not move it.
65
+ - Pass only the Folders a move can land in: filter `folders` before, by your
66
+ app's own rules (a Folder that cannot take it). A move your app refuses when
67
+ it is made is answered with `false`, said why, and the dialog stays.
68
+
69
+ <Canvas of={MoveDialogStories.FolderUnreadable} />
70
+
71
+ <Canvas of={MoveDialogStories.NowhereHere} />
72
+
73
+ <Canvas of={MoveDialogStories.UnderNone} />
74
+
75
+ ## What it owns
76
+
77
+ | It does | So you never write | Refused when written by hand |
78
+ |---|---|---|
79
+ | Reads a Folder's places when it is picked, once, and says when it could not, with Try again | a read state per Folder, or a retry row | |
80
+ | Offers only moves that do something, and chooses nothing for the person but the top when asked | a filter on the Folders, or a preselection | |
81
+ | Sends on Move, says it is moving, and closes when the move went through | a busy state, or an `if (ok) onClose()` | |
82
+
83
+ ## Props
84
+
85
+ <Controls of={MoveDialogStories.Topic} />
@@ -0,0 +1,134 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { userEvent, within } from 'storybook/test'
3
+ import { MoveDialog, type MovePlace } from './MoveDialog'
4
+
5
+ const FOLDERS = [
6
+ { id: 'hq', name: 'Estiva HQ' },
7
+ { id: 'peek', name: 'Peek' },
8
+ { id: 'steer', name: 'Steer' },
9
+ ]
10
+ const TOP: MovePlace = { id: '', path: [] }
11
+ const PROJECT: MovePlace = { id: '30850:a:folders', path: ['Folders: navigation for the whole suite'] }
12
+ const BRIEF: MovePlace = { id: '30840:a:brief', path: ['Folders: navigation for the whole suite', 'Brief'] }
13
+
14
+ /**
15
+ * Moving a file to another Folder, under another file, or both. The places in
16
+ * its own Folder are the caller's, read before it opens; another Folder's are
17
+ * read when it is picked.
18
+ */
19
+ const meta = {
20
+ title: 'Menus & windows/MoveDialog',
21
+ component: MoveDialog,
22
+ parameters: {
23
+ layout: 'fullscreen',
24
+ docs: { story: { inline: false, height: '560px' } },
25
+ },
26
+ argTypes: { onMove: { control: false }, onClose: { control: false }, placesIn: { control: false } },
27
+ args: {
28
+ title: 'Notes',
29
+ description: 'Everyone who can read it now still can.',
30
+ from: 'hq',
31
+ folders: FOLDERS,
32
+ places: [TOP, PROJECT, BRIEF],
33
+ placesIn: async (): Promise<readonly MovePlace[]> => [TOP, { id: '30840:a:brief', path: ['Brief'] }],
34
+ startAtTop: true,
35
+ onMove: async () => true,
36
+ onClose: () => {},
37
+ },
38
+ } satisfies Meta<typeof MoveDialog>
39
+
40
+ export default meta
41
+ type Story = StoryObj<typeof meta>
42
+
43
+ const pickSteer = async ({ canvasElement }: { canvasElement: HTMLElement }) => {
44
+ const page = within(canvasElement.ownerDocument.body)
45
+ await userEvent.click(page.getByRole('combobox', { name: 'Folder' }))
46
+ await userEvent.click(await page.findByRole('option', { name: 'Steer' }))
47
+ }
48
+
49
+ /** A file that may sit under any other: its own Folder first, at the top, with every other place there. */
50
+ export const Topic: Story = {}
51
+
52
+ /** A file that nests under nothing: only the Folder is asked, and not the one it is in. Move waits for a pick. */
53
+ export const Project: Story = {
54
+ args: { title: 'Folders: navigation for the whole suite', places: undefined, placesIn: undefined },
55
+ }
56
+
57
+ /** Nowhere to go in its own Folder: one holding only this file and what is under it. */
58
+ export const NowhereHere: Story = {
59
+ name: 'Nowhere here',
60
+ args: { places: [] },
61
+ }
62
+
63
+ /** Another Folder could not be read: the section's empty line, with Try again. */
64
+ export const FolderUnreadable: Story = {
65
+ name: 'Folder unreadable',
66
+ args: { places: [], placesIn: (): Promise<readonly MovePlace[]> => Promise.reject(new Error('down')) },
67
+ play: pickSteer,
68
+ }
69
+
70
+ /** Another Folder, still being read: the second list says so and waits. */
71
+ export const ReadingAFolder: Story = {
72
+ name: 'Reading a folder',
73
+ args: { placesIn: () => new Promise<readonly MovePlace[]>(() => {}) },
74
+ play: pickSteer,
75
+ }
76
+
77
+ /** A file whose parent is one kind: the empty place is "none", and nothing is chosen for the person. */
78
+ export const UnderNone: Story = {
79
+ name: 'Under none',
80
+ args: { startAtTop: false, topLabel: 'None — under none of these', places: [TOP, PROJECT] },
81
+ }
82
+
83
+ /** The Folders are still being read: the list says so. */
84
+ export const ReadingFolders: Story = {
85
+ name: 'Reading folders',
86
+ args: { folders: undefined },
87
+ }
88
+
89
+ /** No Folder to offer: said in the dialog's body, and Move stays greyed. */
90
+ export const NoOtherFolder: Story = {
91
+ name: 'No other folder',
92
+ args: { folders: [FOLDERS[0]], places: undefined, placesIn: undefined },
93
+ }
94
+
95
+ /** Another app's words, opening on the Folder the app chose. */
96
+ export const AnotherAppsWords: Story = {
97
+ name: 'Another app’s words',
98
+ args: {
99
+ heading: 'Move to Folder',
100
+ folderLabel: 'Destination Folder',
101
+ noFolder: 'There is no other Folder it can be moved to.',
102
+ description: 'Only the Folder it is listed in changes. Its issues and its conversation stay exactly as they are.',
103
+ title: 'Folders: navigation for the whole suite',
104
+ places: undefined,
105
+ placesIn: undefined,
106
+ startIn: 'steer',
107
+ },
108
+ }
109
+
110
+ /**
111
+ * A file listed in two Folders, after a move that half-worked: `from` is empty, so every Folder is offered, the ones
112
+ * it is in too, since moving into one takes it out of the other; Move again is the retry. Nothing is chosen for the
113
+ * person. The story opens the list.
114
+ */
115
+ export const ListedTwice: Story = {
116
+ name: 'Listed in two Folders',
117
+ args: { title: 'Folders: navigation for the whole suite', from: '', places: undefined, placesIn: undefined },
118
+ play: async ({ canvasElement }) => {
119
+ await userEvent.click(within(canvasElement.ownerDocument.body).getByRole('combobox', { name: 'Folder' }))
120
+ },
121
+ }
122
+
123
+ /** Moving: the button says so, and everything waits for the answer. */
124
+ export const Moving: Story = {
125
+ args: { onMove: () => new Promise<boolean>(() => {}) },
126
+ play: async ({ canvasElement }) => {
127
+ await userEvent.click(within(canvasElement.ownerDocument.body).getByRole('button', { name: 'Move' }))
128
+ },
129
+ }
130
+
131
+ /** The move was refused: it stays open, and the caller has said why. */
132
+ export const Refused: Story = {
133
+ args: { onMove: async () => false },
134
+ }
@@ -0,0 +1,239 @@
1
+ // @vitest-environment jsdom
2
+ /**
3
+ * Move a file to another Folder, under another file, or both (FOL-45): Peek's
4
+ * MoveDialog, moved into the kit (C11, 2 November) with Peek's tests, and
5
+ * what Leaf's and Ship's moves need beside them. A Folder that could not be
6
+ * read is said as the section's empty line with its Try again (B8).
7
+ */
8
+ import { afterEach, describe, expect, it, vi } from 'vitest'
9
+ import { cleanup, render, screen, waitFor } from '@testing-library/react'
10
+ import userEvent from '@testing-library/user-event'
11
+ import { MoveDialog, type MoveDialogProps, type MovePlace } from './MoveDialog'
12
+
13
+ afterEach(cleanup)
14
+
15
+ const HQ = { id: 'hq', name: 'Estiva HQ' }
16
+ const STEER = { id: 'steer', name: 'Steer' }
17
+ const TOP: MovePlace = { id: '', path: [] }
18
+ const BRIEF: MovePlace = { id: '30840:a:brief', path: ['Brief'] }
19
+ const LIVE: MovePlace = { id: '30850:a:live', path: ['A live project'] }
20
+
21
+ const Fixture = (props: Partial<MoveDialogProps>) => (
22
+ <MoveDialog
23
+ title="Notes"
24
+ description="Everyone who can read it now still can."
25
+ from="hq"
26
+ folders={[HQ, STEER]}
27
+ places={[]}
28
+ placesIn={vi.fn(async () => [])}
29
+ onMove={vi.fn(async () => true)}
30
+ onClose={() => {}}
31
+ {...props}
32
+ />
33
+ )
34
+
35
+ const optionsOf = async (name: string) => {
36
+ await userEvent.click(screen.getByRole('combobox', { name }))
37
+ // The chosen option's check reads as a mark in jsdom; the label is the rest.
38
+ return (await screen.findAllByRole('option')).map((option) => option.textContent?.replace('✔️', ''))
39
+ }
40
+
41
+ const pick = async (name: string, option: string) => {
42
+ await userEvent.click(screen.getByRole('combobox', { name }))
43
+ await userEvent.click(await screen.findByRole('option', { name: option }))
44
+ }
45
+
46
+ describe('MoveDialog (FOL-45, Peek’s tests)', () => {
47
+ it('opens on the Folder the file is in, with only real moves there', async () => {
48
+ render(<Fixture places={[BRIEF]} />)
49
+ expect(await optionsOf('Put it under')).toEqual(['Brief'])
50
+ })
51
+
52
+ it('reads another Folder when it is picked, and moves to its top by default', async () => {
53
+ const placesIn = vi.fn(async () => [TOP, BRIEF])
54
+ const onMove = vi.fn(async () => true)
55
+ render(<Fixture startAtTop placesIn={placesIn} onMove={onMove} />)
56
+ await pick('Folder', 'Steer')
57
+ expect(placesIn).toHaveBeenCalledWith('steer')
58
+ expect(await optionsOf('Put it under')).toEqual(['The top of Steer', 'Brief'])
59
+ await userEvent.keyboard('{Escape}')
60
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
61
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer', parent: '' }))
62
+ })
63
+
64
+ it('asks a file that nests under nothing only for the Folder, never offers the one it is in, and waits for a pick', async () => {
65
+ const onMove = vi.fn(async () => true)
66
+ render(<Fixture places={undefined} placesIn={undefined} onMove={onMove} />)
67
+ expect(screen.queryByRole('combobox', { name: 'Put it under' })).toBeNull()
68
+ // Nothing preselected: a Move pressed straight away would be a move nobody chose.
69
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
70
+ expect(await optionsOf('Folder')).toEqual(['Steer'])
71
+ await userEvent.click(await screen.findByRole('option', { name: 'Steer' }))
72
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
73
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer' }))
74
+ })
75
+
76
+ it('never picks a parent for a file whose parent is one kind: Move waits until the person does', async () => {
77
+ const onMove = vi.fn(async () => true)
78
+ render(<Fixture placesIn={async () => [LIVE]} onMove={onMove} />)
79
+ await pick('Folder', 'Steer')
80
+ await screen.findByRole('combobox', { name: 'Put it under' })
81
+ await waitFor(() => expect(screen.getByRole('combobox', { name: 'Put it under' }).hasAttribute('data-disabled')).toBe(false))
82
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
83
+ await pick('Put it under', 'A live project')
84
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
85
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer', parent: LIVE.id }))
86
+ })
87
+
88
+ it('says so when the picked Folder has nowhere to put it, and does not move', async () => {
89
+ render(<Fixture placesIn={async () => []} />)
90
+ await pick('Folder', 'Steer')
91
+ expect(await screen.findByText('There is nowhere in Steer to put it.')).toBeTruthy()
92
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
93
+ })
94
+
95
+ it('says a Folder that could not be read, and reads it again on Try again', async () => {
96
+ const placesIn = vi.fn().mockRejectedValueOnce(new Error('down')).mockResolvedValueOnce([TOP])
97
+ render(<Fixture placesIn={placesIn} />)
98
+ await pick('Folder', 'Steer')
99
+ expect(await screen.findByText('Steer could not be read.')).toBeTruthy()
100
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
101
+ await userEvent.click(screen.getByRole('button', { name: 'Try again' }))
102
+ expect(await optionsOf('Put it under')).toEqual(['The top of Steer'])
103
+ })
104
+ })
105
+
106
+ describe('MoveDialog, the kit’s', () => {
107
+ it('says a Folder that could not be read as the empty line beside it does, with its Try again (B8)', async () => {
108
+ render(<Fixture placesIn={async () => Promise.reject(new Error('down'))} />)
109
+ await pick('Folder', 'Steer')
110
+ const line = await screen.findByText('Steer could not be read.')
111
+ const empty = screen.getByText((_, element) => element?.tagName === 'P' && element.textContent === 'Steer could not be read.')
112
+ expect(empty).toBe(line)
113
+ // The section's empty line: caption and muted, as "There is nowhere in … to put it." is.
114
+ expect(line.className.split(' ')).toEqual(expect.arrayContaining(['text-caption', 'text-text-muted']))
115
+ expect(line.nextElementSibling).toBe(screen.getByRole('button', { name: 'Try again' }))
116
+ })
117
+
118
+ it('reads two picks of one Folder once', async () => {
119
+ const placesIn = vi.fn(() => new Promise<MovePlace[]>(() => {}))
120
+ render(<Fixture placesIn={placesIn} />)
121
+ await pick('Folder', 'Steer')
122
+ await pick('Folder', 'Estiva HQ')
123
+ await pick('Folder', 'Steer')
124
+ expect(placesIn).toHaveBeenCalledTimes(1)
125
+ })
126
+
127
+ it('reads the Folder it opens on when its places were not handed in', async () => {
128
+ const placesIn = vi.fn(async () => [TOP])
129
+ render(<Fixture places={undefined} placesIn={placesIn} startAtTop />)
130
+ await waitFor(() => expect(placesIn).toHaveBeenCalledWith('hq'))
131
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(false))
132
+ })
133
+
134
+ it('without startAtTop, chooses no place even when the top is first: Move waits (Leaf’s)', async () => {
135
+ render(<Fixture places={[TOP, BRIEF]} />)
136
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
137
+ expect(await optionsOf('Put it under')).toEqual(['The top of Estiva HQ', 'Brief'])
138
+ })
139
+
140
+ it('names the empty place with topLabel when the top is not a place: “under none of these”', async () => {
141
+ render(<Fixture places={[TOP, LIVE]} topLabel="None — under none of these" />)
142
+ expect(await optionsOf('Put it under')).toEqual(['None — under none of these', 'A live project'])
143
+ })
144
+
145
+ it('while the Folders are still read, says so in the list, and does not say there is nowhere to go (Leaf’s)', () => {
146
+ render(<Fixture folders={undefined} />)
147
+ expect(screen.queryByText('There is no other folder it can be moved to.')).toBeNull()
148
+ expect(screen.getByRole('combobox', { name: 'Folder' }).textContent).toContain('Reading…')
149
+ })
150
+
151
+ it('says there is no other Folder when none is offered', () => {
152
+ render(<Fixture folders={[HQ]} places={undefined} placesIn={undefined} />)
153
+ expect(screen.getByText('There is no other folder it can be moved to.')).toBeTruthy()
154
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
155
+ })
156
+
157
+ it('takes another app’s words, and opens on the Folder it is given (Ship’s Move to Folder)', async () => {
158
+ const onMove = vi.fn(async () => true)
159
+ render(
160
+ <Fixture
161
+ heading="Move to Folder"
162
+ folderLabel="Destination Folder"
163
+ description="Only the Folder it is listed in changes."
164
+ places={undefined}
165
+ placesIn={undefined}
166
+ startIn="steer"
167
+ onMove={onMove}
168
+ />,
169
+ )
170
+ expect(screen.getByRole('dialog', { name: 'Move to Folder' })).toBeTruthy()
171
+ expect(screen.getByText('Only the Folder it is listed in changes.')).toBeTruthy()
172
+ expect(screen.getByRole('combobox', { name: 'Destination Folder' }).textContent).toContain('Steer')
173
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
174
+ await waitFor(() => expect(onMove).toHaveBeenCalledWith({ folder: 'steer' }))
175
+ })
176
+
177
+ it('says no other Folder in the app’s words', () => {
178
+ render(<Fixture folders={[HQ]} placesIn={undefined} noFolder="There is no other Folder it can be moved to." />)
179
+ expect(screen.getByText('There is no other Folder it can be moved to.')).toBeTruthy()
180
+ })
181
+
182
+ it('stays open when the move is refused, and closes when it went through', async () => {
183
+ const onClose = vi.fn()
184
+ const { unmount } = render(<Fixture places={[BRIEF]} onMove={async () => false} onClose={onClose} />)
185
+ await pick('Put it under', 'Brief')
186
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
187
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Move' })).toBeTruthy())
188
+ expect(onClose).not.toHaveBeenCalled()
189
+ unmount()
190
+ render(<Fixture places={[BRIEF]} onClose={onClose} />)
191
+ await pick('Put it under', 'Brief')
192
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
193
+ await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
194
+ })
195
+
196
+ it('says it is moving, and both buttons wait', async () => {
197
+ render(<Fixture places={[BRIEF]} onMove={() => new Promise<boolean>(() => {})} />)
198
+ await pick('Put it under', 'Brief')
199
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
200
+ expect((screen.getByRole('button', { name: 'Moving…' }) as HTMLButtonElement).disabled).toBe(true)
201
+ expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
202
+ })
203
+ })
204
+
205
+ describe('MoveDialog, a file not listed in exactly one Folder (`from` empty; Ship’s move, 2 November)', () => {
206
+ const THIRD = { id: 'third', name: 'Third' }
207
+ const flat = { places: undefined, placesIn: undefined, from: '' }
208
+
209
+ it('holds no Folder back: listed in two after a move that half-worked, or in none, every Folder is offered', async () => {
210
+ render(<Fixture {...flat} folders={[HQ, STEER, THIRD]} />)
211
+ expect(await optionsOf('Folder')).toEqual(['Estiva HQ', 'Steer', 'Third'])
212
+ })
213
+
214
+ it('chooses nothing for the person even so: Move waits for a pick, or it opens on startIn', async () => {
215
+ render(<Fixture {...flat} folders={[HQ, STEER, THIRD]} />)
216
+ expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(true)
217
+ cleanup()
218
+ render(<Fixture {...flat} folders={[HQ, STEER, THIRD]} startIn="third" />)
219
+ expect(screen.getByRole('combobox', { name: 'Folder' }).textContent).toContain('Third')
220
+ })
221
+
222
+ it('stays open on a refusal, and Move again is the retry, to the same Folder', async () => {
223
+ const onMove = vi.fn(async () => false)
224
+ render(<Fixture {...flat} folders={[HQ, STEER, THIRD]} onMove={onMove} />)
225
+ await pick('Folder', 'Steer')
226
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
227
+ await waitFor(() => expect(onMove).toHaveBeenCalledTimes(1))
228
+ await waitFor(() => expect((screen.getByRole('button', { name: 'Move' }) as HTMLButtonElement).disabled).toBe(false))
229
+ await userEvent.click(screen.getByRole('button', { name: 'Move' }))
230
+ await waitFor(() => expect(onMove).toHaveBeenCalledTimes(2))
231
+ expect(onMove).toHaveBeenLastCalledWith({ folder: 'steer' })
232
+ })
233
+
234
+ it('listed in one again (`from` named), the one it is in is held back once more', async () => {
235
+ const { rerender } = render(<Fixture {...flat} folders={[HQ, STEER, THIRD]} />)
236
+ rerender(<Fixture {...flat} from="hq" folders={[HQ, STEER, THIRD]} />)
237
+ expect(await optionsOf('Folder')).toEqual(['Steer', 'Third'])
238
+ })
239
+ })