|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +const { makeDataTable } = vi.hoisted(() => ({ |
| 4 | + makeDataTable: () => ({ |
| 5 | + columns: [{ key: "value", label: "Value" }], |
| 6 | + rows: [ |
| 7 | + { |
| 8 | + dateLabel: "Jan 1", |
| 9 | + formattedClose: "$104", |
| 10 | + formattedHigh: "$108", |
| 11 | + formattedLow: "$98", |
| 12 | + formattedOpen: "$101", |
| 13 | + formattedValue: "Value", |
| 14 | + formattedValues: { value: "Value" }, |
| 15 | + index: 0, |
| 16 | + label: "Sample", |
| 17 | + percentageLabel: "50%", |
| 18 | + xLabel: "Sample" |
| 19 | + } |
| 20 | + ] |
| 21 | + }) |
| 22 | +})); |
| 23 | + |
| 24 | +vi.mock("react-native", () => ({ |
| 25 | + Pressable: () => null, |
| 26 | + StyleSheet: { create: (styles: unknown) => styles }, |
| 27 | + Text: () => null, |
| 28 | + View: () => null |
| 29 | +})); |
| 30 | + |
| 31 | +vi.mock("@chart-kit/react-native", () => ({ |
| 32 | + BarChart: () => null, |
| 33 | + ContributionGraph: () => null, |
| 34 | + DonutChart: () => null, |
| 35 | + LineChart: () => null, |
| 36 | + PieChart: () => null, |
| 37 | + ProgressChart: () => null, |
| 38 | + ProgressRing: () => null, |
| 39 | + getBarChartDataTable: makeDataTable, |
| 40 | + getContributionGraphDataTable: makeDataTable, |
| 41 | + getLineChartDataTable: makeDataTable, |
| 42 | + getPieChartDataTable: makeDataTable, |
| 43 | + getProgressChartDataTable: makeDataTable, |
| 44 | + useChartKitTheme: () => ({ mode: "light" }) |
| 45 | +})); |
| 46 | + |
| 47 | +vi.mock("@chart-kit/react-native/pro-preview", () => ({ |
| 48 | + CandlestickChart: () => null, |
| 49 | + CombinedChart: () => null, |
| 50 | + LineChartRangeSelector: () => null, |
| 51 | + getCandlestickEmergencyClosureSessions: () => [], |
| 52 | + getCandlestickChartDataTable: makeDataTable, |
| 53 | + getCombinedChartDataTable: makeDataTable |
| 54 | +})); |
| 55 | + |
| 56 | +vi.mock("@chart-kit/svg-renderer", () => ({ |
| 57 | + SvgRect: () => null |
| 58 | +})); |
| 59 | + |
| 60 | +import { publicChartMode } from "./publicChartMode"; |
| 61 | +import { barOverviewStories } from "./stories/barOverviewStories"; |
| 62 | +import { combinedOverviewStories } from "./stories/combinedOverviewStories"; |
| 63 | +import { contributionOverviewStories } from "./stories/contributionOverviewStories"; |
| 64 | +import { financialOverviewStories } from "./stories/financialOverviewStories"; |
| 65 | +import { lineOverviewStories } from "./stories/lineOverviewStories"; |
| 66 | +import { pieOverviewStories } from "./stories/pieOverviewStories"; |
| 67 | +import { progressOverviewStories } from "./stories/progressOverviewStories"; |
| 68 | +import type { ShowcasePage, ShowcaseStory } from "./stories/storyPrimitives"; |
| 69 | + |
| 70 | +const pagesRequiringTableFallback = [ |
| 71 | + "line-charts", |
| 72 | + "bar-charts", |
| 73 | + "combined-charts", |
| 74 | + "financial-charts", |
| 75 | + "pie-donut", |
| 76 | + "progress", |
| 77 | + "heatmaps" |
| 78 | +]; |
| 79 | + |
| 80 | +const storiesWithAccessibilityDetails: ShowcaseStory[] = [ |
| 81 | + ...lineOverviewStories, |
| 82 | + ...barOverviewStories, |
| 83 | + ...combinedOverviewStories, |
| 84 | + ...financialOverviewStories, |
| 85 | + ...pieOverviewStories, |
| 86 | + ...progressOverviewStories, |
| 87 | + ...contributionOverviewStories |
| 88 | +]; |
| 89 | + |
| 90 | +const getPageStoryIds = (page: ShowcasePage) => |
| 91 | + page.storyGroups?.flatMap((group) => group.storyIds) ?? page.storyIds ?? []; |
| 92 | + |
| 93 | +describe("showcase accessibility data details", () => { |
| 94 | + it("keeps a table fallback story on every accessibility QA page", () => { |
| 95 | + for (const pageId of pagesRequiringTableFallback) { |
| 96 | + const page = publicChartMode.pages.find((item) => item.id === pageId); |
| 97 | + expect( |
| 98 | + page, |
| 99 | + `${pageId} should be part of the public chart mode` |
| 100 | + ).toBeDefined(); |
| 101 | + |
| 102 | + if (!page) { |
| 103 | + continue; |
| 104 | + } |
| 105 | + |
| 106 | + const pageStories = getPageStoryIds(page).map((storyId) => |
| 107 | + storiesWithAccessibilityDetails.find((story) => story.id === storyId) |
| 108 | + ); |
| 109 | + |
| 110 | + expect( |
| 111 | + pageStories.some((story) => story?.Details !== undefined), |
| 112 | + `${pageId} should expose at least one collapsed data details panel` |
| 113 | + ).toBe(true); |
| 114 | + } |
| 115 | + }); |
| 116 | +}); |
0 commit comments