@databiosphere/findable-ui 49.0.0 → 49.2.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +26 -0
- package/lib/common/ai/config/types.d.ts +22 -0
- package/lib/common/ai/config/types.js +1 -0
- package/lib/common/ai/constants.d.ts +3 -0
- package/lib/common/ai/constants.js +3 -0
- package/lib/components/Filter/components/FilterLabel/filterLabel.js +1 -1
- package/lib/components/Filter/components/FilterLabel/filterLabel.stories.d.ts +3 -0
- package/lib/components/Filter/components/FilterLabel/filterLabel.stories.js +5 -0
- package/lib/components/Filter/components/Filters/stories/constants.js +21 -1
- package/lib/components/Filter/components/SearchAllFilters/searchAllFilters.styles.js +2 -0
- package/lib/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.d.ts +4 -0
- package/lib/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.js +4 -0
- package/lib/components/common/Chip/components/Beta/beta.d.ts +10 -0
- package/lib/components/common/Chip/components/Beta/beta.js +12 -0
- package/lib/components/common/Chip/components/Beta/beta.styles.d.ts +3 -0
- package/lib/components/common/Chip/components/Beta/beta.styles.js +14 -0
- package/lib/components/common/Chip/components/Beta/stories/beta.stories.d.ts +6 -0
- package/lib/components/common/Chip/components/Beta/stories/beta.stories.js +6 -0
- package/lib/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.d.ts +6 -0
- package/lib/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.js +8 -0
- package/lib/components/common/Tabs/tabs.js +1 -1
- package/lib/components/common/ToggleButtonGroup/provider/context.d.ts +2 -0
- package/lib/components/common/ToggleButtonGroup/provider/context.js +5 -0
- package/lib/components/common/ToggleButtonGroup/provider/hook.d.ts +7 -0
- package/lib/components/common/ToggleButtonGroup/provider/hook.js +9 -0
- package/lib/components/common/ToggleButtonGroup/provider/provider.d.ts +12 -0
- package/lib/components/common/ToggleButtonGroup/provider/provider.js +22 -0
- package/lib/components/common/ToggleButtonGroup/provider/types.d.ts +9 -0
- package/lib/components/common/ToggleButtonGroup/provider/types.js +1 -0
- package/lib/config/entities.d.ts +2 -0
- package/lib/hooks/ai/useAiRoutes/hook.d.ts +6 -0
- package/lib/hooks/ai/useAiRoutes/hook.js +18 -0
- package/lib/styles/common/mui/drawer.d.ts +9 -0
- package/lib/styles/common/mui/drawer.js +15 -0
- package/lib/styles/common/mui/inputBase.d.ts +13 -0
- package/lib/styles/common/mui/inputBase.js +25 -0
- package/lib/styles/common/mui/stack.d.ts +11 -0
- package/lib/styles/common/mui/stack.js +22 -0
- package/lib/tests/testIds.d.ts +3 -0
- package/lib/tests/testIds.js +3 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.d.ts +6 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.js +17 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.d.ts +6 -0
- package/lib/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.js +23 -0
- package/lib/views/ExploreView/entityList/filters/filters.styles.d.ts +7 -0
- package/lib/views/ExploreView/entityList/filters/filters.styles.js +17 -0
- package/lib/views/ExploreView/exploreView.js +3 -2
- package/lib/views/ResearchView/assistant/assistant.d.ts +6 -0
- package/lib/views/ResearchView/assistant/assistant.js +16 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.js +15 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.styles.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Drawer/drawer.styles.js +21 -0
- package/lib/views/ResearchView/assistant/components/Drawer/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Drawer/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Form/constants.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Form/constants.js +3 -0
- package/lib/views/ResearchView/assistant/components/Form/form.d.ts +11 -0
- package/lib/views/ResearchView/assistant/components/Form/form.js +27 -0
- package/lib/views/ResearchView/assistant/components/Form/form.styles.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Form/form.styles.js +7 -0
- package/lib/views/ResearchView/assistant/components/Form/types.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Form/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Form/utils.d.ts +16 -0
- package/lib/views/ResearchView/assistant/components/Form/utils.js +41 -0
- package/lib/views/ResearchView/assistant/components/Input/constants.d.ts +2 -0
- package/lib/views/ResearchView/assistant/components/Input/constants.js +14 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.d.ts +7 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.js +7 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.js +32 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.d.ts +32 -0
- package/lib/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.js +74 -0
- package/lib/views/ResearchView/assistant/components/Input/input.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Input/input.js +19 -0
- package/lib/views/ResearchView/assistant/components/Input/input.styles.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Input/input.styles.js +19 -0
- package/lib/views/ResearchView/assistant/components/Input/stories/input.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Input/stories/input.stories.js +11 -0
- package/lib/views/ResearchView/assistant/components/Input/types.d.ts +2 -0
- package/lib/views/ResearchView/assistant/components/Input/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Input/utils.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Input/utils.js +25 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.js +15 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.d.ts +13 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.js +25 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.js +12 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.js +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.js +26 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.d.ts +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.js +14 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.js +10 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.js +13 -0
- package/lib/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.d.ts +8 -0
- package/lib/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.js +20 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.d.ts +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.js +16 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.styles.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/messages.styles.js +9 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/messageSelector.d.ts +17 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/messageSelector.js +32 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/types.d.ts +5 -0
- package/lib/views/ResearchView/assistant/components/Messages/selector/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/args.d.ts +3 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/args.js +109 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/messages.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/Messages/stories/messages.stories.js +14 -0
- package/lib/views/ResearchView/assistant/components/Messages/types.d.ts +4 -0
- package/lib/views/ResearchView/assistant/components/Messages/types.js +1 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.js +12 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.js +16 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.d.ts +6 -0
- package/lib/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.js +20 -0
- package/lib/views/ResearchView/assistant/stories/args.d.ts +4 -0
- package/lib/views/ResearchView/assistant/stories/args.js +30 -0
- package/lib/views/ResearchView/assistant/stories/assistant.stories.d.ts +6 -0
- package/lib/views/ResearchView/assistant/stories/assistant.stories.js +23 -0
- package/lib/views/ResearchView/query/constants.d.ts +5 -0
- package/lib/views/ResearchView/query/constants.js +5 -0
- package/lib/views/ResearchView/query/fetch.d.ts +17 -0
- package/lib/views/ResearchView/query/fetch.js +44 -0
- package/lib/views/ResearchView/researchView.d.ts +10 -0
- package/lib/views/ResearchView/researchView.js +13 -0
- package/lib/views/ResearchView/state/actions/setError/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setError/action.js +17 -0
- package/lib/views/ResearchView/state/actions/setError/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setError/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setError/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setError/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setMessage/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setMessage/action.js +21 -0
- package/lib/views/ResearchView/state/actions/setMessage/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setMessage/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setMessage/types.d.ts +15 -0
- package/lib/views/ResearchView/state/actions/setMessage/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setQuery/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setQuery/action.js +17 -0
- package/lib/views/ResearchView/state/actions/setQuery/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setQuery/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setQuery/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setQuery/types.js +1 -0
- package/lib/views/ResearchView/state/actions/setStatus/action.d.ts +10 -0
- package/lib/views/ResearchView/state/actions/setStatus/action.js +13 -0
- package/lib/views/ResearchView/state/actions/setStatus/dispatch.d.ts +7 -0
- package/lib/views/ResearchView/state/actions/setStatus/dispatch.js +12 -0
- package/lib/views/ResearchView/state/actions/setStatus/types.d.ts +14 -0
- package/lib/views/ResearchView/state/actions/setStatus/types.js +1 -0
- package/lib/views/ResearchView/state/actions/types.d.ts +17 -0
- package/lib/views/ResearchView/state/actions/types.js +10 -0
- package/lib/views/ResearchView/state/constants.d.ts +5 -0
- package/lib/views/ResearchView/state/constants.js +7 -0
- package/lib/views/ResearchView/state/context.d.ts +5 -0
- package/lib/views/ResearchView/state/context.js +9 -0
- package/lib/views/ResearchView/state/guards/guards.d.ts +33 -0
- package/lib/views/ResearchView/state/guards/guards.js +41 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/hook.d.ts +6 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/hook.js +26 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/types.d.ts +10 -0
- package/lib/views/ResearchView/state/hooks/UseChatDispatch/types.js +1 -0
- package/lib/views/ResearchView/state/hooks/UseChatReducer/hook.d.ts +8 -0
- package/lib/views/ResearchView/state/hooks/UseChatReducer/hook.js +12 -0
- package/lib/views/ResearchView/state/hooks/UseChatState/hook.d.ts +7 -0
- package/lib/views/ResearchView/state/hooks/UseChatState/hook.js +11 -0
- package/lib/views/ResearchView/state/initializer/initializer.d.ts +8 -0
- package/lib/views/ResearchView/state/initializer/initializer.js +22 -0
- package/lib/views/ResearchView/state/initializer/types.d.ts +2 -0
- package/lib/views/ResearchView/state/initializer/types.js +1 -0
- package/lib/views/ResearchView/state/provider.d.ts +19 -0
- package/lib/views/ResearchView/state/provider.js +20 -0
- package/lib/views/ResearchView/state/query/context.d.ts +5 -0
- package/lib/views/ResearchView/state/query/context.js +7 -0
- package/lib/views/ResearchView/state/query/hooks/UseQuery/hook.d.ts +6 -0
- package/lib/views/ResearchView/state/query/hooks/UseQuery/hook.js +9 -0
- package/lib/views/ResearchView/state/query/hooks/UseSubmit/hook.d.ts +7 -0
- package/lib/views/ResearchView/state/query/hooks/UseSubmit/hook.js +46 -0
- package/lib/views/ResearchView/state/query/provider.d.ts +13 -0
- package/lib/views/ResearchView/state/query/provider.js +15 -0
- package/lib/views/ResearchView/state/query/types.d.ts +24 -0
- package/lib/views/ResearchView/state/query/types.js +1 -0
- package/lib/views/ResearchView/state/reducer.d.ts +10 -0
- package/lib/views/ResearchView/state/reducer.js +32 -0
- package/lib/views/ResearchView/state/types.d.ts +125 -0
- package/lib/views/ResearchView/state/types.js +22 -0
- package/package.json +1 -1
- package/src/common/ai/config/types.ts +25 -0
- package/src/common/ai/constants.ts +3 -0
- package/src/components/Filter/components/FilterLabel/filterLabel.stories.tsx +6 -0
- package/src/components/Filter/components/FilterLabel/filterLabel.tsx +6 -1
- package/src/components/Filter/components/Filters/stories/constants.ts +25 -1
- package/src/components/Filter/components/SearchAllFilters/searchAllFilters.styles.ts +2 -0
- package/src/components/Layout/components/Sidebar/components/SidebarTools/sidebarTools.styles.ts +4 -0
- package/src/components/common/Chip/components/Beta/beta.styles.ts +15 -0
- package/src/components/common/Chip/components/Beta/beta.tsx +25 -0
- package/src/components/common/Chip/components/Beta/stories/beta.stories.tsx +12 -0
- package/src/components/common/CustomIcon/components/UpArrowIcon/upArrowIcon.tsx +21 -0
- package/src/components/common/Tabs/tabs.tsx +5 -1
- package/src/components/common/ToggleButtonGroup/provider/context.ts +9 -0
- package/src/components/common/ToggleButtonGroup/provider/hook.ts +16 -0
- package/src/components/common/ToggleButtonGroup/provider/provider.tsx +37 -0
- package/src/components/common/ToggleButtonGroup/provider/types.ts +17 -0
- package/src/config/entities.ts +2 -0
- package/src/hooks/ai/useAiRoutes/hook.ts +22 -0
- package/src/styles/common/mui/drawer.ts +24 -0
- package/src/styles/common/mui/inputBase.ts +38 -0
- package/src/styles/common/mui/stack.ts +33 -0
- package/src/tests/testIds.ts +3 -0
- package/src/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.styles.ts +25 -0
- package/src/views/ExploreView/entityList/filters/components/ToggleButtonGroup/toggleButtonGroup.tsx +35 -0
- package/src/views/ExploreView/entityList/filters/filters.styles.ts +19 -0
- package/src/views/ExploreView/exploreView.tsx +16 -12
- package/src/views/ResearchView/assistant/assistant.tsx +28 -0
- package/src/views/ResearchView/assistant/components/Drawer/drawer.styles.ts +24 -0
- package/src/views/ResearchView/assistant/components/Drawer/drawer.tsx +26 -0
- package/src/views/ResearchView/assistant/components/Drawer/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Form/constants.ts +3 -0
- package/src/views/ResearchView/assistant/components/Form/form.styles.ts +8 -0
- package/src/views/ResearchView/assistant/components/Form/form.tsx +40 -0
- package/src/views/ResearchView/assistant/components/Form/types.ts +9 -0
- package/src/views/ResearchView/assistant/components/Form/utils.ts +51 -0
- package/src/views/ResearchView/assistant/components/Input/constants.ts +16 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/constants.ts +7 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/hook.ts +45 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/types.ts +10 -0
- package/src/views/ResearchView/assistant/components/Input/hooks/UseKeyShortCuts/utils.ts +93 -0
- package/src/views/ResearchView/assistant/components/Input/input.styles.ts +21 -0
- package/src/views/ResearchView/assistant/components/Input/input.tsx +37 -0
- package/src/views/ResearchView/assistant/components/Input/stories/input.stories.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Input/types.ts +3 -0
- package/src/views/ResearchView/assistant/components/Input/utils.ts +34 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/assistantMessage.tsx +49 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/AssistantMessage/utils.ts +31 -0
- package/src/views/ResearchView/assistant/components/Messages/components/ErrorMessage/errorMessage.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Messages/components/ErrorMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.styles.ts +27 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/chips.tsx +31 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/components/Chips/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/promptMessage.tsx +26 -0
- package/src/views/ResearchView/assistant/components/Messages/components/PromptMessage/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/useMessage.styles.ts +11 -0
- package/src/views/ResearchView/assistant/components/Messages/components/UserMessage/userMessage.tsx +21 -0
- package/src/views/ResearchView/assistant/components/Messages/hooks/UseScroll/hook.ts +25 -0
- package/src/views/ResearchView/assistant/components/Messages/messages.styles.ts +10 -0
- package/src/views/ResearchView/assistant/components/Messages/messages.tsx +29 -0
- package/src/views/ResearchView/assistant/components/Messages/selector/messageSelector.tsx +37 -0
- package/src/views/ResearchView/assistant/components/Messages/selector/types.ts +6 -0
- package/src/views/ResearchView/assistant/components/Messages/stories/args.ts +115 -0
- package/src/views/ResearchView/assistant/components/Messages/stories/messages.stories.tsx +24 -0
- package/src/views/ResearchView/assistant/components/Messages/types.ts +5 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/stories/toggleButtonGroup.stories.tsx +22 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.styles.ts +22 -0
- package/src/views/ResearchView/assistant/components/ToggleButtonGroup/toggleButtonGroup.tsx +34 -0
- package/src/views/ResearchView/assistant/stories/args.ts +36 -0
- package/src/views/ResearchView/assistant/stories/assistant.stories.tsx +39 -0
- package/src/views/ResearchView/query/constants.ts +5 -0
- package/src/views/ResearchView/query/fetch.ts +58 -0
- package/src/views/ResearchView/researchView.tsx +19 -0
- package/src/views/ResearchView/state/actions/setError/action.ts +22 -0
- package/src/views/ResearchView/state/actions/setError/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setError/types.ts +16 -0
- package/src/views/ResearchView/state/actions/setMessage/action.ts +26 -0
- package/src/views/ResearchView/state/actions/setMessage/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setMessage/types.ts +19 -0
- package/src/views/ResearchView/state/actions/setQuery/action.ts +22 -0
- package/src/views/ResearchView/state/actions/setQuery/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setQuery/types.ts +16 -0
- package/src/views/ResearchView/state/actions/setStatus/action.ts +19 -0
- package/src/views/ResearchView/state/actions/setStatus/dispatch.ts +14 -0
- package/src/views/ResearchView/state/actions/setStatus/types.ts +16 -0
- package/src/views/ResearchView/state/actions/types.ts +23 -0
- package/src/views/ResearchView/state/constants.ts +9 -0
- package/src/views/ResearchView/state/context.ts +11 -0
- package/src/views/ResearchView/state/guards/guards.ts +58 -0
- package/src/views/ResearchView/state/hooks/UseChatDispatch/hook.ts +46 -0
- package/src/views/ResearchView/state/hooks/UseChatDispatch/types.ts +11 -0
- package/src/views/ResearchView/state/hooks/UseChatReducer/hook.ts +15 -0
- package/src/views/ResearchView/state/hooks/UseChatState/hook.ts +14 -0
- package/src/views/ResearchView/state/initializer/initializer.ts +23 -0
- package/src/views/ResearchView/state/initializer/types.ts +3 -0
- package/src/views/ResearchView/state/provider.tsx +34 -0
- package/src/views/ResearchView/state/query/context.ts +9 -0
- package/src/views/ResearchView/state/query/hooks/UseQuery/hook.ts +11 -0
- package/src/views/ResearchView/state/query/hooks/UseSubmit/hook.ts +66 -0
- package/src/views/ResearchView/state/query/provider.tsx +27 -0
- package/src/views/ResearchView/state/query/types.ts +31 -0
- package/src/views/ResearchView/state/reducer.ts +34 -0
- package/src/views/ResearchView/state/types.ts +149 -0
- package/tests/research.assistantMessageUtils.test.ts +149 -0
- package/tests/research.chatState.test.ts +463 -0
- package/tests/research.fetchResponse.test.ts +164 -0
- package/tests/research.queryProvider.test.ts +321 -0
- package/tests/research.useKeyShortCuts.test.ts +254 -0
- package/tests/toggleButtonGroupProvider.test.tsx +125 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
import { chatReducer } from "../src/views/ResearchView/state/reducer";
|
|
2
|
+
import { setErrorAction } from "../src/views/ResearchView/state/actions/setError/action";
|
|
3
|
+
import { setError } from "../src/views/ResearchView/state/actions/setError/dispatch";
|
|
4
|
+
import { setMessageAction } from "../src/views/ResearchView/state/actions/setMessage/action";
|
|
5
|
+
import { setMessage } from "../src/views/ResearchView/state/actions/setMessage/dispatch";
|
|
6
|
+
import { setQueryAction } from "../src/views/ResearchView/state/actions/setQuery/action";
|
|
7
|
+
import { setQuery } from "../src/views/ResearchView/state/actions/setQuery/dispatch";
|
|
8
|
+
import { setStatusAction } from "../src/views/ResearchView/state/actions/setStatus/action";
|
|
9
|
+
import { setStatus } from "../src/views/ResearchView/state/actions/setStatus/dispatch";
|
|
10
|
+
import { ChatActionKind } from "../src/views/ResearchView/state/actions/types";
|
|
11
|
+
import {
|
|
12
|
+
ChatState,
|
|
13
|
+
MESSAGE_TYPE,
|
|
14
|
+
MessageResponse,
|
|
15
|
+
SUGGESTION_VARIANT,
|
|
16
|
+
} from "../src/views/ResearchView/state/types";
|
|
17
|
+
import { initializer } from "../src/views/ResearchView/state/initializer/initializer";
|
|
18
|
+
import { INITIAL_STATE } from "../src/views/ResearchView/state/constants";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates a mock MessageResponse for testing.
|
|
22
|
+
* @param message - Optional message override.
|
|
23
|
+
* @returns A mock MessageResponse object.
|
|
24
|
+
*/
|
|
25
|
+
const mockResponse = (message: string | null = null): MessageResponse => ({
|
|
26
|
+
intent: "auto",
|
|
27
|
+
message,
|
|
28
|
+
query: {
|
|
29
|
+
mentions: [],
|
|
30
|
+
message: null,
|
|
31
|
+
},
|
|
32
|
+
timing: {
|
|
33
|
+
lookupMs: 0,
|
|
34
|
+
pipelineMs: 0,
|
|
35
|
+
totalMs: 0,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("setError action creator", () => {
|
|
40
|
+
it("should return correct action shape", () => {
|
|
41
|
+
const action = setError({ error: "Something went wrong" });
|
|
42
|
+
|
|
43
|
+
expect(action).toEqual({
|
|
44
|
+
payload: { error: "Something went wrong" },
|
|
45
|
+
type: ChatActionKind.SetError,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("setErrorAction", () => {
|
|
51
|
+
it("should append error to empty array", () => {
|
|
52
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
53
|
+
const result = setErrorAction(state, { error: "Network error" });
|
|
54
|
+
|
|
55
|
+
expect(result.messages).toEqual([
|
|
56
|
+
{
|
|
57
|
+
createdAt: expect.any(Number),
|
|
58
|
+
error: "Network error",
|
|
59
|
+
type: MESSAGE_TYPE.ERROR,
|
|
60
|
+
},
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should append error to existing messages", () => {
|
|
65
|
+
const response = mockResponse("Response");
|
|
66
|
+
const state: ChatState = {
|
|
67
|
+
messages: [
|
|
68
|
+
{ createdAt: 1000, text: "Query", type: MESSAGE_TYPE.USER },
|
|
69
|
+
{ createdAt: 2000, response, type: MESSAGE_TYPE.ASSISTANT },
|
|
70
|
+
],
|
|
71
|
+
status: { loading: false },
|
|
72
|
+
};
|
|
73
|
+
const result = setErrorAction(state, { error: "Request failed" });
|
|
74
|
+
|
|
75
|
+
expect(result.messages).toEqual([
|
|
76
|
+
{ createdAt: 1000, text: "Query", type: MESSAGE_TYPE.USER },
|
|
77
|
+
{ createdAt: 2000, response, type: MESSAGE_TYPE.ASSISTANT },
|
|
78
|
+
{
|
|
79
|
+
createdAt: expect.any(Number),
|
|
80
|
+
error: "Request failed",
|
|
81
|
+
type: MESSAGE_TYPE.ERROR,
|
|
82
|
+
},
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should not mutate original state", () => {
|
|
87
|
+
const state: ChatState = {
|
|
88
|
+
messages: [
|
|
89
|
+
{ createdAt: 1000, text: "Original", type: MESSAGE_TYPE.USER },
|
|
90
|
+
],
|
|
91
|
+
status: { loading: false },
|
|
92
|
+
};
|
|
93
|
+
const result = setErrorAction(state, { error: "Error" });
|
|
94
|
+
|
|
95
|
+
expect(state.messages).toEqual([
|
|
96
|
+
{ createdAt: 1000, text: "Original", type: MESSAGE_TYPE.USER },
|
|
97
|
+
]);
|
|
98
|
+
expect(result).not.toBe(state);
|
|
99
|
+
expect(result.messages).not.toBe(state.messages);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("setMessage action creator", () => {
|
|
104
|
+
it("should return correct action shape", () => {
|
|
105
|
+
const response = mockResponse("Hello");
|
|
106
|
+
const action = setMessage({ response });
|
|
107
|
+
|
|
108
|
+
expect(action).toEqual({
|
|
109
|
+
payload: { response },
|
|
110
|
+
type: ChatActionKind.SetMessage,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("setMessageAction", () => {
|
|
116
|
+
it("should append message to empty array", () => {
|
|
117
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
118
|
+
const response = mockResponse("First response");
|
|
119
|
+
const result = setMessageAction(state, { response });
|
|
120
|
+
|
|
121
|
+
expect(result.messages).toEqual([
|
|
122
|
+
{
|
|
123
|
+
createdAt: expect.any(Number),
|
|
124
|
+
response,
|
|
125
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
126
|
+
},
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should append message to existing messages", () => {
|
|
131
|
+
const existingResponse = mockResponse("Second");
|
|
132
|
+
const state: ChatState = {
|
|
133
|
+
messages: [
|
|
134
|
+
{ createdAt: 1000, text: "First", type: MESSAGE_TYPE.USER },
|
|
135
|
+
{
|
|
136
|
+
createdAt: 2000,
|
|
137
|
+
response: existingResponse,
|
|
138
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
status: { loading: false },
|
|
142
|
+
};
|
|
143
|
+
const newResponse = mockResponse("Third");
|
|
144
|
+
const result = setMessageAction(state, { response: newResponse });
|
|
145
|
+
|
|
146
|
+
expect(result.messages).toEqual([
|
|
147
|
+
{ createdAt: 1000, text: "First", type: MESSAGE_TYPE.USER },
|
|
148
|
+
{
|
|
149
|
+
createdAt: 2000,
|
|
150
|
+
response: existingResponse,
|
|
151
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
createdAt: expect.any(Number),
|
|
155
|
+
response: newResponse,
|
|
156
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
157
|
+
},
|
|
158
|
+
]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should not mutate original state", () => {
|
|
162
|
+
const state: ChatState = {
|
|
163
|
+
messages: [
|
|
164
|
+
{ createdAt: 1000, text: "Original", type: MESSAGE_TYPE.USER },
|
|
165
|
+
],
|
|
166
|
+
status: { loading: false },
|
|
167
|
+
};
|
|
168
|
+
const response = mockResponse("New");
|
|
169
|
+
const result = setMessageAction(state, { response });
|
|
170
|
+
|
|
171
|
+
expect(state.messages).toEqual([
|
|
172
|
+
{ createdAt: 1000, text: "Original", type: MESSAGE_TYPE.USER },
|
|
173
|
+
]);
|
|
174
|
+
expect(result).not.toBe(state);
|
|
175
|
+
expect(result.messages).not.toBe(state.messages);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe("setQuery action creator", () => {
|
|
180
|
+
it("should return correct action shape", () => {
|
|
181
|
+
const action = setQuery({ query: "What studies are available?" });
|
|
182
|
+
|
|
183
|
+
expect(action).toEqual({
|
|
184
|
+
payload: { query: "What studies are available?" },
|
|
185
|
+
type: ChatActionKind.SetQuery,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe("setQueryAction", () => {
|
|
191
|
+
it("should append query to empty array", () => {
|
|
192
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
193
|
+
const result = setQueryAction(state, { query: "First query" });
|
|
194
|
+
|
|
195
|
+
expect(result.messages).toEqual([
|
|
196
|
+
{
|
|
197
|
+
createdAt: expect.any(Number),
|
|
198
|
+
text: "First query",
|
|
199
|
+
type: MESSAGE_TYPE.USER,
|
|
200
|
+
},
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should append query to existing messages", () => {
|
|
205
|
+
const existingResponse = mockResponse("Response");
|
|
206
|
+
const state: ChatState = {
|
|
207
|
+
messages: [
|
|
208
|
+
{ createdAt: 1000, text: "First", type: MESSAGE_TYPE.USER },
|
|
209
|
+
{
|
|
210
|
+
createdAt: 2000,
|
|
211
|
+
response: existingResponse,
|
|
212
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
status: { loading: false },
|
|
216
|
+
};
|
|
217
|
+
const result = setQueryAction(state, { query: "Second query" });
|
|
218
|
+
|
|
219
|
+
expect(result.messages).toEqual([
|
|
220
|
+
{ createdAt: 1000, text: "First", type: MESSAGE_TYPE.USER },
|
|
221
|
+
{
|
|
222
|
+
createdAt: 2000,
|
|
223
|
+
response: existingResponse,
|
|
224
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
createdAt: expect.any(Number),
|
|
228
|
+
text: "Second query",
|
|
229
|
+
type: MESSAGE_TYPE.USER,
|
|
230
|
+
},
|
|
231
|
+
]);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should not mutate original state", () => {
|
|
235
|
+
const response = mockResponse("Original response");
|
|
236
|
+
const state: ChatState = {
|
|
237
|
+
messages: [{ createdAt: 1000, response, type: MESSAGE_TYPE.ASSISTANT }],
|
|
238
|
+
status: { loading: false },
|
|
239
|
+
};
|
|
240
|
+
const result = setQueryAction(state, { query: "New query" });
|
|
241
|
+
|
|
242
|
+
expect(state.messages).toEqual([
|
|
243
|
+
{ createdAt: 1000, response, type: MESSAGE_TYPE.ASSISTANT },
|
|
244
|
+
]);
|
|
245
|
+
expect(result).not.toBe(state);
|
|
246
|
+
expect(result.messages).not.toBe(state.messages);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("setStatus action creator", () => {
|
|
251
|
+
it("should return correct action shape", () => {
|
|
252
|
+
const action = setStatus({ loading: true });
|
|
253
|
+
|
|
254
|
+
expect(action).toEqual({
|
|
255
|
+
payload: { loading: true },
|
|
256
|
+
type: ChatActionKind.SetStatus,
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("setStatusAction", () => {
|
|
262
|
+
it("should set loading to true", () => {
|
|
263
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
264
|
+
const result = setStatusAction(state, { loading: true });
|
|
265
|
+
|
|
266
|
+
expect(result.status.loading).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("should set loading to false", () => {
|
|
270
|
+
const state: ChatState = { messages: [], status: { loading: true } };
|
|
271
|
+
const result = setStatusAction(state, { loading: false });
|
|
272
|
+
|
|
273
|
+
expect(result.status.loading).toBe(false);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("should preserve messages when setting loading", () => {
|
|
277
|
+
const response = mockResponse("Test");
|
|
278
|
+
const state: ChatState = {
|
|
279
|
+
messages: [
|
|
280
|
+
{ createdAt: 1000, text: "Query", type: MESSAGE_TYPE.USER },
|
|
281
|
+
{ createdAt: 2000, response, type: MESSAGE_TYPE.ASSISTANT },
|
|
282
|
+
],
|
|
283
|
+
status: { loading: false },
|
|
284
|
+
};
|
|
285
|
+
const result = setStatusAction(state, { loading: true });
|
|
286
|
+
|
|
287
|
+
expect(result.messages).toEqual(state.messages);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should not mutate original state", () => {
|
|
291
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
292
|
+
const result = setStatusAction(state, { loading: true });
|
|
293
|
+
|
|
294
|
+
expect(state.status.loading).toBe(false);
|
|
295
|
+
expect(result).not.toBe(state);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("chatReducer", () => {
|
|
300
|
+
it("should return initial state for unknown action", () => {
|
|
301
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
302
|
+
const unknownAction = { payload: {}, type: "UNKNOWN" } as never;
|
|
303
|
+
|
|
304
|
+
const result = chatReducer(state, unknownAction);
|
|
305
|
+
|
|
306
|
+
expect(result).toBe(state);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("should handle SetMessage action", () => {
|
|
310
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
311
|
+
const response = mockResponse("Test response");
|
|
312
|
+
const action = setMessage({ response });
|
|
313
|
+
|
|
314
|
+
const result = chatReducer(state, action);
|
|
315
|
+
|
|
316
|
+
expect(result.messages).toEqual([
|
|
317
|
+
{
|
|
318
|
+
createdAt: expect.any(Number),
|
|
319
|
+
response,
|
|
320
|
+
type: MESSAGE_TYPE.ASSISTANT,
|
|
321
|
+
},
|
|
322
|
+
]);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("should handle SetQuery action", () => {
|
|
326
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
327
|
+
const action = setQuery({ query: "Test query" });
|
|
328
|
+
|
|
329
|
+
const result = chatReducer(state, action);
|
|
330
|
+
|
|
331
|
+
expect(result.messages).toEqual([
|
|
332
|
+
{
|
|
333
|
+
createdAt: expect.any(Number),
|
|
334
|
+
text: "Test query",
|
|
335
|
+
type: MESSAGE_TYPE.USER,
|
|
336
|
+
},
|
|
337
|
+
]);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("should return new state reference on SetMessage", () => {
|
|
341
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
342
|
+
const response = mockResponse("Test");
|
|
343
|
+
const action = setMessage({ response });
|
|
344
|
+
|
|
345
|
+
const result = chatReducer(state, action);
|
|
346
|
+
|
|
347
|
+
expect(result).not.toBe(state);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("should return new state reference on SetQuery", () => {
|
|
351
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
352
|
+
const action = setQuery({ query: "Test" });
|
|
353
|
+
|
|
354
|
+
const result = chatReducer(state, action);
|
|
355
|
+
|
|
356
|
+
expect(result).not.toBe(state);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("should handle SetStatus action", () => {
|
|
360
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
361
|
+
const action = setStatus({ loading: true });
|
|
362
|
+
|
|
363
|
+
const result = chatReducer(state, action);
|
|
364
|
+
|
|
365
|
+
expect(result.status.loading).toBe(true);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("should return new state reference on SetStatus", () => {
|
|
369
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
370
|
+
const action = setStatus({ loading: true });
|
|
371
|
+
|
|
372
|
+
const result = chatReducer(state, action);
|
|
373
|
+
|
|
374
|
+
expect(result).not.toBe(state);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("should handle SetError action", () => {
|
|
378
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
379
|
+
const action = setError({ error: "Test error" });
|
|
380
|
+
|
|
381
|
+
const result = chatReducer(state, action);
|
|
382
|
+
|
|
383
|
+
expect(result.messages).toEqual([
|
|
384
|
+
{
|
|
385
|
+
createdAt: expect.any(Number),
|
|
386
|
+
error: "Test error",
|
|
387
|
+
type: MESSAGE_TYPE.ERROR,
|
|
388
|
+
},
|
|
389
|
+
]);
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("should return new state reference on SetError", () => {
|
|
393
|
+
const state: ChatState = { messages: [], status: { loading: false } };
|
|
394
|
+
const action = setError({ error: "Test error" });
|
|
395
|
+
|
|
396
|
+
const result = chatReducer(state, action);
|
|
397
|
+
|
|
398
|
+
expect(result).not.toBe(state);
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
describe("initializer", () => {
|
|
403
|
+
it("should return initial state when no args provided", () => {
|
|
404
|
+
const result = initializer();
|
|
405
|
+
|
|
406
|
+
expect(result).toBe(INITIAL_STATE);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("should return initial state when undefined is passed", () => {
|
|
410
|
+
const result = initializer(undefined);
|
|
411
|
+
|
|
412
|
+
expect(result).toBe(INITIAL_STATE);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it("should inject a prompt message when initialArgs is provided", () => {
|
|
416
|
+
const result = initializer({ text: "Welcome to the assistant" });
|
|
417
|
+
|
|
418
|
+
expect(result.messages).toEqual([
|
|
419
|
+
expect.objectContaining({
|
|
420
|
+
initial: true,
|
|
421
|
+
text: "Welcome to the assistant",
|
|
422
|
+
type: MESSAGE_TYPE.PROMPT,
|
|
423
|
+
}),
|
|
424
|
+
]);
|
|
425
|
+
expect(result.messages[0]).toHaveProperty("createdAt");
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("should include all initialArgs properties in the prompt message", () => {
|
|
429
|
+
const result = initializer({
|
|
430
|
+
inputPlaceholder: "Ask about datasets",
|
|
431
|
+
suggestions: [
|
|
432
|
+
{
|
|
433
|
+
label: "GLP-1",
|
|
434
|
+
query: "GLP-1 studies",
|
|
435
|
+
variant: SUGGESTION_VARIANT.CHIP,
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
text: "How can I help?",
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
expect(result.messages).toHaveLength(1);
|
|
442
|
+
expect(result.messages[0]).toEqual(
|
|
443
|
+
expect.objectContaining({
|
|
444
|
+
inputPlaceholder: "Ask about datasets",
|
|
445
|
+
suggestions: [
|
|
446
|
+
{
|
|
447
|
+
label: "GLP-1",
|
|
448
|
+
query: "GLP-1 studies",
|
|
449
|
+
variant: SUGGESTION_VARIANT.CHIP,
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
text: "How can I help?",
|
|
453
|
+
type: MESSAGE_TYPE.PROMPT,
|
|
454
|
+
}),
|
|
455
|
+
);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("should preserve default status when initialArgs is provided", () => {
|
|
459
|
+
const result = initializer({ text: "Welcome" });
|
|
460
|
+
|
|
461
|
+
expect(result.status).toEqual({ loading: false });
|
|
462
|
+
});
|
|
463
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { jest } from "@jest/globals";
|
|
2
|
+
import fetchMock from "jest-fetch-mock";
|
|
3
|
+
import { ERROR_MESSAGE } from "../src/views/ResearchView/query/constants";
|
|
4
|
+
import { fetchResponse } from "../src/views/ResearchView/query/fetch";
|
|
5
|
+
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
fetchMock.enableMocks();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
fetchMock.resetMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe("fetchResponse", () => {
|
|
15
|
+
const mockCallbacks = (): {
|
|
16
|
+
onError: jest.Mock;
|
|
17
|
+
onSettled: jest.Mock;
|
|
18
|
+
onSuccess: jest.Mock;
|
|
19
|
+
} => ({
|
|
20
|
+
onError: jest.fn(),
|
|
21
|
+
onSettled: jest.fn(),
|
|
22
|
+
onSuccess: jest.fn(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should call onSuccess with data on successful response", async () => {
|
|
26
|
+
const mockData = { results: ["study1", "study2"] };
|
|
27
|
+
fetchMock.mockResponseOnce(JSON.stringify(mockData));
|
|
28
|
+
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const callbacks = mockCallbacks();
|
|
31
|
+
|
|
32
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
33
|
+
controller,
|
|
34
|
+
...callbacks,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(callbacks.onSuccess).toHaveBeenCalledWith(mockData);
|
|
38
|
+
expect(callbacks.onError).not.toHaveBeenCalled();
|
|
39
|
+
expect(callbacks.onSettled).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should call onError on rate limit (429)", async () => {
|
|
43
|
+
fetchMock.mockResponseOnce("", { status: 429 });
|
|
44
|
+
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const callbacks = mockCallbacks();
|
|
47
|
+
|
|
48
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
49
|
+
controller,
|
|
50
|
+
...callbacks,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(callbacks.onError).toHaveBeenCalledWith(
|
|
54
|
+
new Error(ERROR_MESSAGE.RATE_LIMITED),
|
|
55
|
+
);
|
|
56
|
+
expect(callbacks.onSuccess).not.toHaveBeenCalled();
|
|
57
|
+
expect(callbacks.onSettled).toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should call onError on non-ok response", async () => {
|
|
61
|
+
fetchMock.mockResponseOnce("", { status: 500 });
|
|
62
|
+
|
|
63
|
+
const controller = new AbortController();
|
|
64
|
+
const callbacks = mockCallbacks();
|
|
65
|
+
|
|
66
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
67
|
+
controller,
|
|
68
|
+
...callbacks,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(callbacks.onError).toHaveBeenCalledWith(
|
|
72
|
+
new Error(`${ERROR_MESSAGE.REQUEST_FAILED} (500)`),
|
|
73
|
+
);
|
|
74
|
+
expect(callbacks.onSuccess).not.toHaveBeenCalled();
|
|
75
|
+
expect(callbacks.onSettled).toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should not call onError when request is aborted", async () => {
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
controller.abort();
|
|
81
|
+
|
|
82
|
+
fetchMock.mockRejectOnce(new DOMException("Aborted", "AbortError"));
|
|
83
|
+
|
|
84
|
+
const callbacks = mockCallbacks();
|
|
85
|
+
|
|
86
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
87
|
+
controller,
|
|
88
|
+
...callbacks,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(callbacks.onError).not.toHaveBeenCalled();
|
|
92
|
+
expect(callbacks.onSuccess).not.toHaveBeenCalled();
|
|
93
|
+
expect(callbacks.onSettled).toHaveBeenCalled();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should call onSettled after success", async () => {
|
|
97
|
+
const mockData = { results: [] };
|
|
98
|
+
fetchMock.mockResponseOnce(JSON.stringify(mockData));
|
|
99
|
+
|
|
100
|
+
const controller = new AbortController();
|
|
101
|
+
const callbacks = mockCallbacks();
|
|
102
|
+
|
|
103
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
104
|
+
controller,
|
|
105
|
+
...callbacks,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(callbacks.onSuccess).toHaveBeenCalledTimes(1);
|
|
109
|
+
expect(callbacks.onSettled).toHaveBeenCalledTimes(1);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should call onSettled after error", async () => {
|
|
113
|
+
fetchMock.mockResponseOnce("", { status: 500 });
|
|
114
|
+
|
|
115
|
+
const controller = new AbortController();
|
|
116
|
+
const callbacks = mockCallbacks();
|
|
117
|
+
|
|
118
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
119
|
+
controller,
|
|
120
|
+
...callbacks,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(callbacks.onError).toHaveBeenCalledTimes(1);
|
|
124
|
+
expect(callbacks.onSettled).toHaveBeenCalledTimes(1);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should send POST request with correct body and headers", async () => {
|
|
128
|
+
fetchMock.mockResponseOnce(JSON.stringify({}));
|
|
129
|
+
|
|
130
|
+
const controller = new AbortController();
|
|
131
|
+
const callbacks = mockCallbacks();
|
|
132
|
+
|
|
133
|
+
await fetchResponse("https://api.example.com/search", "cancer studies", {
|
|
134
|
+
controller,
|
|
135
|
+
...callbacks,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
139
|
+
"https://api.example.com/search",
|
|
140
|
+
expect.objectContaining({
|
|
141
|
+
body: JSON.stringify({ query: "cancer studies" }),
|
|
142
|
+
headers: { "Content-Type": "application/json" },
|
|
143
|
+
method: "POST",
|
|
144
|
+
}),
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("should call onError with unknown error message for non-Error throws", async () => {
|
|
149
|
+
fetchMock.mockRejectOnce("string error" as unknown as Error);
|
|
150
|
+
|
|
151
|
+
const controller = new AbortController();
|
|
152
|
+
const callbacks = mockCallbacks();
|
|
153
|
+
|
|
154
|
+
await fetchResponse("https://api.example.com/search", "diabetes", {
|
|
155
|
+
controller,
|
|
156
|
+
...callbacks,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(callbacks.onError).toHaveBeenCalledWith(
|
|
160
|
+
new Error(ERROR_MESSAGE.UNKNOWN),
|
|
161
|
+
);
|
|
162
|
+
expect(callbacks.onSettled).toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
});
|