Repository navigation
refactor: port the modules the outline tab shares to frontend-base - #2251
brian-smith-tcril wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## bsmith/progress-entrance-exam #2251 +/- ##
=================================================================
+ Coverage 96.79% 96.82% +0.03%
=================================================================
Files 478 485 +7
Lines 7386 7473 +87
Branches 1727 1739 +12
=================================================================
+ Hits 7149 7236 +87
Misses 223 223
Partials 14 14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
d09cf17 to
47f5333
Compare
47f5333 to
29a67cf
Compare
shared/effort-estimate, alerts/course-start-alert and the account activation alert (alerts/logistration-alert/AccountActivationAlert.jsx, messages.ts) move to the same paths under frontend-base/src, with manifest lines. Nothing renders them on a route yet. The account activation alert's request comes with it: courseware/data/ api.js gains sendActivationEmail, and courseware/data/index.js ports exporting that one name; getResumeBlock and getSequenceForUnitDeprecated stay commented out there until #2195. The alert reads the cookie domain from the app config's SESSION_COOKIE_DOMAIN, which has no bundled default, where master read process.env, and the site name from the site config. The package declares js-cookie. course-start-alert ports whole: the outline tab reads the alert, and the masquerade banner has no caller until #2194. CourseStartAlert drops the ?? {} after its metadata read: without metadata it throws either way, so the default only moved the throw. The banner keeps its own, which renders the banner with today's date, and gets a case. EffortEstimate drops its defaultProps, a null class name that classNames skips as it does an absent one. For the package's lint, the masquerade banner's multi-line date value gains parentheses and the activities message gains a description. master covers these modules only through the suites of the outline and progress tabs. Here each gets a test of its own: EffortEstimate.test.tsx, course-start-alert/hooks.test.tsx for both hooks and both components, and AccountActivationAlert.test.tsx, which sets the cookie on the document and lets js-cookie read and remove it. The setup file's pattern for Paragon's own defaultProps warnings (openedx/paragon#3043) gains the four modal components the account activation alert mounts. Part of #2191. Co-Authored-By: Claude <[email protected]>
29a67cf to
5cdad42
Compare
arbrandes
left a comment
There was a problem hiding this comment.
Approved with two suggestions.
|
|
||
| const showAccountActivationAlert = Cookies.get('show-account-activation-popup'); | ||
| if (showAccountActivationAlert !== undefined) { | ||
| Cookies.remove('show-account-activation-popup', { path: '/', domain: getAppConfig(appId).SESSION_COOKIE_DOMAIN }); |
There was a problem hiding this comment.
We should probably add SESSION_COOKIE_DOMAIN: null to the app's default config (frontend-base/src/app.ts:9-15). It's the only key the package reads that isn't listed there, and that list is the closest thing an operator has to documentation of what can be set.
It matters a bit more than the others: when the LMS sets the cookie on a parent domain and the operator hasn't set this key, the cookie is never removed and the activation alert silently never opens.
Behavior doesn't change with a null default: the new test already resets the key to null and passes.
| it('gives today as the start date when the course metadata is gone from the cache', () => { | ||
| const { container } = render(<CourseStartMasqueradeBanner payload={{ courseId }} />); | ||
|
|
||
| const today = new Intl.DateTimeFormat('en').format(new Date()); | ||
| expect(container).toHaveTextContent(`The course starts on ${today}.`); | ||
| }); |
There was a problem hiding this comment.
I'm not sure this case is worth pinning (optional). I'd drop the ?? {} and this case together, as the PR already does for the course start alert. The case asserts that staff are told the course starts today, which is wrong, and the banner only shows once the metadata says someone is masquerading, so it can't be reached without metadata anyway.
Fine to leave if you'd rather keep master's line as it is.
Summary
The modules Learning's outline tab shares with other pages now live in the frontend-base package: the effort estimate (
shared/effort-estimate/), the course start alert and its masquerade banner (alerts/course-start-alert/), and the account activation alert with the request it sends. No user-facing change: no route renders any of it until the outline tab ports in the next layer of this stack, and the legacy tree undersrc/is untouched.Part of #1905. Part of #2191. Stacked above #2249; the outline tab follows as the layer above this one.
Note
For reviewers: the ported files are added under
frontend-base/src/as new files, so this diff cannot show what changed frommaster. Theport-diffscript in #2234's description prints that diff, fromfrontend-base/manifest.tsv. Three of the ported files are identical tomaster's:course-start-alert/hooks.js,course-start-alert/index.jsandeffort-estimate/index.js.What changed
masterremoves theshow-account-activation-popupcookie onprocess.env.SESSION_COOKIE_DOMAIN. Here the domain isgetAppConfig(appId).SESSION_COOKIE_DOMAIN, an app config key with no bundled default: an operator who sets nothing gets the cookie removed on the serving host, asmasterdoes with the variable unset. The continue button's site name isgetSiteConfig().siteName.sendActivationEmailand the courseware data index. The alert imports its request fromcourseware/data, socourseware/data/api.jsgainssendActivationEmailandcourseware/data/index.jsports exporting that one name. The other two names the index re-exports onmaster,getResumeBlockandgetSequenceForUnitDeprecated, are commented out under Port the courseware container and redirects to frontend-base #2195's URL until the courseware container ports them.useCourseStartAlertandCourseStartAlert.jsx.useCourseStartMasqueradeBannerandCourseStartMasqueradeBanner.jsxcome with them and have no caller until the instructor toolbar ports (Wire up the frontend-base masquerade bar #2194).CourseStartAlert.jsxdrops the?? {}after its metadata read: without metadata it throws either way, so the default only moved the throw (decision log entry 9).EffortEstimatedrops itsdefaultProps. React warns about them on a function component. The one default was anullclass name, whichclassNamesskips the same way it skips an absent one.FormattedDatevalue gains parentheses, and the effort estimate'sactivitiesmessage gains adescription; its id and default message are untouched.js-cookieis declared at^3.0.8, the versionmasterinstalls. The lock gains that one package entry.defaultPropswarnings gains four names.AlertModal,ModalDialogBody,ModalDialogFooterandModalDialogTitleare function components declared in Paragon'ssrc/Modal/, each settingdefaultPropsthere, so they join the pattern under Support for defaultProps will be removed from function components in a future major release. paragon#3043. The pattern for react-bootstrap's components (Deprecation warnings from react-bootstrap 1.x components that Paragon wraps paragon#4523) is untouched.Testing
In
frontend-base/: lint, the tests,buildandbuild:cipass. 39 suites, 433 tests passed and 7 skipped (cases kept asit.skipunder the issues that port what they render). Lint ran with the package's.jsxfiles included (openedx/frontend-base#327).New tests.
masterhas no test file for any of these modules; it covers them through the outline and progress tab suites. Each gets one here, since no route in this layer renders them:EffortEstimate.test.tsx: the time in whole minutes, abbreviated on screen and spelled out for screen readers; the activity count; both together; nothing for a block with neither; the class name it is given.course-start-alert/hooks.test.tsx: the alert's full sentence for a course more than a day away and less than a day away, in the learner's time zone and without one, and nothing for a learner who is not enrolled or a course that has started; the masquerade banner on the progress tab, with today's date when the course metadata is gone from the cache, and nothing on another tab or without masquerading.AccountActivationAlert.test.tsx: the alert opens when the cookie is set and removes it; stays closed without it; removes it on the domain the app config names; closes on the continue button and stays open on Escape; resends the activation email, with a spinner until the request settles and a check after. The cases set the cookie on the document and letjs-cookieread and remove it, wheremaster's outline suite replaces the library's functions with mocks.Coverage. The package is at 100% of lines at this layer, against its 96.15% bar, and every file this layer adds is at 100% of lines. Codecov's first report on this PR showed two partially covered lines, the
?? {}after the metadata read inCourseStartAlert.jsxandCourseStartMasqueradeBanner.jsx; the first is dropped and the second has a case now (decision log entry 9).Manual testing. None: no route renders these modules yet. The outline tab layer carries the manual pass.
Decisions
What was decided while building this layer; the scope and the import and config mapping are in #2191.
Full decision log
Decisions: the modules the outline tab shares (#2251)
Decisions made while building this layer of #2191. The scope and the
import and config mapping are in #2191's plan and are not repeated.
The outline tab ports as two layers; this is the bottom one.
The effort estimate, the course start alert, the account activation
alert with its request, and the
js-cookiedependency, in 13 sourceand test files. Accepted cost: nothing here renders on a route, so
there is no manual pass, and each module gets a test
masterdoesnot have, since this layer's CI meets the line threshold alone.
courseware/data/index.jsports with one of its three names.AccountActivationAlert.jsximportssendActivationEmailfrom thedirectory, so the index ports and
api.jsgains the function. Theother two names it re-exports on
master,getResumeBlockandgetSequenceForUnitDeprecated, are commented out under Port the courseware container and redirects to frontend-base #2195's URL,as the factory indexes carry their unported imports.
The cookie domain is read from the app config.
masterreadsprocess.env.SESSION_COOKIE_DOMAINwhen it removes theshow-account-activation-popupcookie; here it isgetAppConfig(appId).SESSION_COOKIE_DOMAIN, with no bundled default,so an operator who sets nothing gets a cookie removed on the serving
host, as
masterdoes with the variable unset. The site name in thecontinue button is
getSiteConfig().siteName.EffortEstimateloses itsdefaultProps. React warns about themon a function component and the suite fails on console output. The
one default was
className: null, whichclassNamesskips the sameway it skips an absent one, so no default parameter takes its place.
Lint.
CourseStartMasqueradeBanner.jsx's multi-lineFormattedDatevalue gains parentheses (the autofixer's change).shared/effort-estimate/messages.ts'sactivitiesmessage gains thedescriptionthe package's lint requires; its id and defaultmessage are untouched.
Paragon's own modal
defaultPropswarnings are silenced by exactpattern. The account activation alert mounts
AlertModal, whoseparts (
AlertModal,ModalDialogBody,ModalDialogFooter,ModalDialogTitle) setdefaultPropson function components. Theirnames join the setup file's pattern under Support for defaultProps will be removed from function components in a future major release. paragon#3043, the
issue for
defaultPropson Paragon's own components.The account activation test uses the document's cookie, not a
mock of
js-cookie.mastercovers the alert through the outlinesuite, which replaces
Cookies.getandCookies.removewith mockfunctions. Here the cases set the cookie on jsdom's document and let
the library read and remove it.
SESSION_COOKIE_DOMAINto a domain that isnot the test page's. jsdom refuses that write, so the cookie
remains and the alert stays closed, which is the guard
masterwrote against re-rendering forever; the case asserts the string
written to
document.cookiecarries the configured domain.mergeAppConfigcannot remove a key (it merges, and a merge skipsan undefined value), so the cases restore the key to
null;js-cookieleaves a null attribute out as it does an unset one.onClose, which does nothing onmasterand here.The course start alert's cases compute dates from the current
time. The alert's text depends on the distance to the start date,
so each case sets a start relative to now (7 days and an hour, 2
hours and a minute) and gives the metadata
userTimezone: 'UTC', sothe expected date string does not depend on the machine's time zone.
No test in the package pins the clock, and none does here.
Of the two
?? {}after the metadata read, one is dropped andone is tested. Both run only if the component renders with no
course metadata in the cache, and the first push of this layer left
both branches untaken, which codecov showed as two partially covered
lines. Each was rendered alone without metadata to see what its
default does.
CourseStartAlert.jsxthrows either way: with the default thestart date is undefined, the distance is
NaN, andFormattedRelativeTimeraises React's "Too many re-renders";without it the destructure throws. The default only moved the
throw, so it is dropped, as refactor: port the dates tab to frontend-base #2234 did in
TimelineandUpgradeToCompleteAlertand refactor: port the modules the progress tab shares to frontend-base #2246 inGetCourseExitNavigation.CourseStartMasqueradeBanner.jsxrenders the banner with today'sdate as the start date, since
FormattedDateformats the currenttime for an undefined value. The default changes the outcome, so
it stays, and a case renders the banner without metadata and
asserts that text. The case records what
master's default does;the date it shows is not the course's.
js-cookieis declared at^3.0.8,master's3.0.8with acaret, as the dates tab layer declared its dependencies. The lock
gains the one package entry.
Checks at the layer's commit (2026-11-12).
npm run lintclean, with the package's
.jsxfiles included(
openedx lintdoes not lint.jsxfiles frontend-base#327).npm test: 39 suites, 433 passed, 7 skipped; lines 100,statements 99.64, branches 97.65, functions 98.15 for the package.
Each file this layer adds is at 100 lines, and
alerts/course-start-alert/at 100 branches.npm run buildandnpm run build:cipass;dist/holds the new modules.🤖 Generated with Claude Code