Skip to content

fix: tests fixed after design tokens support change#1

Merged
arbrandes merged 7 commits intoarbrandes:frontend-base-design-tokensfrom
WGU-Open-edX:frontend-base-tests-fix
Jan 27, 2026
Merged

fix: tests fixed after design tokens support change#1
arbrandes merged 7 commits intoarbrandes:frontend-base-design-tokensfrom
WGU-Open-edX:frontend-base-tests-fix

Conversation

@jesusbalderramawgu
Copy link

Description

this is a PR to fix the tests after the changes in this PR

now the tests are passing successfully.

Screenshot 2026-01-16 at 11 09 13 a m

});
});
describe('useInitializeDashboard', () => {
it('dispatches initialize thunk action on component load', () => {
Copy link
Author

Choose a reason for hiding this comment

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

this was deleted because in the Dashboard/hooks.js file the useInitializeDashboard() function was deleted in a previous commit. Is that correct or should I bring that back?
Screenshot 2026-01-16 at 11 14 30 a m

@@ -1,6 +1,6 @@
import React from 'react';

Choose a reason for hiding this comment

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

Suggested Change, add here useContext:

Suggested change
import React from 'react';
import React, { useContext } from 'react';

Choose a reason for hiding this comment

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

if React import is not needed then remove it pls

const actionButton = screen.getByRole('link', { name: messages.viewCredit.defaultMessage });
expect(actionButton).toHaveAttribute('aria-disabled', 'true');
expect(actionButton).toHaveClass('disabled');
// Paragon is not injecting this arribute that's why for now is commented, not it add this classes as well instead of class disabled

Choose a reason for hiding this comment

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

but is disabling the button or not? 👀

Copy link
Author

Choose a reason for hiding this comment

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

well, I couldn't see that attribute, I just saw that it returns those classes instead of the disabled class.
is there anything that I'm missing and that's why I don't see the attribute.
Not sure if is because of the new paragon version

Choose a reason for hiding this comment

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

it should have the attribute disabled, if not, then the button is not on that state, so your component is not getting that prop/attribute, you need to check how to mock the needed value to get that, btn btn-outline-primary these ones are not related to that state they are related to the variant and border-gray-400 is added directly to the component

Copy link
Author

Choose a reason for hiding this comment

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

thank you so much Diana for your comment, I was able to find the issue, now I'm mocking correctly and I got the correct attribute and class. Pr has been updated

@@ -1,6 +1,6 @@
import React from 'react';

Choose a reason for hiding this comment

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

Suggested change
import React from 'react';
import React, { useContext } from 'react';

@@ -1,6 +1,6 @@
import React from 'react';

Choose a reason for hiding this comment

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

Suggested change
import React from 'react';
import React, { useContext } from 'react';

import { IntlProvider } from '@edx/frontend-platform/i18n';
import { IntlProvider } from '@openedx/frontend-base';

import { reduxHooks } from '../../../../../hooks';

Choose a reason for hiding this comment

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

why changing this one? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

it wasn't necessary to have the path in that way, that's why I simplified

import { IntlProvider } from '@openedx/frontend-base';
import { render, screen } from '@testing-library/react';

import { fireEvent, render, screen } from '@testing-library/react';

Choose a reason for hiding this comment

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

why you are importing fireEvent if you are not using it? 🤔

Copy link
Author

Choose a reason for hiding this comment

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

sorry, my mistake I was checking something and I forgot to remove it.
but I've updated the PR removing this


const state = new MockUseState(hooks);
const numPrograms = 27;
let numPrograms = 3;

Choose a reason for hiding this comment

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

i know this new number makes the test to pass, but why the huge difference?

Copy link
Author

Choose a reason for hiding this comment

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

it wasn't un purpose I got the original value back

const unenrollOption = screen.getByRole('button', { name: messages.unenroll.defaultMessage });
expect(unenrollOption).toBeInTheDocument();
expect(unenrollOption).toHaveAttribute('aria-disabled', 'true');
// the component is not returning the attribute aria disabled

Choose a reason for hiding this comment

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

this still true or need to change the mock here too?

Copy link
Owner

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

The tests themselves pass, which is great sign: thanks! There are a few problems, though:

  • Linting errors need to be addressed (npm run lint)
  • A few small changes requested
  • I'd like the hooks/api tests to be refactored: the masquerade stuff seems overly complicated and potentially buggy

Thanks for taking this on!

Comment on lines 15 to 18
if (typeof window !== 'undefined') {
window.console?.error({ target, name });
window.console?.error(`invalid property "${name}"`);
}
Copy link
Owner

Choose a reason for hiding this comment

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

We should not be adding console logging upstream. It's good for debugging during development, but should not be committed.

Copy link
Author

Choose a reason for hiding this comment

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

this was fixed

});
});
});

