@terreno/ui 57.2.0 → 57.4.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/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +116 -35
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +215 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +278 -47
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +81 -44
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextField.js +83 -6
- package/dist/TextField.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +30 -13
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +53 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +51 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +46 -18
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +273 -0
- package/src/Button.tsx +163 -50
- package/src/Common.ts +219 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.test.tsx +55 -0
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +623 -160
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +84 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/Field.test.tsx +18 -0
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +803 -0
- package/src/GPTChat.tsx +177 -87
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +112 -11
- package/src/MarkdownView.tsx +197 -150
- package/src/MediaQuery.ts +30 -34
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +82 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +29 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +48 -14
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +134 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/login/loginTypes.ts +2 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
import {beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import {DateTime} from "luxon";
|
|
5
|
+
import React, {useCallback, useState} from "react";
|
|
6
|
+
import {Linking, Text} from "react-native";
|
|
7
|
+
import {AnnouncementNavigator} from "./AnnouncementNavigator";
|
|
8
|
+
import {
|
|
9
|
+
buildFrequencyStorageKey,
|
|
10
|
+
resetFrequencySessionStateForTests,
|
|
11
|
+
} from "./announcementFrequency";
|
|
12
|
+
import {Box} from "./Box";
|
|
13
|
+
import {TextField} from "./TextField";
|
|
14
|
+
import {renderWithTheme} from "./test-utils";
|
|
15
|
+
import {Unifier} from "./Unifier";
|
|
16
|
+
import {
|
|
17
|
+
type AnnouncementPublic,
|
|
18
|
+
type PendingAnnouncementsResponse,
|
|
19
|
+
useAnnouncements,
|
|
20
|
+
} from "./useAnnouncements";
|
|
21
|
+
|
|
22
|
+
const makeAnnouncement = (overrides: Partial<AnnouncementPublic> = {}): AnnouncementPublic => ({
|
|
23
|
+
body: "## Update\n\nWe shipped announcements.",
|
|
24
|
+
displayMode: "modal",
|
|
25
|
+
id: "announcement-1",
|
|
26
|
+
priority: 1,
|
|
27
|
+
requiresAcknowledgement: true,
|
|
28
|
+
title: "What is new",
|
|
29
|
+
version: 1,
|
|
30
|
+
...overrides,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const createMockApi = (
|
|
34
|
+
pending: PendingAnnouncementsResponse | (() => PendingAnnouncementsResponse),
|
|
35
|
+
refetchOverride?: () => Promise<void>,
|
|
36
|
+
feedItems: AnnouncementPublic[] = [],
|
|
37
|
+
clickUnwrap: () => Promise<unknown> = async () => ({data: {recorded: true}})
|
|
38
|
+
) => {
|
|
39
|
+
const getPending =
|
|
40
|
+
typeof pending === "function" ? pending : (): PendingAnnouncementsResponse => pending;
|
|
41
|
+
const refetch = refetchOverride ?? mock(() => Promise.resolve());
|
|
42
|
+
const acknowledgeMutation = mock(() => ({
|
|
43
|
+
unwrap: mock(() => Promise.resolve({data: {acknowledged: true}})),
|
|
44
|
+
}));
|
|
45
|
+
const impressionMutation = mock(() => ({
|
|
46
|
+
unwrap: mock(() => Promise.resolve({data: {recorded: true}})),
|
|
47
|
+
}));
|
|
48
|
+
const clickMutation = mock(() => ({
|
|
49
|
+
unwrap: mock(clickUnwrap),
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
const innerApi = {
|
|
53
|
+
injectEndpoints: mock((_config: unknown) => ({
|
|
54
|
+
useAcknowledgeAnnouncementMutation: mock(() => [
|
|
55
|
+
acknowledgeMutation,
|
|
56
|
+
{error: undefined, isLoading: false},
|
|
57
|
+
]),
|
|
58
|
+
useGetAnnouncementFeedQuery: mock(() => ({
|
|
59
|
+
data: {data: feedItems},
|
|
60
|
+
error: undefined,
|
|
61
|
+
isLoading: false,
|
|
62
|
+
refetch,
|
|
63
|
+
})),
|
|
64
|
+
useGetPendingAnnouncementsQuery: mock(() => ({
|
|
65
|
+
data: {data: getPending()},
|
|
66
|
+
error: undefined,
|
|
67
|
+
isLoading: false,
|
|
68
|
+
refetch,
|
|
69
|
+
})),
|
|
70
|
+
useRecordAnnouncementClickMutation: mock(() => [
|
|
71
|
+
clickMutation,
|
|
72
|
+
{error: undefined, isLoading: false},
|
|
73
|
+
]),
|
|
74
|
+
useRecordAnnouncementImpressionMutation: mock(() => [
|
|
75
|
+
impressionMutation,
|
|
76
|
+
{error: undefined, isLoading: false},
|
|
77
|
+
]),
|
|
78
|
+
})),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
acknowledgeMutation,
|
|
83
|
+
api: {
|
|
84
|
+
enhanceEndpoints: mock(() => innerApi),
|
|
85
|
+
},
|
|
86
|
+
clickMutation,
|
|
87
|
+
impressionMutation,
|
|
88
|
+
refetch,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const announcementQueue: PendingAnnouncementsResponse[] = [
|
|
93
|
+
{
|
|
94
|
+
current: makeAnnouncement({id: "announcement-1", title: "First update"}),
|
|
95
|
+
remainingCount: 1,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
current: makeAnnouncement({id: "announcement-2", title: "Second update"}),
|
|
99
|
+
remainingCount: 0,
|
|
100
|
+
},
|
|
101
|
+
{current: null, remainingCount: 0},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
const waitForFrequencyCheck = async (): Promise<void> => {
|
|
105
|
+
await act(async () => {
|
|
106
|
+
await Promise.resolve();
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const createNavigatorStorageMock = (): {
|
|
111
|
+
getItem: ReturnType<typeof mock>;
|
|
112
|
+
setItem: ReturnType<typeof mock>;
|
|
113
|
+
} => {
|
|
114
|
+
const store = new Map<string, unknown>();
|
|
115
|
+
return {
|
|
116
|
+
getItem: mock(async (key: string) => store.get(key) ?? null),
|
|
117
|
+
setItem: mock(async (key: string, value: unknown) => {
|
|
118
|
+
store.set(key, value);
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
describe("AnnouncementNavigator", () => {
|
|
124
|
+
beforeEach(() => {
|
|
125
|
+
resetFrequencySessionStateForTests();
|
|
126
|
+
const storage = createNavigatorStorageMock();
|
|
127
|
+
Unifier.storage.getItem = storage.getItem;
|
|
128
|
+
Unifier.storage.setItem = storage.setItem;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("renders children when no announcements are pending", () => {
|
|
132
|
+
const {api} = createMockApi({current: null, remainingCount: 0});
|
|
133
|
+
const result = renderWithTheme(
|
|
134
|
+
<AnnouncementNavigator api={api}>
|
|
135
|
+
<Box testID="app-content">
|
|
136
|
+
<Text>App</Text>
|
|
137
|
+
</Box>
|
|
138
|
+
</AnnouncementNavigator>
|
|
139
|
+
);
|
|
140
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("hides children while a modal announcement is pending", async () => {
|
|
144
|
+
const {api, impressionMutation} = createMockApi({
|
|
145
|
+
current: makeAnnouncement({displayMode: "modal"}),
|
|
146
|
+
remainingCount: 0,
|
|
147
|
+
});
|
|
148
|
+
const result = renderWithTheme(
|
|
149
|
+
<AnnouncementNavigator api={api}>
|
|
150
|
+
<Box testID="app-content">
|
|
151
|
+
<Text>App</Text>
|
|
152
|
+
</Box>
|
|
153
|
+
</AnnouncementNavigator>
|
|
154
|
+
);
|
|
155
|
+
await waitForFrequencyCheck();
|
|
156
|
+
expect(result.getByTestId("announcement-screen")).toBeTruthy();
|
|
157
|
+
assert.isNull(result.queryByTestId("app-content"));
|
|
158
|
+
expect(impressionMutation).toHaveBeenCalledTimes(1);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("refetches after acknowledge when more announcements remain", async () => {
|
|
162
|
+
const {api, refetch, acknowledgeMutation} = createMockApi({
|
|
163
|
+
current: makeAnnouncement({id: "announcement-1", title: "First"}),
|
|
164
|
+
remainingCount: 1,
|
|
165
|
+
});
|
|
166
|
+
const result = renderWithTheme(
|
|
167
|
+
<AnnouncementNavigator api={api}>
|
|
168
|
+
<Box testID="app-content">
|
|
169
|
+
<Text>App</Text>
|
|
170
|
+
</Box>
|
|
171
|
+
</AnnouncementNavigator>
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
await waitForFrequencyCheck();
|
|
175
|
+
await act(async () => {
|
|
176
|
+
fireEvent.press(result.getByText("Got it"));
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
expect(acknowledgeMutation).toHaveBeenCalled();
|
|
180
|
+
expect(refetch).toHaveBeenCalled();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("shows the next announcement after refetch advances the queue", async () => {
|
|
184
|
+
const QueueHarness: React.FC = () => {
|
|
185
|
+
const [queueIndex, setQueueIndex] = useState(0);
|
|
186
|
+
const refetch = useCallback(async (): Promise<void> => {
|
|
187
|
+
setQueueIndex((currentIndex) => Math.min(currentIndex + 1, announcementQueue.length - 1));
|
|
188
|
+
}, []);
|
|
189
|
+
const {api} = createMockApi(() => announcementQueue[queueIndex], refetch);
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<AnnouncementNavigator api={api} frequency={{maxInterruptionsPerSession: 5}}>
|
|
193
|
+
<Box testID="app-content">
|
|
194
|
+
<Text>App</Text>
|
|
195
|
+
</Box>
|
|
196
|
+
</AnnouncementNavigator>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const result = renderWithTheme(<QueueHarness />);
|
|
201
|
+
await waitForFrequencyCheck();
|
|
202
|
+
expect(result.getByText("First update")).toBeTruthy();
|
|
203
|
+
|
|
204
|
+
await act(async () => {
|
|
205
|
+
fireEvent.press(result.getByText("Got it"));
|
|
206
|
+
});
|
|
207
|
+
await waitForFrequencyCheck();
|
|
208
|
+
|
|
209
|
+
expect(result.getByText("Second update")).toBeTruthy();
|
|
210
|
+
|
|
211
|
+
await act(async () => {
|
|
212
|
+
fireEvent.press(result.getByText("Got it"));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
216
|
+
expect(result.queryByTestId("announcement-screen")).toBeNull();
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("renders a loading spinner while pending announcements load", () => {
|
|
220
|
+
const innerApi = {
|
|
221
|
+
injectEndpoints: mock(() => ({
|
|
222
|
+
useAcknowledgeAnnouncementMutation: mock(() => [
|
|
223
|
+
mock(),
|
|
224
|
+
{error: undefined, isLoading: false},
|
|
225
|
+
]),
|
|
226
|
+
useGetAnnouncementFeedQuery: mock(() => ({
|
|
227
|
+
data: undefined,
|
|
228
|
+
error: undefined,
|
|
229
|
+
isLoading: true,
|
|
230
|
+
refetch: mock(() => Promise.resolve()),
|
|
231
|
+
})),
|
|
232
|
+
useGetPendingAnnouncementsQuery: mock(() => ({
|
|
233
|
+
data: undefined,
|
|
234
|
+
error: undefined,
|
|
235
|
+
isLoading: true,
|
|
236
|
+
refetch: mock(() => Promise.resolve()),
|
|
237
|
+
})),
|
|
238
|
+
useRecordAnnouncementClickMutation: mock(() => [
|
|
239
|
+
mock(),
|
|
240
|
+
{error: undefined, isLoading: false},
|
|
241
|
+
]),
|
|
242
|
+
useRecordAnnouncementImpressionMutation: mock(() => [
|
|
243
|
+
mock(),
|
|
244
|
+
{error: undefined, isLoading: false},
|
|
245
|
+
]),
|
|
246
|
+
})),
|
|
247
|
+
};
|
|
248
|
+
const result = renderWithTheme(
|
|
249
|
+
<AnnouncementNavigator api={{enhanceEndpoints: mock(() => innerApi)}}>
|
|
250
|
+
<Box testID="app-content">
|
|
251
|
+
<Text>App</Text>
|
|
252
|
+
</Box>
|
|
253
|
+
</AnnouncementNavigator>
|
|
254
|
+
);
|
|
255
|
+
expect(result.getByTestId("announcement-navigator-loading")).toBeTruthy();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("shows retry UI for recoverable pending errors", () => {
|
|
259
|
+
const refetch = mock(() => Promise.resolve());
|
|
260
|
+
const innerApi = {
|
|
261
|
+
injectEndpoints: mock(() => ({
|
|
262
|
+
useAcknowledgeAnnouncementMutation: mock(() => [
|
|
263
|
+
mock(),
|
|
264
|
+
{error: undefined, isLoading: false},
|
|
265
|
+
]),
|
|
266
|
+
useGetAnnouncementFeedQuery: mock(() => ({
|
|
267
|
+
data: {data: []},
|
|
268
|
+
error: undefined,
|
|
269
|
+
isLoading: false,
|
|
270
|
+
refetch,
|
|
271
|
+
})),
|
|
272
|
+
useGetPendingAnnouncementsQuery: mock(() => ({
|
|
273
|
+
data: undefined,
|
|
274
|
+
error: {status: 500},
|
|
275
|
+
isLoading: false,
|
|
276
|
+
refetch,
|
|
277
|
+
})),
|
|
278
|
+
useRecordAnnouncementClickMutation: mock(() => [
|
|
279
|
+
mock(),
|
|
280
|
+
{error: undefined, isLoading: false},
|
|
281
|
+
]),
|
|
282
|
+
useRecordAnnouncementImpressionMutation: mock(() => [
|
|
283
|
+
mock(),
|
|
284
|
+
{error: undefined, isLoading: false},
|
|
285
|
+
]),
|
|
286
|
+
})),
|
|
287
|
+
};
|
|
288
|
+
const onError = mock(() => undefined);
|
|
289
|
+
const result = renderWithTheme(
|
|
290
|
+
<AnnouncementNavigator api={{enhanceEndpoints: mock(() => innerApi)}} onError={onError}>
|
|
291
|
+
<Box testID="app-content">
|
|
292
|
+
<Text>App</Text>
|
|
293
|
+
</Box>
|
|
294
|
+
</AnnouncementNavigator>
|
|
295
|
+
);
|
|
296
|
+
expect(result.getByTestId("announcement-navigator-error")).toBeTruthy();
|
|
297
|
+
expect(onError).toHaveBeenCalled();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("renders children when only the feed request fails", () => {
|
|
301
|
+
const innerApi = {
|
|
302
|
+
injectEndpoints: mock(() => ({
|
|
303
|
+
useAcknowledgeAnnouncementMutation: mock(() => [
|
|
304
|
+
mock(),
|
|
305
|
+
{error: undefined, isLoading: false},
|
|
306
|
+
]),
|
|
307
|
+
useGetAnnouncementFeedQuery: mock(() => ({
|
|
308
|
+
data: undefined,
|
|
309
|
+
error: {status: 500},
|
|
310
|
+
isLoading: false,
|
|
311
|
+
refetch: mock(() => Promise.resolve()),
|
|
312
|
+
})),
|
|
313
|
+
useGetPendingAnnouncementsQuery: mock(() => ({
|
|
314
|
+
data: {data: {current: null, remainingCount: 0}},
|
|
315
|
+
error: undefined,
|
|
316
|
+
isLoading: false,
|
|
317
|
+
refetch: mock(() => Promise.resolve()),
|
|
318
|
+
})),
|
|
319
|
+
useRecordAnnouncementClickMutation: mock(() => [
|
|
320
|
+
mock(),
|
|
321
|
+
{error: undefined, isLoading: false},
|
|
322
|
+
]),
|
|
323
|
+
useRecordAnnouncementImpressionMutation: mock(() => [
|
|
324
|
+
mock(),
|
|
325
|
+
{error: undefined, isLoading: false},
|
|
326
|
+
]),
|
|
327
|
+
})),
|
|
328
|
+
};
|
|
329
|
+
const result = renderWithTheme(
|
|
330
|
+
<AnnouncementNavigator api={{enhanceEndpoints: mock(() => innerApi)}}>
|
|
331
|
+
<Box testID="app-content">
|
|
332
|
+
<Text>App</Text>
|
|
333
|
+
</Box>
|
|
334
|
+
</AnnouncementNavigator>
|
|
335
|
+
);
|
|
336
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
337
|
+
expect(result.queryByTestId("announcement-navigator-error")).toBeNull();
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("keeps children mounted and shows a banner for banner announcements", async () => {
|
|
341
|
+
const {api, impressionMutation} = createMockApi({
|
|
342
|
+
current: makeAnnouncement({displayMode: "banner", requiresAcknowledgement: false}),
|
|
343
|
+
remainingCount: 0,
|
|
344
|
+
});
|
|
345
|
+
const result = renderWithTheme(
|
|
346
|
+
<AnnouncementNavigator api={api}>
|
|
347
|
+
<Box testID="app-content">
|
|
348
|
+
<Text>App</Text>
|
|
349
|
+
</Box>
|
|
350
|
+
</AnnouncementNavigator>
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
await waitForFrequencyCheck();
|
|
354
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
355
|
+
expect(result.getByTestId("announcement-banner")).toBeTruthy();
|
|
356
|
+
expect(result.queryByTestId("announcement-screen")).toBeNull();
|
|
357
|
+
expect(impressionMutation).toHaveBeenCalledTimes(1);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("preserves child input state when a banner is dismissed", async () => {
|
|
361
|
+
const StatefulInput: React.FC = () => {
|
|
362
|
+
const [value, setValue] = useState("");
|
|
363
|
+
return <TextField onChange={setValue} testID="todo-input" title="New Todo" value={value} />;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
const BannerDismissHarness: React.FC = () => {
|
|
367
|
+
const [pending, setPending] = useState<PendingAnnouncementsResponse>({
|
|
368
|
+
current: makeAnnouncement({displayMode: "banner", requiresAcknowledgement: false}),
|
|
369
|
+
remainingCount: 0,
|
|
370
|
+
});
|
|
371
|
+
const refetch = useCallback(async (): Promise<void> => {
|
|
372
|
+
setPending({current: null, remainingCount: 0});
|
|
373
|
+
}, []);
|
|
374
|
+
const {api} = createMockApi(pending, refetch);
|
|
375
|
+
|
|
376
|
+
return (
|
|
377
|
+
<AnnouncementNavigator api={api} frequency={{maxInterruptionsPerSession: 5}}>
|
|
378
|
+
<Box testID="app-content">
|
|
379
|
+
<StatefulInput />
|
|
380
|
+
</Box>
|
|
381
|
+
</AnnouncementNavigator>
|
|
382
|
+
);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
const result = renderWithTheme(<BannerDismissHarness />);
|
|
386
|
+
await waitForFrequencyCheck();
|
|
387
|
+
expect(result.getByTestId("announcement-banner")).toBeTruthy();
|
|
388
|
+
|
|
389
|
+
await act(async () => {
|
|
390
|
+
fireEvent.changeText(result.getByTestId("todo-input"), "unsaved text");
|
|
391
|
+
});
|
|
392
|
+
expect(result.getByTestId("todo-input").props.value).toBe("unsaved text");
|
|
393
|
+
|
|
394
|
+
await act(async () => {
|
|
395
|
+
fireEvent.press(result.getByText("Dismiss"));
|
|
396
|
+
await Promise.resolve();
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
expect(result.queryByTestId("announcement-banner")).toBeNull();
|
|
400
|
+
expect(result.getByTestId("todo-input").props.value).toBe("unsaved text");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("ignores unexpected feed displayMode items in pending.current", () => {
|
|
404
|
+
const {api} = createMockApi({
|
|
405
|
+
current: makeAnnouncement({displayMode: "feed"}),
|
|
406
|
+
remainingCount: 0,
|
|
407
|
+
});
|
|
408
|
+
const result = renderWithTheme(
|
|
409
|
+
<AnnouncementNavigator api={api}>
|
|
410
|
+
<Box testID="app-content">
|
|
411
|
+
<Text>App</Text>
|
|
412
|
+
</Box>
|
|
413
|
+
</AnnouncementNavigator>
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
417
|
+
assert.isNull(result.queryByTestId("announcement-banner"));
|
|
418
|
+
assert.isNull(result.queryByTestId("announcement-screen"));
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("does not show a second interrupt in the same session when maxInterruptionsPerSession is 1", async () => {
|
|
422
|
+
const QueueHarness: React.FC = () => {
|
|
423
|
+
const [queueIndex, setQueueIndex] = useState(0);
|
|
424
|
+
const refetch = useCallback(async (): Promise<void> => {
|
|
425
|
+
setQueueIndex((currentIndex) => Math.min(currentIndex + 1, announcementQueue.length - 1));
|
|
426
|
+
}, []);
|
|
427
|
+
const {api} = createMockApi(() => announcementQueue[queueIndex], refetch);
|
|
428
|
+
|
|
429
|
+
return (
|
|
430
|
+
<AnnouncementNavigator api={api}>
|
|
431
|
+
<Box testID="app-content">
|
|
432
|
+
<Text>App</Text>
|
|
433
|
+
</Box>
|
|
434
|
+
</AnnouncementNavigator>
|
|
435
|
+
);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const result = renderWithTheme(<QueueHarness />);
|
|
439
|
+
await waitForFrequencyCheck();
|
|
440
|
+
expect(result.getByText("First update")).toBeTruthy();
|
|
441
|
+
|
|
442
|
+
await act(async () => {
|
|
443
|
+
fireEvent.press(result.getByText("Got it"));
|
|
444
|
+
});
|
|
445
|
+
await waitForFrequencyCheck();
|
|
446
|
+
|
|
447
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
448
|
+
assert.isNull(result.queryByText("Second update"));
|
|
449
|
+
assert.isNull(result.queryByTestId("announcement-screen"));
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it("shows the next interrupt after module session reset simulating cold start", async () => {
|
|
453
|
+
// resetFrequencySessionStateForTests() simulates a JS runtime reload; navigator remount alone does not reset the cap.
|
|
454
|
+
const FirstSessionHarness: React.FC = () => {
|
|
455
|
+
const {api} = createMockApi({
|
|
456
|
+
current: makeAnnouncement({id: "announcement-1", title: "First update"}),
|
|
457
|
+
remainingCount: 1,
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
return (
|
|
461
|
+
<AnnouncementNavigator api={api}>
|
|
462
|
+
<Box testID="app-content">
|
|
463
|
+
<Text>App</Text>
|
|
464
|
+
</Box>
|
|
465
|
+
</AnnouncementNavigator>
|
|
466
|
+
);
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
const firstSession = renderWithTheme(<FirstSessionHarness />);
|
|
470
|
+
await act(async () => {
|
|
471
|
+
await Promise.resolve();
|
|
472
|
+
});
|
|
473
|
+
expect(firstSession.getByText("First update")).toBeTruthy();
|
|
474
|
+
firstSession.unmount();
|
|
475
|
+
resetFrequencySessionStateForTests();
|
|
476
|
+
|
|
477
|
+
const SecondSessionHarness: React.FC = () => {
|
|
478
|
+
const {api} = createMockApi({
|
|
479
|
+
current: makeAnnouncement({id: "announcement-2", title: "Second update"}),
|
|
480
|
+
remainingCount: 0,
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
return (
|
|
484
|
+
<AnnouncementNavigator api={api}>
|
|
485
|
+
<Box testID="app-content">
|
|
486
|
+
<Text>App</Text>
|
|
487
|
+
</Box>
|
|
488
|
+
</AnnouncementNavigator>
|
|
489
|
+
);
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
const secondSession = renderWithTheme(<SecondSessionHarness />);
|
|
493
|
+
await act(async () => {
|
|
494
|
+
await Promise.resolve();
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
expect(secondSession.getByText("Second update")).toBeTruthy();
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("keeps a visible interrupt mounted when the parent rerenders an equivalent inline frequency object", async () => {
|
|
501
|
+
const {api} = createMockApi({
|
|
502
|
+
current: makeAnnouncement({title: "Stable interrupt"}),
|
|
503
|
+
remainingCount: 0,
|
|
504
|
+
});
|
|
505
|
+
const result = renderWithTheme(
|
|
506
|
+
<AnnouncementNavigator api={api} frequency={{maxInterruptionsPerSession: 5}}>
|
|
507
|
+
<Box testID="app-content">
|
|
508
|
+
<Text>App</Text>
|
|
509
|
+
</Box>
|
|
510
|
+
</AnnouncementNavigator>
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
await waitForFrequencyCheck();
|
|
514
|
+
expect(result.getByTestId("announcement-screen")).toBeTruthy();
|
|
515
|
+
assert.isNull(result.queryByTestId("app-content"));
|
|
516
|
+
|
|
517
|
+
result.rerender(
|
|
518
|
+
<AnnouncementNavigator api={api} frequency={{maxInterruptionsPerSession: 5}}>
|
|
519
|
+
<Box testID="app-content">
|
|
520
|
+
<Text>App</Text>
|
|
521
|
+
</Box>
|
|
522
|
+
</AnnouncementNavigator>
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
expect(result.getByTestId("announcement-screen")).toBeTruthy();
|
|
526
|
+
assert.isNull(result.queryByTestId("app-content"));
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it("skips interrupts on first launch when skipFirstLaunch is true", async () => {
|
|
530
|
+
const {api} = createMockApi({
|
|
531
|
+
current: makeAnnouncement({title: "Welcome"}),
|
|
532
|
+
remainingCount: 0,
|
|
533
|
+
});
|
|
534
|
+
const result = renderWithTheme(
|
|
535
|
+
<AnnouncementNavigator api={api} frequency={{skipFirstLaunch: true, userId: "user-1"}}>
|
|
536
|
+
<Box testID="app-content">
|
|
537
|
+
<Text>App</Text>
|
|
538
|
+
</Box>
|
|
539
|
+
</AnnouncementNavigator>
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
await act(async () => {
|
|
543
|
+
await Promise.resolve();
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
547
|
+
assert.isNull(result.queryByTestId("announcement-screen"));
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("skips interrupts inside the cooldown window", async () => {
|
|
551
|
+
const lastInterruptKey = buildFrequencyStorageKey("anon", "lastInterruptAt");
|
|
552
|
+
const recentInterruptAt = DateTime.now().minus({hours: 1}).toISO() ?? "";
|
|
553
|
+
Unifier.storage.getItem = mock(async (key: string) => {
|
|
554
|
+
if (key === lastInterruptKey) {
|
|
555
|
+
return recentInterruptAt;
|
|
556
|
+
}
|
|
557
|
+
return null;
|
|
558
|
+
});
|
|
559
|
+
Unifier.storage.setItem = mock(async () => undefined);
|
|
560
|
+
|
|
561
|
+
const {api, impressionMutation} = createMockApi({
|
|
562
|
+
current: makeAnnouncement({title: "Cooldown blocked"}),
|
|
563
|
+
remainingCount: 0,
|
|
564
|
+
});
|
|
565
|
+
const result = renderWithTheme(
|
|
566
|
+
<AnnouncementNavigator api={api} frequency={{cooldownHours: 24}}>
|
|
567
|
+
<Box testID="app-content">
|
|
568
|
+
<Text>App</Text>
|
|
569
|
+
</Box>
|
|
570
|
+
</AnnouncementNavigator>
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
await act(async () => {
|
|
574
|
+
await Promise.resolve();
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
578
|
+
assert.isNull(result.queryByTestId("announcement-screen"));
|
|
579
|
+
expect(impressionMutation).not.toHaveBeenCalled();
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
it("does not apply frequency caps to feed data from useAnnouncements", async () => {
|
|
583
|
+
const feedItem = makeAnnouncement({
|
|
584
|
+
displayMode: "feed",
|
|
585
|
+
id: "feed-item",
|
|
586
|
+
title: "Changelog entry",
|
|
587
|
+
});
|
|
588
|
+
const {api} = createMockApi(
|
|
589
|
+
{
|
|
590
|
+
current: makeAnnouncement({title: "Blocked interrupt"}),
|
|
591
|
+
remainingCount: 0,
|
|
592
|
+
},
|
|
593
|
+
undefined,
|
|
594
|
+
[feedItem]
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
const FeedHarness: React.FC = () => {
|
|
598
|
+
const {feed} = useAnnouncements(api);
|
|
599
|
+
return (
|
|
600
|
+
<AnnouncementNavigator api={api} frequency={{maxInterruptionsPerSession: 0}}>
|
|
601
|
+
<Box testID="app-content">
|
|
602
|
+
<Text testID="feed-title">{feed[0]?.title ?? "missing"}</Text>
|
|
603
|
+
</Box>
|
|
604
|
+
</AnnouncementNavigator>
|
|
605
|
+
);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const result = renderWithTheme(<FeedHarness />);
|
|
609
|
+
await act(async () => {
|
|
610
|
+
await Promise.resolve();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
expect(result.getByTestId("feed-title")).toHaveTextContent("Changelog entry");
|
|
614
|
+
expect(result.getByTestId("app-content")).toBeTruthy();
|
|
615
|
+
assert.isNull(result.queryByTestId("announcement-screen"));
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
it("fails open when frequency storage reads fail", async () => {
|
|
619
|
+
Unifier.storage.getItem = mock(async () => {
|
|
620
|
+
throw new Error("storage read failed");
|
|
621
|
+
});
|
|
622
|
+
Unifier.storage.setItem = mock(async () => {
|
|
623
|
+
throw new Error("storage write failed");
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
const {api, impressionMutation} = createMockApi({
|
|
627
|
+
current: makeAnnouncement({title: "Still visible"}),
|
|
628
|
+
remainingCount: 0,
|
|
629
|
+
});
|
|
630
|
+
const result = renderWithTheme(
|
|
631
|
+
<AnnouncementNavigator api={api} frequency={{cooldownHours: 12, skipFirstLaunch: true}}>
|
|
632
|
+
<Box testID="app-content">
|
|
633
|
+
<Text>App</Text>
|
|
634
|
+
</Box>
|
|
635
|
+
</AnnouncementNavigator>
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
await act(async () => {
|
|
639
|
+
await Promise.resolve();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
expect(result.getByTestId("announcement-screen")).toBeTruthy();
|
|
643
|
+
expect(impressionMutation).toHaveBeenCalledTimes(1);
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
it("records an impression instead of acknowledging when the API marks dismiss-only", async () => {
|
|
647
|
+
const {api, impressionMutation, acknowledgeMutation} = createMockApi({
|
|
648
|
+
current: makeAnnouncement({requiresAcknowledgement: false}),
|
|
649
|
+
remainingCount: 0,
|
|
650
|
+
});
|
|
651
|
+
const result = renderWithTheme(
|
|
652
|
+
<AnnouncementNavigator api={api}>
|
|
653
|
+
<Box testID="app-content">
|
|
654
|
+
<Text>App</Text>
|
|
655
|
+
</Box>
|
|
656
|
+
</AnnouncementNavigator>
|
|
657
|
+
);
|
|
658
|
+
await waitForFrequencyCheck();
|
|
659
|
+
await act(async () => {
|
|
660
|
+
fireEvent.press(result.getByText("Dismiss"));
|
|
661
|
+
});
|
|
662
|
+
expect(impressionMutation).toHaveBeenCalled();
|
|
663
|
+
expect(acknowledgeMutation).not.toHaveBeenCalled();
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
it("records a click and opens the primary action URL from the modal", async () => {
|
|
667
|
+
const openUrl = mock(() => Promise.resolve(true));
|
|
668
|
+
Linking.canOpenURL = openUrl;
|
|
669
|
+
Linking.openURL = mock(() => Promise.resolve());
|
|
670
|
+
|
|
671
|
+
const {api, clickMutation} = createMockApi({
|
|
672
|
+
current: makeAnnouncement({
|
|
673
|
+
primaryAction: {label: "Read docs", url: "https://example.com/docs"},
|
|
674
|
+
}),
|
|
675
|
+
remainingCount: 0,
|
|
676
|
+
});
|
|
677
|
+
const result = renderWithTheme(
|
|
678
|
+
<AnnouncementNavigator api={api}>
|
|
679
|
+
<Box testID="app-content">
|
|
680
|
+
<Text>App</Text>
|
|
681
|
+
</Box>
|
|
682
|
+
</AnnouncementNavigator>
|
|
683
|
+
);
|
|
684
|
+
|
|
685
|
+
await waitForFrequencyCheck();
|
|
686
|
+
await act(async () => {
|
|
687
|
+
fireEvent.press(result.getByText("Read docs"));
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
assert.strictEqual(clickMutation.mock.calls.length, 1);
|
|
691
|
+
assert.deepEqual(clickMutation.mock.calls[0], [{announcementId: "announcement-1"}]);
|
|
692
|
+
expect(openUrl).toHaveBeenCalledWith("https://example.com/docs");
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
it("still opens the primary action URL when click tracking fails", async () => {
|
|
696
|
+
const warnSpy = mock(() => undefined);
|
|
697
|
+
const originalWarn = console.warn;
|
|
698
|
+
console.warn = warnSpy;
|
|
699
|
+
|
|
700
|
+
const openUrl = mock(() => Promise.resolve(true));
|
|
701
|
+
Linking.canOpenURL = openUrl;
|
|
702
|
+
Linking.openURL = mock(() => Promise.resolve());
|
|
703
|
+
|
|
704
|
+
const {api, clickMutation} = createMockApi(
|
|
705
|
+
{
|
|
706
|
+
current: makeAnnouncement({
|
|
707
|
+
primaryAction: {label: "Read docs", url: "https://example.com/docs"},
|
|
708
|
+
}),
|
|
709
|
+
remainingCount: 0,
|
|
710
|
+
},
|
|
711
|
+
undefined,
|
|
712
|
+
[],
|
|
713
|
+
async () => {
|
|
714
|
+
throw new Error("click failed");
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
|
|
718
|
+
const result = renderWithTheme(
|
|
719
|
+
<AnnouncementNavigator api={api}>
|
|
720
|
+
<Box testID="app-content">
|
|
721
|
+
<Text>App</Text>
|
|
722
|
+
</Box>
|
|
723
|
+
</AnnouncementNavigator>
|
|
724
|
+
);
|
|
725
|
+
|
|
726
|
+
await waitForFrequencyCheck();
|
|
727
|
+
await act(async () => {
|
|
728
|
+
fireEvent.press(result.getByText("Read docs"));
|
|
729
|
+
await Promise.resolve();
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
assert.strictEqual(clickMutation.mock.calls.length, 1);
|
|
733
|
+
assert.isAtLeast(warnSpy.mock.calls.length, 1);
|
|
734
|
+
expect(openUrl).toHaveBeenCalledWith("https://example.com/docs");
|
|
735
|
+
|
|
736
|
+
console.warn = originalWarn;
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
it("does not record a click when the announcement has no primary action", async () => {
|
|
740
|
+
const {api, clickMutation} = createMockApi({
|
|
741
|
+
current: makeAnnouncement(),
|
|
742
|
+
remainingCount: 0,
|
|
743
|
+
});
|
|
744
|
+
const result = renderWithTheme(
|
|
745
|
+
<AnnouncementNavigator api={api}>
|
|
746
|
+
<Box testID="app-content">
|
|
747
|
+
<Text>App</Text>
|
|
748
|
+
</Box>
|
|
749
|
+
</AnnouncementNavigator>
|
|
750
|
+
);
|
|
751
|
+
|
|
752
|
+
await waitForFrequencyCheck();
|
|
753
|
+
await act(async () => {
|
|
754
|
+
fireEvent.press(result.getByText("Got it"));
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
assert.strictEqual(clickMutation.mock.calls.length, 0);
|
|
758
|
+
});
|
|
759
|
+
});
|