Skip to content

Commit

Permalink
test: review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jun 20, 2024
1 parent 3cfe51f commit 7aa020b
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 151 deletions.
24 changes: 20 additions & 4 deletions src/components/i18n/__tests__/__snapshots__/i18n.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,19 @@ exports[`I18n Component should generate a predictable locale key output snapshot
"keys": [
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'completed', 'titleGlobal'] })",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'error', 'title'] })",
},
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'error', 'description'] })",
},
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'completed', 'descriptionGlobal'] })",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'completed', 'titleGlobal'], count: existingExports.length })",
},
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'completed', 'descriptionGlobal'], count: existingExports.length })",
},
{
"key": "curiosity-toolbar.notifications",
Expand All @@ -930,11 +938,11 @@ exports[`I18n Component should generate a predictable locale key output snapshot
},
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'pending', 'titleGlobal'] })",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'error', 'title'] })",
},
{
"key": "curiosity-toolbar.notifications",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'pending', 'descriptionGlobal'] })",
"match": "translate('curiosity-toolbar.notifications', { context: ['export', 'error', 'description'] })",
},
{
"key": "curiosity-toolbar.notifications",
Expand Down Expand Up @@ -1256,6 +1264,14 @@ exports[`I18n Component should have locale keys that exist in the default langua
"file": "src/redux/actions/platformActions.js",
"key": "curiosity-toolbar.notifications",
},
{
"file": "src/redux/actions/platformActions.js",
"key": "curiosity-toolbar.notifications",
},
{
"file": "src/redux/actions/platformActions.js",
"key": "curiosity-toolbar.notifications",
},
]
`;

Expand Down
69 changes: 18 additions & 51 deletions src/components/toolbar/__tests__/toolbarFieldExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('ToolbarFieldExport Component', () => {
it('should handle updating export through redux state with component', () => {
const props = {
useOnSelect: () => jest.fn(),
useExport: () => ({ checkExports: jest.fn() })
useExport: () => ({ checkAllExports: jest.fn() })
};

const component = renderComponent(<ToolbarFieldExport {...props} />);
Expand Down Expand Up @@ -80,27 +80,15 @@ describe('ToolbarFieldExport Component', () => {
useProduct: () => ({
productId: 'loremIpsum'
}),
useSelectors: () => [
{
data: {
data: {
products: {
loremIpsum: {
isCompleted: false,
isPending: true,
completed: [],
pending: [
{
status: PLATFORM_API_EXPORT_STATUS_TYPES.PENDING,
format: 'dolorSit'
}
]
}
}
}
useSelector: () => ({
isPending: true,
pending: [
{
status: PLATFORM_API_EXPORT_STATUS_TYPES.PENDING,
format: 'dolorSit'
}
}
]
]
})
})
);
await unmountPolling();
Expand All @@ -111,31 +99,10 @@ describe('ToolbarFieldExport Component', () => {
useProduct: () => ({
productId: 'loremIpsum'
}),
useSelectors: () => [
{
app: {
exports: {
data: {
data: {
products: {
loremIpsum: {
isCompleted: true,
isPending: false,
completed: [
{
status: PLATFORM_API_EXPORT_STATUS_TYPES.COMPLETE,
format: 'dolorSit'
}
],
pending: []
}
}
}
}
}
}
}
]
useSelector: () => ({
isPending: false,
pending: []
})
})
);
await unmountCompleted();
Expand Down Expand Up @@ -163,21 +130,21 @@ describe('ToolbarFieldExport Component', () => {
expect(mockServiceCreateExport.mock.calls).toMatchSnapshot('createExport');

// confirm attempt at getting an existing export status
const mockServiceGetExistingExports = jest.fn().mockImplementation(
const mockServiceGetExistingExportsStatus = jest.fn().mockImplementation(
(...args) =>
dispatch =>
dispatch(...args)
);
const {
result: { checkExports },
result: { checkAllExports },
unmount: unmountStatus
} = await renderHook(() =>
useExport({
getExistingExports: mockServiceGetExistingExports
getExistingExportsStatus: mockServiceGetExistingExportsStatus
})
);
checkExports();
checkAllExports();
await unmountStatus();
expect(mockServiceGetExistingExports).toHaveBeenCalledTimes(1);
expect(mockServiceGetExistingExportsStatus).toHaveBeenCalledTimes(1);
});
});
24 changes: 8 additions & 16 deletions src/components/toolbar/toolbarFieldExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,24 @@ const toolbarFieldOptions = Object.values(FIELD_TYPES).map(type => ({
*
* @param {object} options
* @param {Function} options.useProduct
* @param {Function} options.useSelectors
* @param {Function} options.useSelector
* @returns {{isProductPending: boolean, productPendingFormats: Array<string>}}
*/
const useExportStatus = ({
useProduct: useAliasProduct = useProduct,
useSelectors: useAliasSelectors = storeHooks.reactRedux.useSelectors
useSelector: useAliasSelector = storeHooks.reactRedux.useSelector
} = {}) => {
const { productId } = useAliasProduct();
const [product, global] = useAliasSelectors([
({ app }) => app?.exports?.[productId],
({ app }) => app?.exports?.global
]);
const { isPending, pending } = useAliasSelector(({ app }) => app?.exports?.[productId], {});

const pendingProductFormats = [];
const isProductPending = product?.isPending || global?.data?.data?.products?.[productId]?.isPending || false;
const isProductPending = isPending || false;

if (isProductPending) {
const convert = arr => (Array.isArray(arr) && arr.map(({ format: productFormat }) => productFormat)) || [];
pendingProductFormats.push(
...Array.from(
new Set([
...convert(product?.data?.data?.products?.[productId]?.pending),
...convert(global?.data?.data?.products?.[productId]?.pending)
])
)
);
const pendingList = pending;
if (Array.isArray(pendingList)) {
pendingProductFormats.push(...pendingList.map(({ format: productFormat }) => productFormat));
}
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,52 @@ exports[`PlatformActions Should return a dispatch object for the hideGlobalFilte
`;

exports[`PlatformActions Should return response content for createExport method: dispatch object 1`] = `
[
[
[
[Function],
{
"meta": {
"id": undefined,
"notifications": {
"pending": {
"dismissable": true,
"id": "swatch-create-export-undefined",
"title": "t(curiosity-toolbar.notifications_export_pending, {"context":"title"})",
"variant": "info",
},
"rejected": {
"description": "t(curiosity-toolbar.notifications_export_error, {"context":"description"})",
"dismissable": true,
"title": "t(curiosity-toolbar.notifications_export_error, {"context":"title"})",
"variant": "warning",
},
},
},
"payload": Promise {},
"type": "SET_PLATFORM_EXPORT_CREATE",
},
],
],
]
`;

exports[`PlatformActions Should return response content for getExistingExports method: dispatch object 1`] = `
[
[
{
"meta": {
"notifications": {
"fulfilled": {
"description": "t(curiosity-toolbar.notifications_export_completed, {"context":"descriptionGlobal","count":0})",
"dismissable": true,
"title": "t(curiosity-toolbar.notifications_export_completed, {"context":"titleGlobal","count":0})",
"variant": "success",
},
"pending": {
"dismissable": true,
"id": "swatch-create-export",
"title": "t(curiosity-toolbar.notifications_export_pending, {"context":"title"})",
"title": "Continuing reports download",
"variant": "info",
},
"rejected": {
"description": "t(curiosity-toolbar.notifications_export_error, {"context":"description"})",
Expand All @@ -27,25 +64,18 @@ exports[`PlatformActions Should return response content for createExport method:
},
},
"payload": Promise {},
"type": "SET_PLATFORM_EXPORT_CREATE",
"type": "SET_PLATFORM_EXPORT_STATUS",
},
],
]
`;

exports[`PlatformActions Should return response content for getExistingExports method: dispatch object 1`] = `
exports[`PlatformActions Should return response content for getExistingExportsStatus method: dispatch object 1`] = `
[
[
{
"meta": {
"id": "global",
"notifications": {
"pending": {
"description": "t(curiosity-toolbar.notifications_export_pending, {"context":"descriptionGlobal"})",
"dismissable": true,
"id": "swatch-global-export",
"title": "t(curiosity-toolbar.notifications_export_pending, {"context":"titleGlobal"})",
},
"rejected": {
"description": "t(curiosity-toolbar.notifications_export_error, {"context":"description"})",
"dismissable": true,
Expand All @@ -61,14 +91,35 @@ exports[`PlatformActions Should return response content for getExistingExports m
]
`;

exports[`PlatformActions Should return response content for setExportStatus method: dispatch object 1`] = `
exports[`PlatformActions Should return response content for removeExistingExports method: dispatch object 1`] = `
[
[
{
"meta": {
"id": undefined,
"notifications": {
"rejected": {
"description": "t(curiosity-toolbar.notifications_export_error, {"context":"description"})",
"dismissable": true,
"title": "t(curiosity-toolbar.notifications_export_error, {"context":"title"})",
"variant": "warning",
},
},
},
"payload": Promise {},
"type": "DELETE_EXPORT",
},
],
]
`;

exports[`PlatformActions Should return response content for setExportStatus method: dispatch object 1`] = `
[
[
{
"completed": [],
"id": undefined,
"isPending": false,
"pending": [],
"type": "SET_PLATFORM_EXPORT_STATUS",
},
],
Expand Down
22 changes: 17 additions & 5 deletions src/redux/actions/__tests__/platformActions.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { applyMiddleware, combineReducers, legacy_createStore as createStore } from 'redux';
import moxios from 'moxios';
import { promiseMiddleware } from '../../middleware';
import { platformActions, setExportStatus } from '../platformActions';
import { platformActions } from '../platformActions';
import { appReducer } from '../../reducers';

describe('PlatformActions', () => {
Expand Down Expand Up @@ -51,19 +51,31 @@ describe('PlatformActions', () => {
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});

it('Should return response content for setExportStatus method', () => {
it('Should return response content for getExistingExports method', () => {
const mockDispatch = jest.fn();
setExportStatus(mockDispatch)();
platformActions.getExistingExports([])(mockDispatch);
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});

it('Should return response content for getExistingExports method', () => {
it('Should return response content for getExistingExportsStatus method', () => {
const mockDispatch = jest.fn();
platformActions.getExistingExports()(mockDispatch);
platformActions.getExistingExportsStatus()(mockDispatch);
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});

it('Should return a dispatch object for the hideGlobalFilter method', () => {
expect(platformActions.hideGlobalFilter()).toMatchSnapshot('dispatch object');
});

it('Should return response content for removeExistingExports method', () => {
const mockDispatch = jest.fn();
platformActions.removeExistingExports([])(mockDispatch);
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});

it('Should return response content for setExportStatus method', () => {
const mockDispatch = jest.fn();
platformActions.setExportStatus()(mockDispatch);
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});
});
Loading

0 comments on commit 7aa020b

Please sign in to comment.