No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

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

Please remove the extraneous whitespace.

Copy link
Author

Choose a reason for hiding this comment

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

this was fixed

src/hooks/api.js Outdated
Comment on lines 125 to 144
export const useClearMasquerade = () => {
const clearRequest = reduxHooks.useClearRequest();
const initializeApp = module.useInitializeApp();
return () => {
clearRequest(RequestKeys.masquerade);
initializeApp();
};
};

export const useMasqueradeAs = (cardId) => {
reduxHooks.useCardEntitlementData(cardId);
const onSuccess = ({ data }) => {
reduxHooks.useLoadData()(data);
};

return module.useNetworkRequest(
(user) => api.initializeList({ user }),
{ onSuccess, requestKey: RequestKeys.masquerade },
);
};
Copy link
Owner

@arbrandes arbrandes Jan 21, 2026

Choose a reason for hiding this comment

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

Both of these functions are only used by tests. They should be moved to the test file, for starters.

But that's not all. They feel overly complicated, and I suspect there are bugs hidden in them. There must be a simpler way to test these hooks, no?

Copy link
Author

@jesusbalderramawgu jesusbalderramawgu Jan 21, 2026

Choose a reason for hiding this comment

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

I took a look into this and in fact those functions were removed in a previous commit.
for example this function
useClearMasquerade was used in ‎src/containers/MasqueradeBar/hooks.js
but that doesn't exist anymore in our current branch, that component changed, now it is here
src/widgets/LearnerDashboardHeader/MasqueradeBar/hooks.js but is not the same, is not using the useClearMasquerade function anymore, nothing uses that. I couldn't find a reference in our current branch code.
So I removed the tests for this cases because are not in use anymore.

please let me know if you agree with this or if is something that I'm missing.
thanks for your feedback!

@jesusbalderramawgu
Copy link
Author

The tests themselves pass, which is great sign: thanks! There are a few problems, though:

  • Linting errors need to be addressed (npm run lint)
  • A few small changes requested
  • I'd like the hooks/api tests to be refactored: the masquerade stuff seems overly complicated and potentially buggy

Thanks for taking this on!

Thank you so much for your feedback, ah yeah I forgot to run the lint in my local.
I will take a look into this.

@jesusbalderramawgu
Copy link
Author

The tests themselves pass, which is great sign: thanks! There are a few problems, though:

  • Linting errors need to be addressed (npm run lint)
  • A few small changes requested
  • I'd like the hooks/api tests to be refactored: the masquerade stuff seems overly complicated and potentially buggy

Thanks for taking this on!

I made the changes, linting errors were fixed

Copy link
Owner

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my previous comments. Since all tests are now passing, I took a closer look and found a few more things to change:

  • The masquerade code was removed from the Redux state on purpose: it shouldn't be restored. The corresponding tests should be removed instead.
  • The multiple aliases workaround should be removed, and the '@src' prefix used instead (as introduced by Jacobo in frontend-base@alpha.9).

I apologize for the last one, as it means a potentially large refactor. But it's for a good cause.

import { StrictDict } from '../../utils';

export const routePath = `${getSiteConfig().publicPath}:courseId`;
export const routePath = `${getSiteConfig().PUBLIC_PATH}:courseId`;
Copy link
Owner

Choose a reason for hiding this comment

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

getSiteConfig() does not support PUBLIC_PATH anymore, but publicPath is also wrong. It should be basename: https://github.com/openedx/frontend-base/blob/main/types.ts#L58 as of openedx/frontend-base@f9600ee84.

That said, this constant is not used anywhere. I think we can get rid of id.

import { keyStore } from 'utils';
import { baseAppUrl } from 'data/services/lms/urls';
import { EXECUTIVE_EDUCATION_COURSE_MODES } from 'data/constants/course';
import { EXECUTIVE_EDUCATION_COURSE_MODES } from '../../../../data/constants/course';
Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't we also have to use relative imports for the two lines above?

Copy link
Owner

Choose a reason for hiding this comment

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

I just ran across the aliases you added. We should be able to use the @src prefix now, as I commented below.

