Skip to content

Conversation

@brobro10000
Copy link
Member

Initial consolidation of testing framework POC. Consolidate contexts, constants and API structures.

A reference tech is Pact that does a similar process with HTTP responses, while this frameworks hopes to mimic it with frontend context providers. It will allow for faster testing across features that have been consolidated.

Current POC is using Content Highlights. Currently WIP.

Pushes will look at the effect on test coverage and possible testing runtimes since we are reducing the overall amount of imports required per test.

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

@codecov
Copy link

codecov bot commented Jan 23, 2023

Codecov Report

❌ Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.77%. Comparing base (cd82047) to head (fa0fe39).
⚠️ Report is 748 commits behind head on master.

Files with missing lines Patch % Lines
...ty/ContentHighlightCatalogVisibilityRadioInput.jsx 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #959      +/-   ##
==========================================
+ Coverage   83.21%   83.77%   +0.56%     
==========================================
  Files         400      406       +6     
  Lines        8697     8722      +25     
  Branches     1798     1800       +2     
==========================================
+ Hits         7237     7307      +70     
+ Misses       1422     1377      -45     
  Partials       38       38              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@brobro10000 brobro10000 marked this pull request as ready for review February 2, 2023 14:10
* Sets enterpriseCuration.canOnlyViewHighlightSets to false if there are no highlight sets
* when the user enters content highlights dashboard.
*/
const setDefault = useCallback(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[curious] Can you expand on the rationale for this change? Why can't we define setDefault within the useEffect here?

@@ -0,0 +1,12 @@
import { camelCaseObject } from '@edx/frontend-platform';

const rawTestCourseData = require('./testCourseData.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might recommend looking into rosie (https://github.com/rosiejs/rosie) to generate these test data via factories instead of hardcoded JSON files.

initialStateValue,
testCourseAggregation,
} from '../../../../data/tests/ContentHighlightsTestData';
import 'jest-canvas-mock';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Might recommend putting this in setupTest.js so we load the canvas mocks for Jest across all tests in the repo, not just this one test file (similar to how to use jest-localstorage-mock).

const dropdownButton = screen.getByRole('button', { name: '1 of 5' });
userEvent.click(dropdownButton);
const number4 = screen.getByRole('button', { name: '4' });
// expect(number4).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove commented out line

import { ContentHighlightsContext, initialStateValue, testCourseAggregation } from '../../../../data/tests/ContentHighlightsTestData';
import { useContentHighlightsContext } from '../hooks';

const TestComponent = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is there a more explicit component name that might better describe its purpose than TestComponent?

Comment on lines +4 to +7
const rawTestCourseData = require('./testCourseData.json');
const rawTestCourseHighlights = require('./testCourseHighlights.json');
const testCourseAggregation = require('./testCourseAggregation.json');
const testHighlightSet = require('./testHighlightSet.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to another comment, might be worth looking into rosie or similar to generate JS objects using a factory, which would likely be a bit more maintainable/scalable/customizable.

"course:HarvardX+CS50AI": true,
"course:HarvardX+CS50P": true,
"course:HarvardX+CS50x": true
} No newline at end of file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The intent of this file isn't immediately obvious. Is there a more explicit file name beyond "course aggregation" to indicate what this is used for?

@@ -0,0 +1,63 @@
/* eslint-disable max-len */
/* eslint-disable react/jsx-filename-extension */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't ignore this rule. If this file is rendering JSX, it should be using the .jsx file extension.

enterpriseId: PropTypes.string,
}),
}),
value: PropTypes.shape(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit/curious] Should/can these empty PropTypes.shape() define their properties?

@@ -0,0 +1,6 @@
import { EnterpriseAppContext, initialStateValue } from './context';

export default {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If you're treating the default export as an object, you might use named exports instead with something like:

export { initialStateValue, EnterpriseAppContext } from './context';

@brobro10000
Copy link
Member Author

No longer needed.

@brobro10000 brobro10000 closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants