Skip to content

Commit 5a871d1

Browse files
authored
Merge pull request RedHatInsights#255 from apinkert/learn-journey
Add user journey support + learn tab
2 parents 4039845 + 9be3d49 commit 5a871d1

18 files changed

Lines changed: 2194 additions & 2 deletions

.storybook/hooks/scalprum.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Mock @scalprum/react-core for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
// Mock Models object for virtual assistant
7+
const mockModels = {
8+
ASK_RED_HAT: 'mock-ask-red-hat-model',
9+
};
10+
11+
// Mock useLoadModule hook - returns mock module and loading: false
12+
export const useLoadModule = () => [mockModels, { loading: false }];
13+
14+
// Mock useRemoteHook - returns empty hook result and loading: false
15+
export const useRemoteHook = () => ({
16+
hookResult: [null, () => {}], // Mock state and setState
17+
loading: false
18+
});
19+
20+
// Mock useGetState - returns empty state
21+
export const useGetState = () => ({});
22+
23+
// Mock other exports that might be needed
24+
export const initialize = () => {};
25+
export const getScalprum = () => ({});

.storybook/hooks/unleash.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Mock @unleash/proxy-client-react for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
// Mock useFlag hook - always returns false
7+
export const useFlag = () => false;
8+
9+
// Mock other exports
10+
export const FlagProvider = ({ children }) => children;
11+
export const UnleashClient = class {};
12+
export const useUnleashContext = () => ({});
13+
export const useVariant = () => ({ name: 'disabled', enabled: false });
14+
export const useFlags = () => [];

.storybook/hooks/useChrome.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Mock useChrome for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
import { defaultMockChrome } from '../mocks/chromeMock';
7+
8+
export default function useChrome() {
9+
// Return the mock chrome from window if available
10+
if (typeof window !== 'undefined' && window.insights?.chrome) {
11+
// @ts-ignore
12+
return window.insights.chrome;
13+
}
14+
15+
// Fallback to shared mock
16+
return defaultMockChrome;
17+
}
18+
19+
// Named export for compatibility
20+
export { useChrome };

.storybook/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { StorybookConfig } from '@storybook/react-webpack5';
22
import remarkGfm from 'remark-gfm';
3+
import path from 'path';
34

45
const config: StorybookConfig = {
56
stories: ['../src/docs/*.mdx', '../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
@@ -15,6 +16,7 @@ const config: StorybookConfig = {
1516
},
1617
},
1718
},
19+
'msw-storybook-addon',
1820
],
1921
framework: {
2022
name: '@storybook/react-webpack5',
@@ -24,6 +26,27 @@ const config: StorybookConfig = {
2426
defaultName: 'Documentation',
2527
},
2628
webpackFinal: async (config) => {
29+
// Mock external dependencies for Storybook (same pattern as insights-rbac-ui)
30+
config.resolve = {
31+
...config.resolve,
32+
alias: {
33+
...config.resolve?.alias,
34+
// External dependency mocks
35+
'@redhat-cloud-services/frontend-components/useChrome': path.resolve(
36+
process.cwd(),
37+
'.storybook/hooks/useChrome.tsx'
38+
),
39+
'@unleash/proxy-client-react': path.resolve(
40+
process.cwd(),
41+
'.storybook/hooks/unleash.js'
42+
),
43+
'@scalprum/react-core': path.resolve(
44+
process.cwd(),
45+
'.storybook/hooks/scalprum.js'
46+
),
47+
},
48+
};
49+
2750
// Add SCSS support
2851
config.module = config.module || {};
2952
config.module.rules = config.module.rules || [];
@@ -44,6 +67,7 @@ const config: StorybookConfig = {
4467
propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
4568
},
4669
},
70+
staticDirs: ['../public'],
4771
};
4872

4973
export default config;

.storybook/mocks/chromeMock.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Shared Chrome mock for Storybook
3+
* Single source of truth for chrome API mocking
4+
*/
5+
6+
export const defaultMockChrome = {
7+
auth: {
8+
getUser: async () => ({
9+
identity: {
10+
account_number: '12345',
11+
org_id: '67890',
12+
user: {
13+
username: 'testuser',
14+
email: 'test@example.com',
15+
first_name: 'Test',
16+
last_name: 'User',
17+
is_active: true,
18+
is_org_admin: false,
19+
},
20+
internal: {
21+
account_id: '12345',
22+
},
23+
},
24+
}),
25+
},
26+
getBundleData: () => ({ bundleId: 'insights' }),
27+
getAvailableBundles: () => [
28+
{ id: 'insights', title: 'Red Hat Insights' },
29+
{ id: 'ansible', title: 'Ansible Automation Platform' },
30+
{ id: 'openshift', title: 'OpenShift' },
31+
{ id: 'settings', title: 'Settings' },
32+
],
33+
updateDocumentTitle: (title: string) => {
34+
if (typeof document !== 'undefined') {
35+
document.title = title;
36+
}
37+
},
38+
hideGlobalFilter: () => {},
39+
isBeta: () => false,
40+
isProd: () => false,
41+
getEnvironment: () => 'stage',
42+
};

.storybook/preview.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
import type { Preview } from '@storybook/react-webpack5';
22
import '@patternfly/react-core/dist/styles/base.css';
33
import React from 'react';
4+
import { initialize, mswLoader } from 'msw-storybook-addon';
5+
import { defaultMockChrome } from './mocks/chromeMock';
6+
7+
// Set up global chrome mock immediately
8+
if (typeof window !== 'undefined') {
9+
// @ts-ignore
10+
window.insights = { chrome: defaultMockChrome };
11+
}
412

513
const preview: Preview = {
14+
beforeAll: async () => {
15+
// Initialize MSW with error on unhandled requests to catch missing mocks
16+
initialize({ onUnhandledRequest: 'warn' });
17+
},
18+
loaders: [mswLoader],
619
parameters: {
720
options: {
821
storySort: {
922
method: 'alphabetical',
10-
order: ['Documentation', '*'],
23+
order: ['Documentation', 'User Journeys', 'Components', '*'],
1124
},
1225
},
1326
layout: 'fullscreen',

0 commit comments

Comments
 (0)