jest.config.js Outdated
Comment on lines 20 to 35
// App aliases
'^hooks$': '<rootDir>/src/hooks',
'^testUtils$': '<rootDir>/src/testUtils.js',
'^data/constants/app$': '<rootDir>/src/data/constants/app.js',
'^data/constants/requests$': '<rootDir>/src/data/constants/requests.js',
'^data/services/lms/api$': '<rootDir>/src/data/services/lms/api.js',
'^data/services/lms/utils$': '<rootDir>/src/data/services/lms/utils.js',
'^data/services/lms/urls$': '<rootDir>/src/data/services/lms/urls.js',
'^data/redux/hooks$': '<rootDir>/src/data/redux/hooks/index.js',
'^data/redux/app/reducer$': '<rootDir>/src/data/redux/app/reducer.js',
'^data/redux$': '<rootDir>/src/data/redux/index.js',
'^utils$': '<rootDir>/src/utils/index.js',
'^utils/hooks$': '<rootDir>/src/utils/hooks.js',
'^components/(.*)$': '<rootDir>/src/components/$1',
'^containers/(.*)$': '<rootDir>/src/containers/$1',
'^tracking$': '<rootDir>/src/tracking/index.js',
Copy link
Owner

Choose a reason for hiding this comment

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

I know using relative imports is painful, but an alias per import isn't the best way to solve it. I just published frontend-base@alpha.9 with should allow you to use a '@src' prefix in the imports.

Comment on lines 19 to 28
export const masquerade = (state) => {
const request = state.requests[RequestKeys.masquerade] || {};
return {
isMasquerading: request.status === RequestStates.completed,
isMasqueradingFailed: request.status === RequestStates.failed,
isMasqueradingPending: request.status === RequestStates.pending,
masqueradeErrorStatus: request.error?.response?.status,
};
};

Copy link
Owner

Choose a reason for hiding this comment

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

I think I remember, now (it's been a while). I believe I moved the masquerade stuff out of Redux into a React context so that it could be moved up into the header. There's no need to restore the masquerade stuff in Redux so the tests work: for now you can just remove the corresponding tests.

enrollEntitlementSession: 'enrollEntitlementSession',
leaveEntitlementSession: 'leaveEntitlementSession',
recommendedCourses: 'recommendedCourses',
masquerade: 'masquerade',
Copy link
Owner

Choose a reason for hiding this comment

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

No need to restore this - the corresponding test should be removed, instead. See my other comment about masquerade.

@jesusbalderramawgu
Copy link
Author

Thanks for addressing my previous comments. Since all tests are now passing, I took a closer look and found a few more things to change:

  • The masquerade code was removed from the Redux state on purpose: it shouldn't be restored. The corresponding tests should be removed instead.
  • The multiple aliases workaround should be removed, and the '@src' prefix used instead (as introduced by Jacobo in frontend-base@alpha.9).

I apologize for the last one, as it means a potentially large refactor. But it's for a good cause.

Thanks Adolfo, I will work on the prefixes

@jesusbalderramawgu
Copy link
Author

Thanks for addressing my previous comments. Since all tests are now passing, I took a closer look and found a few more things to change:

  • The masquerade code was removed from the Redux state on purpose: it shouldn't be restored. The corresponding tests should be removed instead.
  • The multiple aliases workaround should be removed, and the '@src' prefix used instead (as introduced by Jacobo in frontend-base@alpha.9).

I apologize for the last one, as it means a potentially large refactor. But it's for a good cause.

I have updated the frontend-base into frontend-base@alpha.11 and changed the prefixes, also I addressed the other comments. Thanks for your feedback, anything please let me now

Copy link
Owner

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Good work, it seems like we're almost there. I asked for a few minor changes, but in addition, can you also please remove the npm run build lines from the CI workflow so that tests pass? (We don't have a way to build-test until we figure out a solution for openedx/frontend-base#124).

@jesusbalderramawgu
Copy link
Author

Good work, it seems like we're almost there. I asked for a few minor changes, but in addition, can you also please remove the npm run build lines from the CI workflow so that tests pass? (We don't have a way to build-test until we figure out a solution for openedx/frontend-base#124).

Thank you so much, for your feedback. I've updated the PR with your latest comments.
anything please let me know

@codecov-commenter
Copy link

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Owner

@arbrandes arbrandes left a comment

Choose a reason for hiding this comment

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

Excellent! Approved! Thanks for bearing with me. 👍🏼

@arbrandes arbrandes merged commit 57a5c40 into arbrandes:frontend-base-design-tokens Jan 27, 2026
3 checks passed
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.

[frontend-base] Fix tests

4 participants