|
| 1 | +import { expect, userEvent, within } from 'storybook/test'; |
| 2 | +import { createGridRowVisibilitySummaryComponent } from '../../../../packages/core-ui/js/gui_components/data-grid-editor/grid-row-visibility-summary/index.js'; |
| 3 | + |
| 4 | +function renderGridRowVisibilitySummaryStory(args) { |
| 5 | + const root = document.createElement('section'); |
| 6 | + root.style.display = 'flex'; |
| 7 | + root.style.flexDirection = 'column'; |
| 8 | + root.style.gap = '0.75rem'; |
| 9 | + root.style.padding = '0.75rem'; |
| 10 | + root.style.background = 'var(--panel-bg)'; |
| 11 | + root.style.color = 'var(--page-text)'; |
| 12 | + const statusRoot = document.createElement('div'); |
| 13 | + const controlsRoot = document.createElement('div'); |
| 14 | + controlsRoot.style.display = 'flex'; |
| 15 | + controlsRoot.style.flexWrap = 'wrap'; |
| 16 | + controlsRoot.style.gap = '0.5rem'; |
| 17 | + controlsRoot.innerHTML = ` |
| 18 | + <button type="button" data-action="show-filtered">Show Filtered Summary</button> |
| 19 | + <button type="button" data-action="clear-filtered">Clear Filtered Summary</button> |
| 20 | + `; |
| 21 | + |
| 22 | + root.appendChild(statusRoot); |
| 23 | + root.appendChild(controlsRoot); |
| 24 | + |
| 25 | + const component = createGridRowVisibilitySummaryComponent({ |
| 26 | + root: statusRoot, |
| 27 | + documentObj: document, |
| 28 | + props: { |
| 29 | + totalRowCount: args.totalRowCount, |
| 30 | + visibleRowCount: args.visibleRowCount, |
| 31 | + hasActiveFilters: args.hasActiveFilters, |
| 32 | + }, |
| 33 | + }); |
| 34 | + |
| 35 | + controlsRoot.querySelector('[data-action="show-filtered"]')?.addEventListener('click', () => { |
| 36 | + component.update({ |
| 37 | + totalRowCount: 8, |
| 38 | + visibleRowCount: 3, |
| 39 | + hasActiveFilters: true, |
| 40 | + }); |
| 41 | + }); |
| 42 | + controlsRoot.querySelector('[data-action="clear-filtered"]')?.addEventListener('click', () => { |
| 43 | + component.update({ |
| 44 | + totalRowCount: args.totalRowCount, |
| 45 | + visibleRowCount: args.totalRowCount, |
| 46 | + hasActiveFilters: false, |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + root.__storybookCleanup = () => component.destroy(); |
| 51 | + return root; |
| 52 | +} |
| 53 | + |
| 54 | +const meta = { |
| 55 | + title: 'Data Grid Editor/Grid Row Visibility Summary', |
| 56 | + tags: ['autodocs'], |
| 57 | + parameters: { |
| 58 | + docs: { |
| 59 | + description: { |
| 60 | + component: |
| 61 | + 'GridRowVisibilitySummary is the extracted MVC status control for the Data Grid Editor row totals. It shows the always-visible total row count and conditionally adds the filtered visible count when the grid is actively filtered.', |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + args: { |
| 66 | + totalRowCount: 8, |
| 67 | + visibleRowCount: 8, |
| 68 | + hasActiveFilters: false, |
| 69 | + }, |
| 70 | + render: renderGridRowVisibilitySummaryStory, |
| 71 | +}; |
| 72 | + |
| 73 | +export default meta; |
| 74 | + |
| 75 | +export const TotalOnly = { |
| 76 | + parameters: { |
| 77 | + docs: { |
| 78 | + description: { |
| 79 | + story: |
| 80 | + 'Shows the default summary state with only the total row count visible. Reviewers should see the same status text that appears beneath the full data-grid component when no filters are active.', |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + play: async ({ canvasElement }) => { |
| 85 | + const canvas = within(canvasElement); |
| 86 | + await expect(canvas.getByRole('status')).toHaveTextContent('Total rows: 8'); |
| 87 | + }, |
| 88 | +}; |
| 89 | + |
| 90 | +export const FilteredVisible = { |
| 91 | + args: { |
| 92 | + totalRowCount: 8, |
| 93 | + visibleRowCount: 3, |
| 94 | + hasActiveFilters: true, |
| 95 | + }, |
| 96 | + parameters: { |
| 97 | + docs: { |
| 98 | + description: { |
| 99 | + story: |
| 100 | + 'Shows the filtered state. Reviewers should see both the total row count and the filtered visible count, matching the app behavior after a global or column filter is applied.', |
| 101 | + }, |
| 102 | + }, |
| 103 | + }, |
| 104 | + play: async ({ canvasElement }) => { |
| 105 | + const canvas = within(canvasElement); |
| 106 | + await expect(canvas.getByRole('status')).toHaveTextContent('Total rows: 8 | Filtered Visible: 3'); |
| 107 | + }, |
| 108 | +}; |
| 109 | + |
| 110 | +export const InteractiveStateChange = { |
| 111 | + parameters: { |
| 112 | + docs: { |
| 113 | + description: { |
| 114 | + story: |
| 115 | + 'Demonstrates the component state transition. Try the buttons to switch between the filtered and unfiltered summaries and confirm the status text updates without the full grid story around it.', |
| 116 | + }, |
| 117 | + }, |
| 118 | + }, |
| 119 | + play: async ({ canvasElement }) => { |
| 120 | + const canvas = within(canvasElement); |
| 121 | + await userEvent.click(canvas.getByRole('button', { name: 'Show Filtered Summary' })); |
| 122 | + await expect(canvas.getByRole('status')).toHaveTextContent('Total rows: 8 | Filtered Visible: 3'); |
| 123 | + await userEvent.click(canvas.getByRole('button', { name: 'Clear Filtered Summary' })); |
| 124 | + await expect(canvas.getByRole('status')).toHaveTextContent('Total rows: 8'); |
| 125 | + }, |
| 126 | +}; |
0 commit comments