|
| 1 | +/** |
| 2 | + * ObjectUI |
| 3 | + * Copyright (c) 2024-present ObjectStack Inc. |
| 4 | + * |
| 5 | + * This source code is licensed under the MIT license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * objectstack#27504 — a packaged action the installation switched off is not |
| 11 | + * offered on the record header (`page:header`) or in an `action:bar`. |
| 12 | + * |
| 13 | + * The platform serves the switched-off names beside the object document and |
| 14 | + * the data layer stamps those entries (`markSwitchedOffActions`); both |
| 15 | + * surfaces ask `isActionSwitchedOff` beside their capability gate. Before this, |
| 16 | + * the button stayed live and a click only met the door's 409. |
| 17 | + */ |
| 18 | + |
| 19 | +import { describe, it, expect } from 'vitest'; |
| 20 | +import { render, screen } from '@testing-library/react'; |
| 21 | +import { ComponentRegistry, markSwitchedOffActions } from '@object-ui/core'; |
| 22 | +import { ActionProvider } from '@object-ui/react'; |
| 23 | +// The renderers register on import; this file is not in the dom-heavy set. |
| 24 | +import '../renderers'; |
| 25 | + |
| 26 | +function Node({ schema }: { schema: any }) { |
| 27 | + const Component = ComponentRegistry.get(schema.type); |
| 28 | + if (!Component) throw new Error(`${schema.type} not registered`); |
| 29 | + // eslint-disable-next-line react-hooks/static-components -- registry component is stable |
| 30 | + return <Component schema={schema} />; |
| 31 | +} |
| 32 | + |
| 33 | +const served = (switchedOff: string[]) => |
| 34 | + markSwitchedOffActions( |
| 35 | + { |
| 36 | + name: 'showcase_task', |
| 37 | + actions: [ |
| 38 | + { name: 'showcase_mark_done', label: 'Mark Done', type: 'script', locations: ['record_header'] }, |
| 39 | + { name: 'showcase_log_time', label: 'Log Time', type: 'script', locations: ['record_header'] }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + switchedOff, |
| 43 | + ).actions; |
| 44 | + |
| 45 | +const renderIn = (schema: any) => |
| 46 | + render(<ActionProvider context={{ user: { id: 'u1' } } as any}><Node schema={schema} /></ActionProvider>); |
| 47 | + |
| 48 | +const markDone = () => screen.queryByRole('button', { name: /Mark Done/i }); |
| 49 | + |
| 50 | +describe.each([ |
| 51 | + ['page:header', (actions: any[]) => ({ type: 'page:header', title: 'Task', actions })], |
| 52 | + ['action:bar', (actions: any[]) => ({ type: 'action:bar', location: 'record_header', actions })], |
| 53 | +])('%s — switched-off packaged action (objectstack#27504)', (_type, schemaOf) => { |
| 54 | + it('does not offer an action the platform served as switched off', () => { |
| 55 | + renderIn(schemaOf(served(['showcase_mark_done']))); |
| 56 | + expect(markDone()).toBeNull(); |
| 57 | + // A filter, not a blank bar: its sibling still renders. |
| 58 | + expect(screen.getByRole('button', { name: /Log Time/i })).toBeTruthy(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('offers it again once the served state no longer names it', () => { |
| 62 | + renderIn(schemaOf(served([]))); |
| 63 | + expect(markDone()).toBeTruthy(); |
| 64 | + }); |
| 65 | +}); |
0 commit comments