@estiva-app/ui 0.98.0 → 0.99.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.
- package/README.md +1 -1
- package/dist/AppProvider.d.ts +6 -3
- package/dist/AppProvider.d.ts.map +1 -1
- package/dist/ArchiveDialog.d.ts +35 -0
- package/dist/ArchiveDialog.d.ts.map +1 -0
- package/dist/AttachedCard.d.ts +13 -2
- package/dist/AttachedCard.d.ts.map +1 -1
- package/dist/Card.d.ts +6 -1
- package/dist/Card.d.ts.map +1 -1
- package/dist/ChipInput.d.ts +3 -1
- package/dist/ChipInput.d.ts.map +1 -1
- package/dist/CollapsibleSection.d.ts +27 -2
- package/dist/CollapsibleSection.d.ts.map +1 -1
- package/dist/CommentBox.d.ts +2 -2
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/ConfirmDialog.d.ts +15 -2
- package/dist/ConfirmDialog.d.ts.map +1 -1
- package/dist/ConversationCard.d.ts +6 -1
- package/dist/ConversationCard.d.ts.map +1 -1
- package/dist/ConversationLayout.d.ts +19 -4
- package/dist/ConversationLayout.d.ts.map +1 -1
- package/dist/ConversationPlace.d.ts +17 -0
- package/dist/ConversationPlace.d.ts.map +1 -0
- package/dist/DocumentEditor.d.ts +38 -0
- package/dist/DocumentEditor.d.ts.map +1 -1
- package/dist/DocumentField.d.ts +50 -0
- package/dist/DocumentField.d.ts.map +1 -0
- package/dist/EditableText.d.ts +38 -4
- package/dist/EditableText.d.ts.map +1 -1
- package/dist/EmptyState.d.ts +10 -5
- package/dist/EmptyState.d.ts.map +1 -1
- package/dist/FormDialog.d.ts +38 -0
- package/dist/FormDialog.d.ts.map +1 -0
- package/dist/InlineText.d.ts.map +1 -1
- package/dist/MoveDialog.d.ts +61 -0
- package/dist/MoveDialog.d.ts.map +1 -0
- package/dist/NavItem.d.ts +9 -2
- package/dist/NavItem.d.ts.map +1 -1
- package/dist/NavTree.d.ts +16 -3
- package/dist/NavTree.d.ts.map +1 -1
- package/dist/PinnedComment.d.ts +3 -1
- package/dist/PinnedComment.d.ts.map +1 -1
- package/dist/ReactionHorizon.d.ts +5 -1
- package/dist/ReactionHorizon.d.ts.map +1 -1
- package/dist/ResolveDialog.d.ts +3 -1
- package/dist/ResolveDialog.d.ts.map +1 -1
- package/dist/SelectionToolbar.d.ts +2 -2
- package/dist/Thread.d.ts +6 -3
- package/dist/Thread.d.ts.map +1 -1
- package/dist/commentBoxFrame.d.ts.map +1 -1
- package/dist/conversation.examples.d.ts +4 -1
- package/dist/conversation.examples.d.ts.map +1 -1
- package/dist/conversationScroll.d.ts +80 -0
- package/dist/conversationScroll.d.ts.map +1 -0
- package/dist/editor.d.ts +1 -0
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +228 -69
- package/dist/editor.js.map +4 -4
- package/dist/eslint/index.js +2 -2
- package/dist/eslint/index.js.map +2 -2
- package/dist/eslint/no-field-outside-a-form.d.ts +2 -2
- package/dist/eslint/no-field-outside-a-form.d.ts.map +1 -1
- package/dist/eslint/no-native-title.d.ts +1 -1
- package/dist/eslint/no-native-title.d.ts.map +1 -1
- package/dist/formBusy.d.ts +5 -2
- package/dist/formBusy.d.ts.map +1 -1
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2210 -1458
- package/dist/index.js.map +4 -4
- package/dist/looks.d.ts +8 -0
- package/dist/looks.d.ts.map +1 -1
- package/dist/seenOnScreen.d.ts +27 -0
- package/dist/seenOnScreen.d.ts.map +1 -0
- package/dist/showInConversation.d.ts +31 -0
- package/dist/showInConversation.d.ts.map +1 -0
- package/dist/threadCard.d.ts +13 -0
- package/dist/threadCard.d.ts.map +1 -1
- package/package.json +1 -1
- package/registry.json +904 -139
- package/src/AppProvider.mdx +4 -0
- package/src/AppProvider.test.tsx +34 -2
- package/src/AppProvider.tsx +17 -6
- package/src/ArchiveDialog.mdx +70 -0
- package/src/ArchiveDialog.stories.tsx +64 -0
- package/src/ArchiveDialog.test.tsx +90 -0
- package/src/ArchiveDialog.tsx +70 -0
- package/src/AttachedCard.mdx +6 -0
- package/src/AttachedCard.stories.tsx +9 -1
- package/src/AttachedCard.test.tsx +111 -2
- package/src/AttachedCard.tsx +77 -7
- package/src/Card.mdx +20 -1
- package/src/Card.stories.tsx +20 -0
- package/src/Card.test.tsx +87 -1
- package/src/Card.tsx +51 -3
- package/src/ChipInput.mdx +7 -1
- package/src/ChipInput.stories.tsx +9 -0
- package/src/ChipInput.test.tsx +42 -0
- package/src/ChipInput.tsx +7 -3
- package/src/CollapsibleSection.mdx +20 -1
- package/src/CollapsibleSection.stories.tsx +19 -1
- package/src/CollapsibleSection.test.tsx +85 -2
- package/src/CollapsibleSection.tsx +54 -15
- package/src/CommentBox.mdx +2 -1
- package/src/CommentBox.test.tsx +81 -1
- package/src/CommentBox.tsx +32 -11
- package/src/ConfirmDialog.mdx +25 -3
- package/src/ConfirmDialog.stories.tsx +27 -0
- package/src/ConfirmDialog.test.tsx +87 -1
- package/src/ConfirmDialog.tsx +39 -8
- package/src/ConversationCard.mdx +4 -0
- package/src/ConversationCard.stories.tsx +11 -1
- package/src/ConversationCard.test.tsx +116 -0
- package/src/ConversationCard.tsx +53 -36
- package/src/ConversationLayout.mdx +30 -4
- package/src/ConversationLayout.scroll.test.tsx +411 -0
- package/src/ConversationLayout.stories.tsx +79 -1
- package/src/ConversationLayout.test.tsx +79 -0
- package/src/ConversationLayout.tsx +136 -15
- package/src/ConversationPlace.mdx +53 -0
- package/src/ConversationPlace.stories.tsx +48 -0
- package/src/ConversationPlace.test.tsx +51 -0
- package/src/ConversationPlace.tsx +30 -0
- package/src/DocumentEditor.mdx +2 -1
- package/src/DocumentEditor.tsx +118 -64
- package/src/DocumentField.mdx +83 -0
- package/src/DocumentField.stories.tsx +110 -0
- package/src/DocumentField.test.tsx +281 -0
- package/src/DocumentField.tsx +199 -0
- package/src/EditableText.buttons.test.tsx +318 -0
- package/src/EditableText.mdx +50 -2
- package/src/EditableText.stories.tsx +96 -2
- package/src/EditableText.tsx +189 -5
- package/src/EmptyState.mdx +33 -8
- package/src/EmptyState.stories.tsx +26 -1
- package/src/EmptyState.test.tsx +63 -2
- package/src/EmptyState.tsx +28 -6
- package/src/Form.mdx +3 -1
- package/src/FormDialog.mdx +78 -0
- package/src/FormDialog.stories.tsx +90 -0
- package/src/FormDialog.test.tsx +183 -0
- package/src/FormDialog.tsx +93 -0
- package/src/InlineText.mdx +1 -0
- package/src/InlineText.tsx +2 -1
- package/src/MoveDialog.mdx +74 -0
- package/src/MoveDialog.stories.tsx +121 -0
- package/src/MoveDialog.test.tsx +203 -0
- package/src/MoveDialog.tsx +183 -0
- package/src/NavItem.mdx +15 -0
- package/src/NavItem.stories.tsx +15 -0
- package/src/NavItem.test.tsx +64 -1
- package/src/NavItem.tsx +10 -2
- package/src/NavTree.mdx +26 -4
- package/src/NavTree.stories.tsx +59 -0
- package/src/NavTree.test.tsx +232 -2
- package/src/NavTree.tsx +93 -43
- package/src/PinnedComment.mdx +6 -1
- package/src/PinnedComment.stories.tsx +11 -1
- package/src/PinnedComment.tsx +15 -2
- package/src/ReactionHorizon.mdx +3 -0
- package/src/ReactionHorizon.stories.tsx +3 -0
- package/src/ReactionHorizon.test.tsx +55 -0
- package/src/ReactionHorizon.tsx +30 -11
- package/src/ReplyCard.mdx +3 -0
- package/src/ReplyCard.stories.tsx +19 -1
- package/src/ResolveDialog.mdx +2 -0
- package/src/ResolveDialog.test.tsx +21 -0
- package/src/ResolveDialog.tsx +11 -39
- package/src/SelectionToolbar.tsx +2 -2
- package/src/Textarea.mdx +1 -0
- package/src/Thread.mdx +18 -1
- package/src/Thread.stories.tsx +55 -3
- package/src/Thread.test.tsx +11 -0
- package/src/Thread.tsx +53 -11
- package/src/commentBoxFrame.tsx +2 -2
- package/src/conversation.examples.tsx +10 -2
- package/src/conversationScroll.ts +155 -0
- package/src/editor.ts +1 -0
- package/src/editorSelection.test.tsx +53 -0
- package/src/eslint/no-field-outside-a-form.test.ts +4 -0
- package/src/eslint/no-field-outside-a-form.ts +2 -2
- package/src/eslint/no-native-title.ts +1 -1
- package/src/formBusy.ts +5 -2
- package/src/index.ts +16 -6
- package/src/looks.ts +10 -0
- package/src/registry/registry.test.ts +12 -6
- package/src/seenOnScreen.test.tsx +182 -0
- package/src/seenOnScreen.ts +146 -0
- package/src/showInConversation.test.tsx +168 -0
- package/src/showInConversation.ts +93 -0
- package/src/threadCard.ts +16 -0
- package/stories/Choosing.mdx +7 -2
- package/tailwind-preset.js +7 -0
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* (measured 2026-09-09).
|
|
7
7
|
*/
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
9
|
-
import { cleanup, render, screen } from '@testing-library/react'
|
|
9
|
+
import { act, cleanup, render, renderHook, screen } from '@testing-library/react'
|
|
10
10
|
import userEvent from '@testing-library/user-event'
|
|
11
|
-
import { CollapsibleSection } from './CollapsibleSection'
|
|
11
|
+
import { CollapsibleSection, useRememberedOpen } from './CollapsibleSection'
|
|
12
12
|
import { MenuItem } from './Menu'
|
|
13
13
|
|
|
14
14
|
afterEach(cleanup)
|
|
@@ -133,3 +133,86 @@ describe('CollapsibleSection, its header', () => {
|
|
|
133
133
|
expect(icon.compareDocumentPosition(screen.getByText('Section')) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
134
134
|
})
|
|
135
135
|
})
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The fold this browser remembers, for an app that must know it before it
|
|
139
|
+
* draws what is inside (Peek's Folders, FOL-21: a Folder's rows are a read,
|
|
140
|
+
* made only for a Folder that is open). Peek's own `useRememberedOpen`, moved
|
|
141
|
+
* in: its rules and its tests' cases.
|
|
142
|
+
*/
|
|
143
|
+
describe('useRememberedOpen', () => {
|
|
144
|
+
it('with nothing remembered it is the fallback, and follows it until the person chooses', () => {
|
|
145
|
+
const { result, rerender } = renderHook(({ fallback }) => useRememberedOpen('test.fold', fallback), { initialProps: { fallback: false } })
|
|
146
|
+
expect(result.current[0]).toBe(false)
|
|
147
|
+
rerender({ fallback: true })
|
|
148
|
+
expect(result.current[0]).toBe(true)
|
|
149
|
+
rerender({ fallback: false })
|
|
150
|
+
expect(result.current[0]).toBe(false)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('a default is never written down: only a choice is remembered', () => {
|
|
154
|
+
const { rerender } = renderHook(({ fallback }) => useRememberedOpen('test.fold', fallback), { initialProps: { fallback: true } })
|
|
155
|
+
rerender({ fallback: false })
|
|
156
|
+
expect(window.localStorage.getItem('test.fold')).toBeNull()
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it('a choice beats the fallback from then on, and is remembered as a section remembers it', () => {
|
|
160
|
+
const { result, rerender } = renderHook(({ fallback }) => useRememberedOpen('test.fold', fallback), { initialProps: { fallback: true } })
|
|
161
|
+
act(() => result.current[1](false))
|
|
162
|
+
expect(result.current[0]).toBe(false)
|
|
163
|
+
expect(window.localStorage.getItem('test.fold')).toBe('closed')
|
|
164
|
+
rerender({ fallback: true })
|
|
165
|
+
expect(result.current[0]).toBe(false)
|
|
166
|
+
act(() => result.current[1](true))
|
|
167
|
+
expect(window.localStorage.getItem('test.fold')).toBe('open')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('what this browser remembers is known on the first draw, whatever the fallback', () => {
|
|
171
|
+
window.localStorage.setItem('test.open', 'open')
|
|
172
|
+
window.localStorage.setItem('test.closed', 'closed')
|
|
173
|
+
const seen: boolean[] = []
|
|
174
|
+
renderHook(() => {
|
|
175
|
+
const [open] = useRememberedOpen('test.open', false)
|
|
176
|
+
const [closed] = useRememberedOpen('test.closed', true)
|
|
177
|
+
seen.push(open, closed)
|
|
178
|
+
})
|
|
179
|
+
expect(seen.slice(0, 2)).toEqual([true, false])
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('reads what a CollapsibleSection under the same key remembers, and the section reads what it writes', async () => {
|
|
183
|
+
const { unmount } = render(<CollapsibleSection title="Section" storageKey="test.shared">{rows}</CollapsibleSection>)
|
|
184
|
+
await userEvent.click(title())
|
|
185
|
+
unmount()
|
|
186
|
+
const { result } = renderHook(() => useRememberedOpen('test.shared', true))
|
|
187
|
+
expect(result.current[0]).toBe(false)
|
|
188
|
+
act(() => result.current[1](true))
|
|
189
|
+
render(<CollapsibleSection title="Section" storageKey="test.shared" defaultOpen={false}>{rows}</CollapsibleSection>)
|
|
190
|
+
expect(title().getAttribute('aria-expanded')).toBe('true')
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
it('with no key the choice is kept while mounted, and nothing is written', () => {
|
|
194
|
+
const { result, rerender } = renderHook(({ fallback }) => useRememberedOpen(undefined, fallback), { initialProps: { fallback: false } })
|
|
195
|
+
act(() => result.current[1](true))
|
|
196
|
+
rerender({ fallback: false })
|
|
197
|
+
expect(result.current[0]).toBe(true)
|
|
198
|
+
expect(window.localStorage.length).toBe(0)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
it('a browser that blocks storage still gets a working fold; it forgets', () => {
|
|
202
|
+
const get = vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
|
203
|
+
throw new Error('blocked')
|
|
204
|
+
})
|
|
205
|
+
const set = vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
|
206
|
+
throw new Error('blocked')
|
|
207
|
+
})
|
|
208
|
+
try {
|
|
209
|
+
const { result } = renderHook(() => useRememberedOpen('test.blocked', true))
|
|
210
|
+
expect(result.current[0]).toBe(true)
|
|
211
|
+
act(() => result.current[1](false))
|
|
212
|
+
expect(result.current[0]).toBe(false)
|
|
213
|
+
} finally {
|
|
214
|
+
get.mockRestore()
|
|
215
|
+
set.mockRestore()
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
|
1
|
+
import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from 'react'
|
|
2
2
|
import { Collapsible } from '@base-ui/react/collapsible'
|
|
3
3
|
import { cn } from './cn'
|
|
4
4
|
import { SectionHeader, type SectionAction } from './SectionHeader'
|
|
@@ -48,7 +48,8 @@ export interface CollapsibleSectionProps {
|
|
|
48
48
|
* The current item, when it sits in here: the section opens each time this
|
|
49
49
|
* names a new one, as a click would — remembered under `storageKey`, told to
|
|
50
50
|
* `onOpenChange`. Closed again by hand, it stays closed until another item
|
|
51
|
-
* opens.
|
|
51
|
+
* opens. Open already, by its default, it is left as it is: a default is
|
|
52
|
+
* never written down. `NavTree` passes it.
|
|
52
53
|
*/
|
|
53
54
|
openFor?: string
|
|
54
55
|
/** 16px, before the title; the arrow takes its place on hover — `SectionHeader`'s. */
|
|
@@ -90,24 +91,41 @@ const CLOSED = 'closed'
|
|
|
90
91
|
* would, each time it names a new item. An effect, not a render: opening tells
|
|
91
92
|
* the caller (`onOpenChange`), and a parent is never set while a child draws.
|
|
92
93
|
* Gone and back — the item opened, another elsewhere, then it again — is new.
|
|
94
|
+
*
|
|
95
|
+
* Only a shut one is opened: one open by its default stays a default, never
|
|
96
|
+
* written down, so it closes again once the item goes. `link` is different: a
|
|
97
|
+
* link to the section itself (`NavTree`'s `selectedGroup`), each new one
|
|
98
|
+
* opening it as a click would, open already or not — remembered open, told to
|
|
99
|
+
* the caller — so it stays open when the reader goes on elsewhere.
|
|
93
100
|
*/
|
|
94
|
-
export function useOpenFor(openFor: string | undefined, open: boolean, setOpen: (open: boolean) => void) {
|
|
101
|
+
export function useOpenFor(openFor: string | undefined, open: boolean, setOpen: (open: boolean) => void, link?: string) {
|
|
95
102
|
const seen = useRef<string | undefined>(undefined)
|
|
103
|
+
const linked = useRef<string | undefined>(undefined)
|
|
96
104
|
useEffect(() => {
|
|
97
|
-
|
|
105
|
+
const newItem = openFor !== seen.current
|
|
106
|
+
const newLink = link !== linked.current
|
|
98
107
|
seen.current = openFor
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
108
|
+
linked.current = link
|
|
109
|
+
if (newLink && link !== undefined) setOpen(true)
|
|
110
|
+
else if (newItem && openFor !== undefined && !open) setOpen(true)
|
|
111
|
+
// Only a new item or a new link opens it: the reader's own toggles in between are theirs.
|
|
112
|
+
}, [openFor, link])
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Set by a `NavTreeSection` round its section while `NavTree`'s `selectedGroup`
|
|
117
|
+
* names it: the link that led to it, which opens it and is remembered (`useOpenFor`'s
|
|
118
|
+
* `link`). The kit's wiring between the two, not for an app.
|
|
119
|
+
*/
|
|
120
|
+
export const sectionLinked = createContext<string | undefined>(undefined)
|
|
121
|
+
|
|
122
|
+
function readStored(key: string | undefined): boolean | null {
|
|
123
|
+
if (!key) return null
|
|
106
124
|
try {
|
|
107
125
|
const value = window.localStorage.getItem(key)
|
|
108
|
-
return value === OPEN ? true : value === CLOSED ? false :
|
|
126
|
+
return value === OPEN ? true : value === CLOSED ? false : null
|
|
109
127
|
} catch {
|
|
110
|
-
return
|
|
128
|
+
return null
|
|
111
129
|
}
|
|
112
130
|
}
|
|
113
131
|
|
|
@@ -120,15 +138,36 @@ function writeStored(key: string | undefined, open: boolean) {
|
|
|
120
138
|
}
|
|
121
139
|
}
|
|
122
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Open or closed as this browser remembers it under `storageKey`, else `fallback`, for an app that must know before it draws what is inside — a fold whose rows are read only once it is open (Peek's Folders, FOL-21).
|
|
143
|
+
*
|
|
144
|
+
* The same memory as `CollapsibleSection`'s `storageKey`, in the same words,
|
|
145
|
+
* read once when it mounts: hand the pair to a section's `open` and
|
|
146
|
+
* `onOpenChange`. `fallback` decides until the person does, and stays live —
|
|
147
|
+
* a fold can spring open while it holds the current item and close again when
|
|
148
|
+
* it stops — and only a choice is written down, so a default never becomes a
|
|
149
|
+
* memory. No key: the choice is kept while mounted. A browser that blocks
|
|
150
|
+
* storage still gets a working fold; it forgets.
|
|
151
|
+
*/
|
|
152
|
+
export function useRememberedOpen(storageKey: string | undefined, fallback: boolean): [open: boolean, setOpen: (next: boolean) => void] {
|
|
153
|
+
const [choice, setChoice] = useState<boolean | null>(() => readStored(storageKey))
|
|
154
|
+
const setOpen = (next: boolean) => {
|
|
155
|
+
setChoice(next)
|
|
156
|
+
writeStored(storageKey, next)
|
|
157
|
+
}
|
|
158
|
+
return [choice ?? fallback, setOpen]
|
|
159
|
+
}
|
|
160
|
+
|
|
123
161
|
export function CollapsibleSection({ title, defaultOpen = true, open: openProp, onOpenChange, pending = false, storageKey, openFor, icon, trailing, actions, menu, menuLabel, showActions, look = 'heading', indent = false, children, className, contentClassName }: CollapsibleSectionProps) {
|
|
124
|
-
|
|
162
|
+
// The section's default is the one it was drawn with: a later `defaultOpen` does not move it.
|
|
163
|
+
const [initial] = useState(defaultOpen)
|
|
164
|
+
const [openState, remember] = useRememberedOpen(storageKey, initial)
|
|
125
165
|
const open = openProp ?? openState
|
|
126
166
|
const setOpen = (next: boolean) => {
|
|
127
|
-
|
|
128
|
-
writeStored(storageKey, next)
|
|
167
|
+
remember(next)
|
|
129
168
|
onOpenChange?.(next)
|
|
130
169
|
}
|
|
131
|
-
useOpenFor(openFor, open, setOpen)
|
|
170
|
+
useOpenFor(openFor, open, setOpen, useContext(sectionLinked))
|
|
132
171
|
// Pending, Base UI holds the panel shut and so would open it on a click: the click is the title's, and the title says open.
|
|
133
172
|
// Only a click: find-in-page reaching into the shut panel asks to open it, and it is open.
|
|
134
173
|
const shown = open && !pending
|
package/src/CommentBox.mdx
CHANGED
|
@@ -94,7 +94,8 @@ It does these by itself. Write none of them around it.
|
|
|
94
94
|
| A URL pasted over words links them when a message can carry them as a link (one line of plain words, no bracket, no chip, no `)` in the URL); otherwise the URL goes in after the words. The caret goes after the link, so the next Enter sends. Typing after linked words is not linked | a paste handler |
|
|
95
95
|
| A long draft stops at half the window and scrolls inside the box, in the send box and the edit box | a height or a scroll container |
|
|
96
96
|
| The bar down the text while an urgent mention is in the box | an urgent check |
|
|
97
|
-
| The read-only line | a disabled box |
|
|
97
|
+
| The read-only line, with no editor built behind it when the box is closed from the start | a disabled box, or a line of your own |
|
|
98
|
+
| Selected words painted in the selected colour, the one the format buttons' link field keeps them in | a `::selection` rule |
|
|
98
99
|
|
|
99
100
|
## Keys
|
|
100
101
|
|
package/src/CommentBox.test.tsx
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* mode, drafts, files and the read-only line.
|
|
6
6
|
*/
|
|
7
7
|
import { act, Suspense, use } from 'react'
|
|
8
|
-
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
8
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
9
9
|
import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'
|
|
10
10
|
import { Extension, type Editor } from '@tiptap/core'
|
|
11
11
|
import { Fragment, Slice } from '@tiptap/pm/model'
|
|
@@ -14,6 +14,8 @@ import { encodeNaddr, encodeNevent } from '@estiva-app/protocol'
|
|
|
14
14
|
import type { ReferenceViewProps } from './BlockNodes'
|
|
15
15
|
import { CommentBox, commentBoxRows, keepCommentBoxWarm, type BoxUnder, type CommentBoxDraft, type CommentBoxEdit, type CommentBoxProps, type SendAnswer, type UploadAnswer } from './CommentBox'
|
|
16
16
|
import type { MentionPerson, ReferenceSection } from './ComposerTriggers'
|
|
17
|
+
import { ConversationCard } from './ConversationCard'
|
|
18
|
+
import { ConversationLayout } from './ConversationLayout'
|
|
17
19
|
|
|
18
20
|
const PEOPLE: MentionPerson[] = [{ id: 'one', name: 'Person one', pubkey: 'b'.repeat(64) }]
|
|
19
21
|
const INSERT = [commentBoxRows.file, commentBoxRows.mention, commentBoxRows.urgent, commentBoxRows.reference]
|
|
@@ -117,6 +119,59 @@ describe('sending, held until the relay answers', () => {
|
|
|
117
119
|
})
|
|
118
120
|
})
|
|
119
121
|
|
|
122
|
+
/**
|
|
123
|
+
* In a ConversationLayout's box (C1 of the audit of 2 November): the reader's own comment brings them down to it as it
|
|
124
|
+
* is drawn, before the relay has answered, scrolled up or not (Peek's OPT-6, which Peek wired by hand). jsdom has no
|
|
125
|
+
* layout: every box says the same heights, and only the comments' box's offset is read.
|
|
126
|
+
*/
|
|
127
|
+
describe('sending, in a ConversationLayout', () => {
|
|
128
|
+
const comments = (n: number) =>
|
|
129
|
+
Array.from({ length: n }, (_, i) => ({ id: `c${i}`, card: <ConversationCard author={{ name: 'Person one' }} time="11:08 AM">{`Comment ${i}`}</ConversationCard> }))
|
|
130
|
+
const heights = { scroll: 1000 }
|
|
131
|
+
const kept = (['scrollHeight', 'clientHeight'] as const).map((p) => [p, Object.getOwnPropertyDescriptor(HTMLElement.prototype, p)] as const)
|
|
132
|
+
beforeAll(() => {
|
|
133
|
+
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', { configurable: true, get: () => heights.scroll })
|
|
134
|
+
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, get: () => 400 })
|
|
135
|
+
})
|
|
136
|
+
afterAll(() => {
|
|
137
|
+
for (const [p, d] of kept) if (d) Object.defineProperty(HTMLElement.prototype, p, d)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
for (const showsAtOnce of [false, true]) {
|
|
141
|
+
it(`a send brings the reader down to their comment as it is drawn, ${showsAtOnce ? 'shown at once' : 'held'}; a refused one leaves them where they are`, async () => {
|
|
142
|
+
const answer = later<SendAnswer>()
|
|
143
|
+
const list = { current: null as HTMLDivElement | null }
|
|
144
|
+
const at = (n: number, send: CommentBoxProps['send']) => <ConversationLayout threads="beside" items={comments(n)} bodyRef={list} box={<Box showsAtOnce={showsAtOnce} send={send} />} />
|
|
145
|
+
const send = vi.fn<CommentBoxProps['send']>(() => answer.promise)
|
|
146
|
+
const { rerender } = render(at(8, send))
|
|
147
|
+
list.current!.scrollTop = 300
|
|
148
|
+
fireEvent.scroll(list.current!)
|
|
149
|
+
await type('Mine')
|
|
150
|
+
await press('Enter')
|
|
151
|
+
expect(send).toHaveBeenCalledTimes(1)
|
|
152
|
+
// Drawn before the relay answers, as the app draws it.
|
|
153
|
+
heights.scroll = 1200
|
|
154
|
+
rerender(at(9, send))
|
|
155
|
+
expect(list.current!.scrollTop).toBe(1200)
|
|
156
|
+
answer.answer({ accepted: true })
|
|
157
|
+
await settle()
|
|
158
|
+
|
|
159
|
+
// Scrolled up again; a send refused: what arrives next does not pull the reader down.
|
|
160
|
+
list.current!.scrollTop = 300
|
|
161
|
+
fireEvent.scroll(list.current!)
|
|
162
|
+
const refused = vi.fn<CommentBoxProps['send']>(async () => ({ accepted: false, reason: 'rate-limited' }))
|
|
163
|
+
rerender(at(9, refused))
|
|
164
|
+
await type('Mine again')
|
|
165
|
+
await press('Enter')
|
|
166
|
+
await settle()
|
|
167
|
+
expect(refused).toHaveBeenCalledTimes(1)
|
|
168
|
+
heights.scroll = 1400
|
|
169
|
+
rerender(at(10, refused))
|
|
170
|
+
expect(list.current!.scrollTop).toBe(300)
|
|
171
|
+
})
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
120
175
|
describe('sending, shown at once', () => {
|
|
121
176
|
it('the box empties at once; a refusal puts the words back, says why, and tells the app', async () => {
|
|
122
177
|
const answer = later<SendAnswer>()
|
|
@@ -358,6 +413,31 @@ describe('read-only', () => {
|
|
|
358
413
|
expect(document.querySelector('.ProseMirror')).toBeNull()
|
|
359
414
|
expect(screen.queryByRole('button', { name: 'Send' })).toBeNull()
|
|
360
415
|
})
|
|
416
|
+
|
|
417
|
+
it('closed from the start, it builds no editor to say it: none is handed to the app', () => {
|
|
418
|
+
const onEditor = vi.fn()
|
|
419
|
+
render(<Box closed={{ reason: 'Archived. It takes no new comments.' }} onEditor={onEditor} />)
|
|
420
|
+
expect(screen.getByText('Archived. It takes no new comments.')).toBeTruthy()
|
|
421
|
+
expect(onEditor.mock.calls.filter(([editor]) => editor !== null)).toHaveLength(0)
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
it('opened later, it builds its editor then, and can be written in', async () => {
|
|
425
|
+
const onEditor = vi.fn()
|
|
426
|
+
const { rerender } = render(<Box closed={{ reason: 'Signed out.' }} onEditor={onEditor} />)
|
|
427
|
+
rerender(<Box onEditor={onEditor} />)
|
|
428
|
+
expect(onEditor.mock.calls.filter(([editor]) => editor !== null)).toHaveLength(1)
|
|
429
|
+
await type('Hello')
|
|
430
|
+
expect(editorOf().getText()).toBe('Hello')
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
it('closed while something is written, and opened again, it still holds the words', async () => {
|
|
434
|
+
const { rerender } = render(<Box />)
|
|
435
|
+
await type('Kept through the close')
|
|
436
|
+
rerender(<Box closed={{ reason: 'Signed out.' }} />)
|
|
437
|
+
expect(document.querySelector('.ProseMirror')).toBeNull()
|
|
438
|
+
rerender(<Box />)
|
|
439
|
+
expect(editorOf().getText()).toBe('Kept through the close')
|
|
440
|
+
})
|
|
361
441
|
})
|
|
362
442
|
|
|
363
443
|
describe('under the box: the one card, with ✕, and the live parts', () => {
|
package/src/CommentBox.tsx
CHANGED
|
@@ -34,6 +34,7 @@ import { KeptSelection } from './SelectionToolbar'
|
|
|
34
34
|
import { isSuggestionOpen } from './suggestionPopup'
|
|
35
35
|
import { ToolbarButton } from './Toolbar'
|
|
36
36
|
import { caretOnOpen } from './threadCard'
|
|
37
|
+
import { sendsInLayout } from './conversationScroll'
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* The one box every app writes a comment, a reply and a chat line in, from the
|
|
@@ -164,7 +165,7 @@ export interface CommentBoxProps {
|
|
|
164
165
|
upload?: (file: File) => Promise<UploadAnswer>
|
|
165
166
|
/** The file picker's `accept`. */
|
|
166
167
|
accept?: string
|
|
167
|
-
/** The box cannot write here (an archived file, signed out): a line saying why takes its place. */
|
|
168
|
+
/** The box cannot write here (an archived file, signed out): a line saying why takes its place. Closed from the start, it builds no editor. */
|
|
168
169
|
closed?: { reason: ReactNode }
|
|
169
170
|
/**
|
|
170
171
|
* How a link the box holds is drawn — a pasted one, a pasted `nostr:` address, and a `[` pick alike: the app's view
|
|
@@ -428,7 +429,29 @@ const holdsUrgent = (editor: Editor): boolean => {
|
|
|
428
429
|
|
|
429
430
|
let fileCount = 0
|
|
430
431
|
|
|
431
|
-
|
|
432
|
+
/** The line that takes the box's place where nothing can be written: a lock and why. */
|
|
433
|
+
function ClosedLine({ reason, className }: { reason: ReactNode; className?: string }) {
|
|
434
|
+
return (
|
|
435
|
+
<Card fill="inset" className={cn('flex items-start gap-3 px-4 py-3', className)}>
|
|
436
|
+
<IconLock size={16} stroke={1.5} className="mt-0.5 shrink-0 text-text-muted" aria-hidden />
|
|
437
|
+
<p className="text-body-2 text-text-secondary">{reason}</p>
|
|
438
|
+
</Card>
|
|
439
|
+
)
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function CommentBox(props: CommentBoxProps) {
|
|
443
|
+
const { closed, className } = props
|
|
444
|
+
/*
|
|
445
|
+
Closed from the start (an archived file, signed out), nothing is written here: the line alone, and no editor is
|
|
446
|
+
built to say it. Once opened, the box keeps its editor through a close, so what was written comes back with it.
|
|
447
|
+
*/
|
|
448
|
+
const [built, setBuilt] = useState(!closed)
|
|
449
|
+
if (!closed && !built) setBuilt(true)
|
|
450
|
+
if (closed && !built) return <ClosedLine reason={closed.reason} className={className} />
|
|
451
|
+
return <OpenCommentBox {...props} />
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function OpenCommentBox({
|
|
432
455
|
people,
|
|
433
456
|
references,
|
|
434
457
|
referencesChanged,
|
|
@@ -597,8 +620,11 @@ export function CommentBox({
|
|
|
597
620
|
const failed = files.filter((f) => f.state === 'failed').length
|
|
598
621
|
const ready = files.some((f) => f.state === 'ready')
|
|
599
622
|
|
|
623
|
+
// In a ConversationLayout's box: the reader's own comment brings the comments down to it as it is drawn.
|
|
624
|
+
const layout = useContext(sendsInLayout)
|
|
600
625
|
const go = useCallback(
|
|
601
626
|
(ed: Editor): boolean => {
|
|
627
|
+
layout?.sending()
|
|
602
628
|
const body = ed.getJSON()
|
|
603
629
|
const sent = files.filter((f) => f.state === 'ready')
|
|
604
630
|
const sentUnder = underOf(body)
|
|
@@ -613,6 +639,7 @@ export function CommentBox({
|
|
|
613
639
|
onSent?.(body, sent, sentUnder)
|
|
614
640
|
void answered(send(body, sent, sentUnder)).then((answer) => {
|
|
615
641
|
if (answer.accepted) return
|
|
642
|
+
layout?.refused()
|
|
616
643
|
onRefused?.()
|
|
617
644
|
if (ed.isDestroyed) {
|
|
618
645
|
// The box went away before the answer: the words wait in its draft.
|
|
@@ -633,6 +660,7 @@ export function CommentBox({
|
|
|
633
660
|
void answered(send(body, sent, sentUnder)).then((answer) => {
|
|
634
661
|
setSending(false)
|
|
635
662
|
if (!answer.accepted) {
|
|
663
|
+
layout?.refused()
|
|
636
664
|
setRefused(answer.reason)
|
|
637
665
|
return
|
|
638
666
|
}
|
|
@@ -644,7 +672,7 @@ export function CommentBox({
|
|
|
644
672
|
})
|
|
645
673
|
return false
|
|
646
674
|
},
|
|
647
|
-
[files, removed, underOf, showsAtOnce, send, draft, onSent, onRefused],
|
|
675
|
+
[files, removed, underOf, showsAtOnce, send, draft, onSent, onRefused, layout],
|
|
648
676
|
)
|
|
649
677
|
|
|
650
678
|
save.current = () => {
|
|
@@ -673,14 +701,7 @@ export function CommentBox({
|
|
|
673
701
|
}
|
|
674
702
|
}, [editor, edit])
|
|
675
703
|
|
|
676
|
-
if (closed) {
|
|
677
|
-
return (
|
|
678
|
-
<Card fill="inset" className={cn('flex items-start gap-3 px-4 py-3', className)}>
|
|
679
|
-
<IconLock size={16} stroke={1.5} className="mt-0.5 shrink-0 text-text-muted" aria-hidden />
|
|
680
|
-
<p className="text-body-2 text-text-secondary">{closed.reason}</p>
|
|
681
|
-
</Card>
|
|
682
|
-
)
|
|
683
|
-
}
|
|
704
|
+
if (closed) return <ClosedLine reason={closed.reason} className={className} />
|
|
684
705
|
|
|
685
706
|
const fileCards =
|
|
686
707
|
files.length > 0 ? (
|
package/src/ConfirmDialog.mdx
CHANGED
|
@@ -15,6 +15,10 @@ back. Built on DialogShell; the body is plain sentences in `body-2`.
|
|
|
15
15
|
- Before a deletion, an archive, a handover — anything hard to undo. The
|
|
16
16
|
confirm button is `destructive` when the action is.
|
|
17
17
|
- A non-destructive but consequential step confirms with `primary`.
|
|
18
|
+
- A safer way out than the confirm — archive rather than delete → give it as
|
|
19
|
+
`alternative`: its sentence and an outlined button after the words.
|
|
20
|
+
|
|
21
|
+
<Canvas of={ConfirmDialogStories.WithAnAlternative} />
|
|
18
22
|
|
|
19
23
|
## When not
|
|
20
24
|
|
|
@@ -41,11 +45,29 @@ import { ConfirmDialog } from '@estiva-app/ui'
|
|
|
41
45
|
)}
|
|
42
46
|
```
|
|
43
47
|
|
|
44
|
-
-
|
|
48
|
+
- `alternative` is `{ label, sentence, onClick }`. Its button sits under its
|
|
49
|
+
sentence, after your words, and waits while the confirm runs, as Cancel does.
|
|
50
|
+
It closes nothing: open what it leads to, and that takes this one's place.
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<ConfirmDialog
|
|
54
|
+
title="Delete?"
|
|
55
|
+
confirmLabel="Delete"
|
|
56
|
+
destructive
|
|
57
|
+
alternative={{ label: 'Archive instead', sentence: 'To take it out of every list and keep it readable, archive it instead.', onClick: openArchive }}
|
|
58
|
+
onConfirm={() => remove()}
|
|
59
|
+
onClose={close}
|
|
60
|
+
>
|
|
61
|
+
<p>It goes for everyone.</p>
|
|
62
|
+
</ConfirmDialog>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- While `onConfirm` runs, every answer waits. Resolving `false` keeps the
|
|
45
66
|
dialog open — your surface has said why; a resolved `void`/`true`
|
|
46
67
|
closes it.
|
|
47
|
-
- **Escape cancels; a press on the backdrop does not.**
|
|
48
|
-
`
|
|
68
|
+
- **Escape cancels; a press on the backdrop does not.** Escape and the ✕ work
|
|
69
|
+
while `onConfirm` runs, and `onClose` is not called again when it goes
|
|
70
|
+
through. This is Base UI's `AlertDialog`, through the shell's `alert`: a
|
|
49
71
|
destructive question is answered rather than clicked away. The backdrop
|
|
50
72
|
used to cancel, and that is the one behaviour stage 3 deliberately changed.
|
|
51
73
|
- It announces itself as an alert (`role="alertdialog"`), so a screen reader
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
2
|
import { useState } from 'react'
|
|
3
|
+
import { userEvent, within } from 'storybook/test'
|
|
3
4
|
import { Button } from './Button'
|
|
4
5
|
import { ConfirmDialog } from './ConfirmDialog'
|
|
5
6
|
|
|
@@ -73,3 +74,29 @@ export const DeleteAReply: Story = {
|
|
|
73
74
|
name: 'Delete a reply',
|
|
74
75
|
args: { title: 'Delete this reply?', confirmLabel: 'Delete reply', children: 'It goes from the thread for everyone.' },
|
|
75
76
|
}
|
|
77
|
+
|
|
78
|
+
const ARCHIVE_INSTEAD = {
|
|
79
|
+
label: 'Archive instead',
|
|
80
|
+
sentence: 'To take it out of every list and keep it readable, archive it instead.',
|
|
81
|
+
onClick: () => {},
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A third, safer answer under the words: archive it rather than lose it. The question it opens takes this one's place. */
|
|
85
|
+
export const WithAnAlternative: Story = {
|
|
86
|
+
name: 'With an alternative',
|
|
87
|
+
args: {
|
|
88
|
+
title: 'Delete?',
|
|
89
|
+
confirmLabel: 'Delete',
|
|
90
|
+
children: 'It goes from every list for everyone, and cannot be brought back.',
|
|
91
|
+
alternative: ARCHIVE_INSTEAD,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Delete pressed and still running: all three answers wait, the safer one too. */
|
|
96
|
+
export const AlternativeWaits: Story = {
|
|
97
|
+
name: 'Alternative waits while it deletes',
|
|
98
|
+
args: { ...WithAnAlternative.args, onConfirm: () => new Promise<void>(() => {}) },
|
|
99
|
+
play: async ({ canvasElement }) => {
|
|
100
|
+
await userEvent.click(within(canvasElement.ownerDocument.body).getByRole('button', { name: 'Delete' }))
|
|
101
|
+
},
|
|
102
|
+
}
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
* (D20) — and none of them was held by anything.
|
|
9
9
|
*/
|
|
10
10
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
11
|
-
import {
|
|
11
|
+
import { readFileSync } from 'node:fs'
|
|
12
|
+
import { join } from 'node:path'
|
|
13
|
+
import { useState } from 'react'
|
|
14
|
+
import { act, cleanup, render, screen } from '@testing-library/react'
|
|
12
15
|
import userEvent from '@testing-library/user-event'
|
|
13
16
|
import { ConfirmDialog } from './ConfirmDialog'
|
|
17
|
+
import { readIndexExports } from './registry/build'
|
|
14
18
|
|
|
15
19
|
afterEach(cleanup)
|
|
16
20
|
|
|
@@ -106,4 +110,86 @@ describe('ConfirmDialog', () => {
|
|
|
106
110
|
expect((screen.getByRole('button', { name: 'Cancel' }) as HTMLButtonElement).disabled).toBe(true)
|
|
107
111
|
release(true)
|
|
108
112
|
})
|
|
113
|
+
|
|
114
|
+
it('closed with Escape while the action runs, it is closed once, not again when the action goes through', async () => {
|
|
115
|
+
const user = userEvent.setup()
|
|
116
|
+
let release: (value: boolean) => void = () => {}
|
|
117
|
+
const onClose = vi.fn()
|
|
118
|
+
function Page() {
|
|
119
|
+
const [open, setOpen] = useState(true)
|
|
120
|
+
return open ? (
|
|
121
|
+
<Fixture
|
|
122
|
+
onConfirm={() => new Promise<boolean>((resolve) => { release = resolve })}
|
|
123
|
+
onClose={() => {
|
|
124
|
+
onClose()
|
|
125
|
+
setOpen(false)
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
) : null
|
|
129
|
+
}
|
|
130
|
+
render(<Page />)
|
|
131
|
+
await user.click(await screen.findByRole('button', { name: 'Delete' }))
|
|
132
|
+
await user.keyboard('{Escape}')
|
|
133
|
+
expect(onClose).toHaveBeenCalledOnce()
|
|
134
|
+
await act(async () => release(true))
|
|
135
|
+
expect(onClose).toHaveBeenCalledOnce()
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
describe('alternative: a third, safer answer (Peek’s Archive instead)', () => {
|
|
139
|
+
const archiveInstead = (onClick = vi.fn()) => ({
|
|
140
|
+
label: 'Archive instead',
|
|
141
|
+
sentence: 'To take it out of every list and keep it readable, archive it instead.',
|
|
142
|
+
onClick,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('is offered under the words, with its sentence, and runs on a press without confirming', async () => {
|
|
146
|
+
const user = userEvent.setup()
|
|
147
|
+
const onClick = vi.fn()
|
|
148
|
+
const onConfirm = vi.fn()
|
|
149
|
+
render(<Fixture onConfirm={onConfirm} alternative={archiveInstead(onClick)} />)
|
|
150
|
+
await user.click(await screen.findByRole('button', { name: 'Archive instead' }))
|
|
151
|
+
expect(onClick).toHaveBeenCalledOnce()
|
|
152
|
+
expect(onConfirm).not.toHaveBeenCalled()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('sits after the words, its sentence 8px above it: Peek’s outlined small button, at the start of the line', async () => {
|
|
156
|
+
render(<Fixture alternative={archiveInstead()} />)
|
|
157
|
+
const button = await screen.findByRole('button', { name: 'Archive instead' })
|
|
158
|
+
const sentence = screen.getByText('To take it out of every list and keep it readable, archive it instead.')
|
|
159
|
+
const block = button.parentElement!
|
|
160
|
+
expect(sentence.parentElement).toBe(block)
|
|
161
|
+
expect(sentence.nextElementSibling).toBe(button)
|
|
162
|
+
expect(block.className.split(' ')).toEqual(expect.arrayContaining(['flex', 'flex-col', 'items-start', 'gap-2']))
|
|
163
|
+
// Inside the dialog's words, after what the caller wrote.
|
|
164
|
+
expect(block.parentElement!.textContent!.indexOf('This cannot be undone.')).toBe(0)
|
|
165
|
+
expect(block.previousSibling?.textContent).toBe('This cannot be undone.')
|
|
166
|
+
expect(button.className).toContain('border-border-default')
|
|
167
|
+
expect(button.className).toContain('h-6')
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('waits while the confirm runs, as the other two answers do', async () => {
|
|
171
|
+
const user = userEvent.setup()
|
|
172
|
+
let release: (value: boolean) => void = () => {}
|
|
173
|
+
const onClick = vi.fn()
|
|
174
|
+
render(<Fixture onConfirm={() => new Promise<boolean>((resolve) => { release = resolve })} alternative={archiveInstead(onClick)} />)
|
|
175
|
+
await user.click(await screen.findByRole('button', { name: 'Delete' }))
|
|
176
|
+
const button = screen.getByRole('button', { name: 'Archive instead' }) as HTMLButtonElement
|
|
177
|
+
expect(button.disabled).toBe(true)
|
|
178
|
+
await user.click(button)
|
|
179
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
180
|
+
release(false)
|
|
181
|
+
await vi.waitFor(() => expect(button.disabled).toBe(false))
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('offers nothing more where there is none', async () => {
|
|
185
|
+
render(<Fixture />)
|
|
186
|
+
await screen.findByRole('alertdialog')
|
|
187
|
+
expect(screen.getAllByRole('button').map((b) => b.textContent)).toEqual(['', 'Cancel', 'Delete'])
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('its type is exported beside the dialog, for an app that builds one ahead', () => {
|
|
191
|
+
const exported = readIndexExports(readFileSync(join(process.cwd(), 'src', 'index.ts'), 'utf8'))
|
|
192
|
+
expect(exported).toContainEqual(expect.objectContaining({ name: 'ConfirmDialogAlternative', isType: true }))
|
|
193
|
+
})
|
|
194
|
+
})
|
|
109
195
|
})
|