Skip to content

Commit

Permalink
refactor(bannerMessages): sw-884 generic banners
Browse files Browse the repository at this point in the history
* bannerMessages, replace with generic banners
* bannerMessagesContext, hooks for remove, add banners
* productView, allow banner messages for all products
* redux, actions, types, reducer, restructure
  • Loading branch information
cdcabrera committed Apr 7, 2023
1 parent 3c4de82 commit f8209ef
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 736 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: error response 1`] = `
{
"data": {
"cloudigradeMismatch": false,
},
"error": true,
"fulfilled": undefined,
"pending": undefined,
}
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector and apply new messages: dispatch 1`] = `
[
[
{
"bannerMessages": [
{
"id": "lorem",
"title": "ipsum",
},
{
"id": "new message",
"title": "new message",
},
],
"type": "SET_BANNER_MESSAGES",
"viewId": "dolorSit",
},
],
]
`;

exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: mock store error response 1`] = `
{
"data": {
"cloudigradeMismatch": false,
},
"error": true,
"fulfilled": false,
"pending": false,
}
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector and remove messages: dispatch 1`] = `
[
[
{
"bannerMessages": [],
"type": "SET_BANNER_MESSAGES",
"viewId": "dolorSit",
},
],
]
`;

exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: mock store success response 1`] = `
{
"data": {
"cloudigradeMismatch": true,
exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selector: banner messages 1`] = `
[
{
"id": "lorem",
"title": "ipsum",
},
"error": false,
"fulfilled": true,
"pending": false,
}
`;

exports[`BannerMessagesContext should apply a hook for retrieving messages data from a selectors: success response 1`] = `
{
"data": {
"cloudigradeMismatch": false,
},
"error": undefined,
"fulfilled": true,
"pending": undefined,
}
]
`;

exports[`BannerMessagesContext should return specific properties: specific properties 1`] = `
{
"useGetAppMessages": [Function],
"useBannerMessages": [Function],
"useRemoveBannerMessages": [Function],
"useSetBannerMessages": [Function],
}
`;
22 changes: 9 additions & 13 deletions src/components/bannerMessages/__tests__/bannerMessages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,37 @@ import { BannerMessages } from '../bannerMessages';
describe('BannerMessages Component', () => {
it('should render a basic component', async () => {
const props = {
messages: [
useBannerMessages: () => [
{
id: 'loremIpsum',
title: 'Lorem ipsum title',
message: 'Lorem ipsum message'
}
],
useGetAppMessages: () => ({
data: {
loremIpsum: true
}
})
]
};
const component = await mountHookComponent(<BannerMessages {...props} />);

expect(component).toMatchSnapshot('basic');
});

it('should handle closing messages from state', async () => {
const mockRemove = jest.fn();
const props = {
messages: [
useBannerMessages: () => [
{
id: 'dolorSit',
title: 'Dolor sit title',
message: 'Dolor sit message'
id: 'loremIpsum',
title: 'Lorem ipsum title',
message: 'Lorem ipsum message'
}
],
useGetAppMessages: () => ({ data: { dolorSit: true } })
useRemoveBannerMessages: () => mockRemove
};

const component = await mountHookComponent(<BannerMessages {...props} />);
expect(component).toMatchSnapshot('state messages, ON');

component.find(AlertActionCloseButton).first().simulate('click');

expect(component.render()).toMatchSnapshot('state messages, OFF');
expect(mockRemove.mock.calls).toMatchSnapshot('state messages, OFF id');
});
});
104 changes: 39 additions & 65 deletions src/components/bannerMessages/__tests__/bannerMessagesContext.test.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,60 @@
import { context, useGetAppMessages } from '../bannerMessagesContext';
import { rhsmConstants } from '../../../services/rhsm/rhsmConstants';
import { context, useBannerMessages, useRemoveBannerMessages, useSetBannerMessages } from '../bannerMessagesContext';

describe('BannerMessagesContext', () => {
it('should return specific properties', () => {
expect(context).toMatchSnapshot('specific properties');
});

it('should apply a hook for retrieving messages data from a selectors', () => {
const { result: errorResponse } = shallowHook(() =>
useGetAppMessages({
useSelectorsResponse: () => ({
error: true,
data: {
messages: {}
it('should apply a hook for retrieving messages data from a selector', async () => {
const { result } = await shallowHook(() =>
useBannerMessages({
useSelector: () => [
{
id: 'lorem',
title: 'ipsum'
}
})
]
})
);

expect(errorResponse).toMatchSnapshot('error response');
expect(result).toMatchSnapshot('banner messages');
});

const { result: successResponse } = shallowHook(() =>
useGetAppMessages({
useSelectorsResponse: () => ({
fulfilled: true,
data: {
messages: {}
it('should apply a hook for retrieving messages data from a selector and apply new messages', async () => {
const mockDispatch = jest.fn();
const { result } = await mountHook(() =>
useSetBannerMessages({
useDispatch: () => mockDispatch,
useProduct: () => ({ productId: 'dolorSit' }),
useBannerMessages: () => [
{
id: 'lorem',
title: 'ipsum'
}
})
]
})
);

expect(successResponse).toMatchSnapshot('success response');

const { result: mockStoreSuccessResponse } = shallowHook(
() =>
useGetAppMessages({
useProduct: () => ({ productId: 'loremIpsum' })
}),
{
state: {
messages: {
report: {
loremIpsum: {
fulfilled: true,
data: {
data: [
{
[rhsmConstants.RHSM_API_RESPONSE_TALLY_CAPACITY_META_TYPES.HAS_CLOUDIGRADE_MISMATCH]: true
}
]
}
}
}
}
}
}
);

expect(mockStoreSuccessResponse).toMatchSnapshot('mock store success response');
result('new message');
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch');
});

const { result: mockStoreErrorResponse } = shallowHook(
() =>
useGetAppMessages({
useProduct: () => ({ productId: 'loremIpsum' })
}),
{
state: {
messages: {
report: {
loremIpsum: {
error: true,
data: {
data: []
}
}
}
it('should apply a hook for retrieving messages data from a selector and remove messages', async () => {
const mockDispatch = jest.fn();
const { result } = await mountHook(() =>
useRemoveBannerMessages({
useDispatch: () => mockDispatch,
useProduct: () => ({ productId: 'dolorSit' }),
useBannerMessages: () => [
{
id: 'lorem',
title: 'ipsum'
}
}
}
]
})
);

expect(mockStoreErrorResponse).toMatchSnapshot('mock store error response');
result('ipsum');
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch');
});
});
Loading

0 comments on commit f8209ef

Please sign in to comment.