Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(context): add notification context provider #676

Merged
merged 2 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ import '@app/app.css';
import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { Provider } from 'react-redux';
import { store } from '@app/Shared/Redux/ReduxStore';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const App: React.FunctionComponent = () => (
<ServiceContext.Provider value={defaultServices}>
<Provider store={store}>
<Router>
<AppLayout>
<AppRoutes />
</AppLayout>
</Router>
</Provider>
<NotificationsContext.Provider value={NotificationsInstance}>
<Provider store={store}>
<Router>
<AppLayout>
<AppRoutes />
</AppLayout>
</Router>
</Provider>
</NotificationsContext.Provider>
</ServiceContext.Provider>
);

Expand Down
5 changes: 4 additions & 1 deletion src/test/Agent/AgentLiveProbes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { DeleteActiveProbes } from '@app/Modal/DeleteWarningUtils';
import { AgentLiveProbes } from '@app/Agent/AgentLiveProbes';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' };
Expand Down Expand Up @@ -142,7 +143,9 @@ describe('<AgentLiveProbes />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<AgentLiveProbes />
<NotificationsContext.Provider value={NotificationsInstance}>
<AgentLiveProbes />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Agent/AgentProbeTemplates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { DeleteProbeTemplates } from '@app/Modal/DeleteWarningUtils';
import { AgentProbeTemplates } from '@app/Agent/AgentProbeTemplates';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockMessageType = { type: 'application', subtype: 'json' } as MessageType;

Expand Down Expand Up @@ -126,7 +127,9 @@ describe('<AgentProbeTemplates />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<AgentProbeTemplates agentDetected={true} />
<NotificationsContext.Provider value={NotificationsInstance}>
<AgentProbeTemplates agentDetected={true} />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Archives/AllArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { NotificationMessage } from '@app/Shared/Services/NotificationChannel.se
import { AllArchivedRecordingsTable } from '@app/Archives/AllArchivedRecordingsTable';
import { ArchivedRecording, RecordingDirectory } from '@app/Shared/Services/Api.service';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl1 = 'service:jmx:rmi://someUrl1';
const mockJvmId1 = 'fooJvmId1';
Expand Down Expand Up @@ -184,7 +185,9 @@ describe('<AllArchivedRecordingsTable />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<AllArchivedRecordingsTable />
<NotificationsContext.Provider value={NotificationsInstance}>
<AllArchivedRecordingsTable />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Archives/AllTargetsArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { NotificationMessage } from '@app/Shared/Services/NotificationChannel.se
import { AllTargetsArchivedRecordingsTable } from '@app/Archives/AllTargetsArchivedRecordingsTable';
import { Target } from '@app/Shared/Services/Target.service';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl1 = 'service:jmx:rmi://someUrl1';
const mockAlias1 = 'fooTarget1';
Expand Down Expand Up @@ -234,7 +235,9 @@ describe('<AllTargetsArchivedRecordingsTable />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<AllTargetsArchivedRecordingsTable />
<NotificationsContext.Provider value={NotificationsInstance}>
<AllTargetsArchivedRecordingsTable />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Archives/Archives.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { of } from 'rxjs';
import { Archives } from '@app/Archives/Archives';
import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

jest.mock('@app/Recordings/ArchivedRecordingsTable', () => {
return {
Expand Down Expand Up @@ -142,7 +143,9 @@ describe('<Archives />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<Archives />
<NotificationsContext.Provider value={NotificationsInstance}>
<Archives />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
57 changes: 42 additions & 15 deletions src/test/Common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { setupStore } from '@app/Shared/Redux/ReduxStore';
import { defaultServices, ServiceContext } from '@app/Shared/Services/Services';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
// userEvent functions are recommended to be called in tests (i.e it()).
Expand All @@ -51,10 +52,14 @@ export const renderDefault = (
ui: React.ReactElement,
{
user = userEvent.setup(), // Create a default user session
notifications = NotificationsInstance,
...renderOptions
} = {}
) => {
return { user, ...render(ui, { ...renderOptions }) };
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return <NotificationsContext.Provider value={notifications}>{children}</NotificationsContext.Provider>;
};
return { user, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
};

export const renderWithReduxStore = (
Expand All @@ -63,11 +68,16 @@ export const renderWithReduxStore = (
preloadState = {},
store = setupStore(preloadState), // Create a new store instance if no store was passed in
user = userEvent.setup(), // Create a default user session
notifications = NotificationsInstance,
...renderOptions
} = {}
) => {
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return <Provider store={store}>{children}</Provider>;
return (
<NotificationsContext.Provider value={notifications}>
<Provider store={store}>{children}</Provider>
</NotificationsContext.Provider>
);
};
return { store, user, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
};
Expand All @@ -76,12 +86,17 @@ export const renderWithServiceContext = (
ui: React.ReactElement,
{
services = defaultServices,
notifications = NotificationsInstance,
user = userEvent.setup(), // Create a default user session
...renderOptions
} = {}
) => {
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return <ServiceContext.Provider value={services}>{children}</ServiceContext.Provider>;
return (
<ServiceContext.Provider value={services}>
<NotificationsContext.Provider value={notifications}>{children}</NotificationsContext.Provider>
</ServiceContext.Provider>
);
};
return { user, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
};
Expand All @@ -91,14 +106,17 @@ export const renderWithRouter = (
{
history = createMemoryHistory({ initialEntries: ['/'] }),
user = userEvent.setup(), // Create a default user session
notifications = NotificationsInstance,
...renderOptions
} = {}
) => {
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<Router location={history.location} history={history}>
{children}
</Router>
<NotificationsContext.Provider value={notifications}>
<Router location={history.location} history={history}>
{children}
</Router>
</NotificationsContext.Provider>
);
};
return { user, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
Expand All @@ -110,14 +128,17 @@ export const renderWithServiceContextAndReduxStore = (
preloadState = {},
store = setupStore(preloadState), // Create a new store instance if no store was passed in
services = defaultServices,
notifications = NotificationsInstance,
user = userEvent.setup(), // Create a default user session
...renderOptions
} = {}
) => {
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<ServiceContext.Provider value={services}>
<Provider store={store}>{children}</Provider>
<NotificationsContext.Provider value={notifications}>
<Provider store={store}>{children}</Provider>
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
};
Expand All @@ -128,6 +149,7 @@ export const renderWithServiceContextAndRouter = (
ui: React.ReactElement,
{
services = defaultServices,
notifications = NotificationsInstance,
user = userEvent.setup(), // Create a default user session
history = createMemoryHistory({ initialEntries: ['/'] }),
...renderOptions
Expand All @@ -136,9 +158,11 @@ export const renderWithServiceContextAndRouter = (
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<ServiceContext.Provider value={services}>
<Router location={history.location} history={history}>
{children}
</Router>
<NotificationsContext.Provider value={notifications}>
<Router location={history.location} history={history}>
{children}
</Router>
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
};
Expand All @@ -151,6 +175,7 @@ export const renderWithServiceContextAndReduxStoreWithRouter = (
preloadState = {},
store = setupStore(preloadState), // Create a new store instance if no store was passed in
services = defaultServices,
notifications = NotificationsInstance,
user = userEvent.setup(), // Create a default user session
history = createMemoryHistory({ initialEntries: ['/'] }),
...renderOptions
Expand All @@ -159,11 +184,13 @@ export const renderWithServiceContextAndReduxStoreWithRouter = (
const Wrapper = ({ children }: PropsWithChildren<{}>) => {
return (
<ServiceContext.Provider value={services}>
<Provider store={store}>
<Router location={history.location} history={history}>
{children}
</Router>
</Provider>
<NotificationsContext.Provider value={notifications}>
<Provider store={store}>
<Router location={history.location} history={history}>
{children}
</Router>
</Provider>
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
};
Expand Down
5 changes: 4 additions & 1 deletion src/test/CreateRecording/CustomRecordingForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jest.mock('@patternfly/react-core', () => ({
}));

import { CustomRecordingForm } from '@app/CreateRecording/CustomRecordingForm';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' };
Expand Down Expand Up @@ -102,7 +103,9 @@ describe('<CustomRecordingForm />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<CustomRecordingForm />
<NotificationsContext.Provider value={NotificationsInstance}>
<CustomRecordingForm />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
11 changes: 7 additions & 4 deletions src/test/Dashboard/Dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ import React from 'react';
import { defaultServices, ServiceContext } from '@app/Shared/Services/Services';
import { Target } from '@app/Shared/Services/Target.service';
import { of } from 'rxjs';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockFooConnectUrl = 'service:jmx:rmi://someFooUrl';
// Test fails if new Map([['REALM', 'Custom Targets']]) is used, most likely since 'cryostat' Map is not being utilized

const mockFooTarget: Target = {
connectUrl: mockFooConnectUrl,
alias: 'fooTarget',
annotations: {
cryostat: new Map(),
platform: new Map(),
cryostat: {},
platform: {},
},
};

Expand All @@ -70,7 +71,9 @@ describe('<Dashboard />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<Dashboard></Dashboard>
<NotificationsContext.Provider value={NotificationsInstance}>
<Dashboard />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Events/EventTemplates.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { EventTemplates } from '@app/Events/EventTemplates';
import { DeleteWarningType } from '@app/Modal/DeleteWarningUtils';
import { TargetService } from '@app/Shared/Services/Target.service';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' };
Expand Down Expand Up @@ -123,7 +124,9 @@ describe('<EventTemplates />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<EventTemplates />
<NotificationsContext.Provider value={NotificationsInstance}>
<EventTemplates />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Events/EventTypes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { ServiceContext, defaultServices, Services } from '@app/Shared/Services/
import { TargetService } from '@app/Shared/Services/Target.service';
import { EventType, EventTypes } from '@app/Events/EventTypes';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

const mockConnectUrl = 'service:jmx:rmi://someUrl';
const mockTarget = { connectUrl: mockConnectUrl, alias: 'fooTarget' };
Expand All @@ -68,7 +69,9 @@ describe('<EventTypes />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<EventTypes />
<NotificationsContext.Provider value={NotificationsInstance}>
<EventTypes />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/RecordingMetadata.tsx/BulkEditLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { ActiveRecording, ArchivedRecording, RecordingState } from '@app/Shared/Services/Api.service';
import { NotificationMessage } from '@app/Shared/Services/NotificationChannel.service';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

jest.mock('@patternfly/react-core', () => ({
...jest.requireActual('@patternfly/react-core'),
Expand Down Expand Up @@ -144,7 +145,9 @@ describe('<BulkEditLabels />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<BulkEditLabels checkedIndices={activeCheckedIndices} isTargetRecording={true} />
<NotificationsContext.Provider value={NotificationsInstance}>
<BulkEditLabels checkedIndices={activeCheckedIndices} isTargetRecording={true} />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
5 changes: 4 additions & 1 deletion src/test/Recordings/Recordings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { ServiceContext, defaultServices } from '@app/Shared/Services/Services';
import { Recordings } from '@app/Recordings/Recordings';
import { Target } from '@app/Shared/Services/Target.service';
import { renderWithServiceContext } from '../Common';
import { NotificationsContext, NotificationsInstance } from '@app/Notifications/Notifications';

jest.mock('@app/Recordings/ActiveRecordingsTable', () => {
return {
Expand Down Expand Up @@ -149,7 +150,9 @@ describe('<Recordings />', () => {
await act(async () => {
tree = renderer.create(
<ServiceContext.Provider value={defaultServices}>
<Recordings />
<NotificationsContext.Provider value={NotificationsInstance}>
<Recordings />
</NotificationsContext.Provider>
</ServiceContext.Provider>
);
});
Expand Down
Loading