|
13 | 13 | * column is the 概览 tab's summary rail (objectstack#35596). The stored order |
14 | 14 | * orders the tab row; a hidden list's tab waits at the end of 「更多 N ▾」; |
15 | 15 | * the rail's foot keeps 「已隐藏 N 个 · 显示」, 「恢复默认顺序」 and the |
16 | | - * changed-default hint. The card stack's ⠿ handle, ⌥↑ / ⌥↓, 隐藏 and the |
17 | | - * 「新」 badge were the related cards' chrome and leave the page with them |
18 | | - * (`RelatedCardStack`, no longer drawn by the page). This file carries over |
| 16 | + * changed-default hint. The card stack's ⠿ handle, ⌥↑ / ⌥↓ and the 「新」 |
| 17 | + * badge left the page with the related cards; moving and hiding came back on |
| 18 | + * the tabs (objectstack#35783): an open list's tab is its menu — 「左移」, |
| 19 | + * 「右移」, 「隐藏」 — and 「更多」 ends with 「恢复默认顺序」 while the |
| 20 | + * arrangement is not the default, in a drawer too. This file carries over |
19 | 21 | * `RelatedCardStack-27055.test.tsx`; the merge rules themselves stay pinned in |
20 | 22 | * `synth/__tests__/relatedArrangement-27055.test.ts`. |
21 | 23 | */ |
22 | 24 |
|
23 | 25 | import * as React from 'react'; |
24 | 26 | import { describe, it, expect, vi, afterEach } from 'vitest'; |
25 | | -import { render, cleanup, fireEvent } from '@testing-library/react'; |
| 27 | +import { render, cleanup, fireEvent, screen } from '@testing-library/react'; |
| 28 | +import userEvent from '@testing-library/user-event'; |
26 | 29 | import { RelatedListCompactContext, RelatedListEnlargedContext } from '../relatedListCompact'; |
27 | 30 |
|
28 | 31 | vi.mock('@object-ui/react', async (importOriginal) => ({ |
@@ -184,3 +187,131 @@ describe('a related list\'s tab — ?related= (objectstack#27055, Target 9; obje |
184 | 187 | expect(container.querySelector('[data-record-columns]')).not.toBeNull(); |
185 | 188 | }); |
186 | 189 | }); |
| 190 | + |
| 191 | +describe('a related tab\'s menu and 「更多」\'s reset (objectstack#35783)', () => { |
| 192 | + /** A host holding the store and the open tab, as the record page does. */ |
| 193 | + function TabHost({ initial, onWrite, rail, columns = columnsOf() }: { |
| 194 | + initial?: RelatedArrangement; |
| 195 | + onWrite?: (v: RelatedArrangement) => void; |
| 196 | + rail?: boolean; |
| 197 | + columns?: ReturnType<typeof columnsOf>; |
| 198 | + }) { |
| 199 | + const [arrangement, setArrangement] = React.useState<RelatedArrangement | undefined>(initial); |
| 200 | + const [open, setOpen] = React.useState<string | undefined>(undefined); |
| 201 | + return ( |
| 202 | + <RecordPageColumns |
| 203 | + tier="wide" |
| 204 | + columns={columns} |
| 205 | + rail={rail} |
| 206 | + relatedArrangement={arrangement} |
| 207 | + onRelatedArrangementChange={(next) => { |
| 208 | + onWrite?.(next); |
| 209 | + setArrangement(next); |
| 210 | + }} |
| 211 | + enlargedRelated={open} |
| 212 | + onEnlargeRelated={setOpen} |
| 213 | + onCloseEnlargedRelated={() => setOpen(undefined)} |
| 214 | + /> |
| 215 | + ); |
| 216 | + } |
| 217 | + const tabEl = (id: string) => document.querySelector(`[role="tab"][data-record-tab="${id}"]`) as HTMLElement; |
| 218 | + /** Open `id`'s tab, then its menu, and choose `edit`. */ |
| 219 | + async function arrange(user: ReturnType<typeof userEvent.setup>, id: string, edit: string) { |
| 220 | + if (tabEl(id).getAttribute('aria-selected') !== 'true') await user.click(tabEl(id)); |
| 221 | + await user.click(tabEl(id)); |
| 222 | + await user.click(await screen.findByRole('menuitem', { name: new RegExp(edit) })); |
| 223 | + } |
| 224 | + |
| 225 | + it('「左移」 and 「右移」 move the open list one place and keep it; at either end the way out is disabled', async () => { |
| 226 | + const user = userEvent.setup(); |
| 227 | + const onWrite = vi.fn(); |
| 228 | + render(<TabHost onWrite={onWrite} />); |
| 229 | + await arrange(user, 'note.parent_id', 'Move left'); |
| 230 | + expect(listTabs()).toEqual(['note.parent_id', 'task.lead_id', 'call.lead_id']); |
| 231 | + expect(onWrite.mock.calls.at(-1)![0].order).toEqual(['note.parent_id', 'task.lead_id', 'call.lead_id']); |
| 232 | + await arrange(user, 'task.lead_id', 'Move right'); |
| 233 | + expect(listTabs()).toEqual(['note.parent_id', 'call.lead_id', 'task.lead_id']); |
| 234 | + // The last list cannot go further right; CONTROL, it can go left. |
| 235 | + await user.click(tabEl('task.lead_id')); |
| 236 | + expect((await screen.findByRole('menuitem', { name: /Move right/ })).getAttribute('aria-disabled')).toBe('true'); |
| 237 | + expect(screen.getByRole('menuitem', { name: /Move left/ }).hasAttribute('aria-disabled')).toBe(false); |
| 238 | + }); |
| 239 | + |
| 240 | + it('「隐藏」 takes the open list off the row into 「更多」\'s hidden lists and returns to 概览', async () => { |
| 241 | + const user = userEvent.setup(); |
| 242 | + const onWrite = vi.fn(); |
| 243 | + const { container } = render(<TabHost onWrite={onWrite} />); |
| 244 | + await arrange(user, 'note.parent_id', 'Hide'); |
| 245 | + expect(listTabs()).toEqual(['task.lead_id', 'call.lead_id']); |
| 246 | + expect(onWrite.mock.calls.at(-1)![0].hidden).toEqual(['note.parent_id']); |
| 247 | + expect(tabEl('overview').getAttribute('aria-selected')).toBe('true'); |
| 248 | + expect(container.querySelector('[data-related-enlarged]')).toBeNull(); |
| 249 | + await user.click(document.querySelector('[data-record-tab-more]') as HTMLElement); |
| 250 | + const hiddenItem = (await screen.findAllByRole('menuitem')).find((el) => el.hasAttribute('data-record-tab-hidden')); |
| 251 | + expect(hiddenItem?.getAttribute('data-record-tab-menu-item')).toBe('note.parent_id'); |
| 252 | + }); |
| 253 | + |
| 254 | + it('「更多」 ends with 「恢复默认顺序」 while the arrangement is not the default: the default order, every list shown — in a drawer too', async () => { |
| 255 | + const user = userEvent.setup(); |
| 256 | + const onWrite = vi.fn(); |
| 257 | + const moved = editRelatedArrangement(DEFAULT, undefined, { kind: 'move', id: 'call.lead_id', to: 0 }, Date.now()); |
| 258 | + const both = editRelatedArrangement(DEFAULT, moved, { kind: 'hide', id: 'task.lead_id' }, Date.now()); |
| 259 | + const { container } = render(<TabHost initial={both} onWrite={onWrite} rail={false} />); |
| 260 | + // A drawer: no rail, so no foot line — 「更多」 is the one way back. |
| 261 | + expect(container.querySelector('[data-related-foot-line]')).toBeNull(); |
| 262 | + expect(listTabs()).toEqual(['call.lead_id', 'note.parent_id']); |
| 263 | + await user.click(document.querySelector('[data-record-tab-more]') as HTMLElement); |
| 264 | + await user.click(await screen.findByRole('menuitem', { name: 'Restore default order' })); |
| 265 | + expect(listTabs()).toEqual(DEFAULT); |
| 266 | + expect(onWrite.mock.calls.at(-1)![0]).toMatchObject({ order: [], hidden: [] }); |
| 267 | + // CONTROL: in the default arrangement there is nothing to restore, and a row that fits draws no 「更多」. |
| 268 | + expect(document.querySelector('[data-record-tab-more]')).toBeNull(); |
| 269 | + }); |
| 270 | + |
| 271 | + it('a row moved but nothing hidden still offers the reset, under a bare 「更多」', async () => { |
| 272 | + const user = userEvent.setup(); |
| 273 | + const moved = editRelatedArrangement(DEFAULT, undefined, { kind: 'move', id: 'call.lead_id', to: 0 }, Date.now()); |
| 274 | + render(<TabHost initial={moved} />); |
| 275 | + const trigger = document.querySelector('[data-record-tab-more]') as HTMLElement; |
| 276 | + expect(trigger.textContent).toBe('More'); |
| 277 | + await user.click(trigger); |
| 278 | + expect((await screen.findAllByRole('menuitem')).map((el) => el.textContent)).toEqual(['Restore default order']); |
| 279 | + }); |
| 280 | + |
| 281 | + it('概览, 附件, 审批 and 动态 are fixed: open, they have no menu; CONTROL, an open list\'s tab has one', async () => { |
| 282 | + const user = userEvent.setup(); |
| 283 | + const columns = buildDefaultPageColumns( |
| 284 | + buildDefaultPageSchema({ name: 'lead', fields: {}, enable: { files: true } } as any, { |
| 285 | + related: RELATED, |
| 286 | + hideDiscussion: false, |
| 287 | + approvals: { count: 1, node: { approvals: { available: true, requests: [{ id: 'r1' }] } } }, |
| 288 | + }), |
| 289 | + )!; |
| 290 | + render(<TabHost columns={columns} />); |
| 291 | + const fixed = ['overview', 'attachments', 'approvals', 'timeline']; |
| 292 | + for (const id of fixed) { |
| 293 | + expect(tabEl(id), id).not.toBeNull(); |
| 294 | + if (tabEl(id).getAttribute('aria-selected') !== 'true') await user.click(tabEl(id)); |
| 295 | + expect(tabEl(id).getAttribute('aria-selected')).toBe('true'); |
| 296 | + await user.click(tabEl(id)); |
| 297 | + expect(tabEl(id).hasAttribute('aria-haspopup'), id).toBe(false); |
| 298 | + expect(document.querySelector('[data-record-tab-arrange-menu]'), id).toBeNull(); |
| 299 | + } |
| 300 | + await user.click(tabEl('call.lead_id')); |
| 301 | + await user.click(tabEl('call.lead_id')); |
| 302 | + expect(tabEl('call.lead_id').getAttribute('aria-haspopup')).toBe('menu'); |
| 303 | + expect(document.querySelector('[data-record-tab-arrange-menu="call.lead_id"]')).not.toBeNull(); |
| 304 | + }); |
| 305 | + |
| 306 | + it('a list\'s tab not yet open opens on its first click and on Enter, with no menu', async () => { |
| 307 | + const user = userEvent.setup(); |
| 308 | + render(<TabHost />); |
| 309 | + await user.click(tabEl('note.parent_id')); |
| 310 | + expect(tabEl('note.parent_id').getAttribute('aria-selected')).toBe('true'); |
| 311 | + expect(document.querySelector('[data-record-tab-arrange-menu]')).toBeNull(); |
| 312 | + tabEl('call.lead_id').focus(); |
| 313 | + await user.keyboard('{Enter}'); |
| 314 | + expect(tabEl('call.lead_id').getAttribute('aria-selected')).toBe('true'); |
| 315 | + expect(document.querySelector('[data-record-tab-arrange-menu]')).toBeNull(); |
| 316 | + }); |
| 317 | +}); |
0 commit comments