From f9201d933172c07d619cb8a91ad3e96f1a423e4b Mon Sep 17 00:00:00 2001 From: Chris Deery <3932645+cdeery@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:11:26 -0400 Subject: [PATCH] fix: log errors on no results (#39) --- .../view-results/ViewResults.jsx | 15 +++++++++ .../view-results/test/ViewResults.test.jsx | 31 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/skills-builder/skills-builder-modal/view-results/ViewResults.jsx b/src/skills-builder/skills-builder-modal/view-results/ViewResults.jsx index 0d1b06b..c78127b 100644 --- a/src/skills-builder/skills-builder-modal/view-results/ViewResults.jsx +++ b/src/skills-builder/skills-builder-modal/view-results/ViewResults.jsx @@ -54,6 +54,21 @@ const ViewResults = () => { }, is_default: true, }); + + // Check if any LOB doesn't have a recommendation for a job + results.forEach((jobResult) => { + let hasAnyRecommendations = false; + productTypes.current.forEach((lob) => { + if (jobResult.recommendations[lob].length === 0) { + logError(`Job [${jobResult.name}] has no recommendations for ${lob}`); + } else { + hasAnyRecommendations = true; + } + }); + if (!hasAnyRecommendations) { + logError(`Job [${jobResult.name}] has no recommendations for any LOB in [${productTypes.current}]`); + } + }); }; getAllRecommendations() diff --git a/src/skills-builder/skills-builder-modal/view-results/test/ViewResults.test.jsx b/src/skills-builder/skills-builder-modal/view-results/test/ViewResults.test.jsx index 108b284..18789aa 100644 --- a/src/skills-builder/skills-builder-modal/view-results/test/ViewResults.test.jsx +++ b/src/skills-builder/skills-builder-modal/view-results/test/ViewResults.test.jsx @@ -3,6 +3,7 @@ import { } from '@testing-library/react'; import { mergeConfig } from '@edx/frontend-platform'; import { sendTrackEvent } from '@edx/frontend-platform/analytics'; +import { logError } from '@edx/frontend-platform/logging'; import messages from '../messages'; import { SkillsBuilderWrapperWithContext, contextValue, dispatchMock } from '../../../test/setupSkillsBuilder'; import { getProductRecommendations } from '../../../utils/search'; @@ -17,6 +18,10 @@ jest.mock('../data/hooks', () => ({ useProductTypes: jest.fn(), })); +jest.mock('@edx/frontend-platform/logging', () => ({ + logError: jest.fn(), +})); + const renderSkillsBuilderWrapper = ( value = { ...contextValue, @@ -169,6 +174,7 @@ describe('view-results', () => { }); it('hides a LOB if there are no results', async () => { expect(screen.queryByText(messages.productTypeBootCampDescription.defaultMessage)).toBeNull(); + expect(logError).toHaveBeenCalledTimes(2); // These should all work. expect(screen.getByText(messages.productTypeDegreeDescription.defaultMessage)).toBeTruthy(); expect(screen.getByText(messages.productTypeExecutiveEducationDescription.defaultMessage)).toBeTruthy(); @@ -176,6 +182,31 @@ describe('view-results', () => { expect(screen.getByText(messages.productTypeCourseDescription.defaultMessage)).toBeTruthy(); }); }); + + describe('Product lines are hidden with no results', () => { + beforeAll(() => { + useProductTypes.mockImplementation(() => (['boot_camp', 'course'])); + + // Don't return anything for any LOB + getProductRecommendations.mockImplementation(() => []); + // Restore the mock to the expected value for the other tests. + afterEach(() => { + getProductRecommendations.mockImplementation(() => ( + mockData.productRecommendations + )); + useProductTypes.mockImplementation(() => (['2U_degree', 'boot_camp', 'executive_education', 'program', 'course'])); + }); + }); + it('Sends an error if there are no results for any LOB', async () => { + expect(logError).toHaveBeenCalledTimes(6); + expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for boot_camp'); + expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for course'); + expect(logError).toHaveBeenCalledWith('Job [Prospector] has no recommendations for any LOB in [boot_camp,course]'); + expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for boot_camp'); + expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for course'); + expect(logError).toHaveBeenCalledWith('Job [Mirror Breaker] has no recommendations for any LOB in [boot_camp,course]'); + }); + }); }); describe('show all button', () => {