Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add testing to useParagonTheme hooks #514

Merged

Conversation

dcoa
Copy link
Contributor

@dcoa dcoa commented Jul 16, 2023

Description:

This is a testing contribution to Theming Configuration in Runtime.

Context: #440

C.C @adamstankiewicz

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jul 16, 2023
@openedx-webhooks
Copy link

openedx-webhooks commented Jul 16, 2023

Thanks for the pull request, @dcoa! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@codecov
Copy link

codecov bot commented Jul 16, 2023

Codecov Report

Patch coverage has no change and project coverage change: +10.43 🎉

Comparison is base (efdf60c) 68.61% compared to head (8889335) 79.05%.

Additional details and impacted files
@@                    Coverage Diff                    @@
##           ags/inject-theme-css     #514       +/-   ##
=========================================================
+ Coverage                 68.61%   79.05%   +10.43%     
=========================================================
  Files                        48       48               
  Lines                      1351     1351               
  Branches                    283      283               
=========================================================
+ Hits                        927     1068      +141     
+ Misses                      360      251      -109     
+ Partials                     64       32       -32     

see 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dcoa dcoa changed the title test: add testing to useTheme hooks test: add testing to useParagonThemeCore hook Jul 16, 2023
@dcoa dcoa marked this pull request as ready for review July 16, 2023 22:42
@dcoa dcoa changed the title test: add testing to useParagonThemeCore hook test: add testing to useParagonTheme hooks Jul 17, 2023
@dcoa dcoa force-pushed the ags/inject-theme-css branch 2 times, most recently from 333318b to 34b5184 Compare July 19, 2023 06:55
Copy link
Member

@adamstankiewicz adamstankiewicz 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 the testing contribution, @dcoa! 🙌 Left some initial feedback.

Comment on lines 39 to 40
default: 'https://cdn.jsdelivr.net/npm/@edx/paragon@$paragonVersion/dist/core.min.css',
brandOverride: 'https://cdn.jsdelivr.net/npm/@edx/brand@$brandVersionVersion/dist/core.min.css',
Copy link
Member

Choose a reason for hiding this comment

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

nit: might replace $paragonVersion and $brandVersion with explicit version numbers and/or a distribution tag like alpha (e.g., https://cdn.jsdelivr.net/npm/@edx/paragon@alpha/dist/core.min.css). The URLs passed into this hook have already had their wildcard keywords replaced.

Comment on lines 15 to 16
themeOnLoad.mockClear();
logError.mockClear();
Copy link
Member

Choose a reason for hiding this comment

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

nit: could use jest.clearAllMocks()

act(() => createdLinkTag.onload());
expect(createdLinkTag.href).toBe(coreConfig.themeCore.urls.default);
expect(themeOnLoad).toHaveBeenCalledTimes(1);
expect(initialState).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

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

[clarification/curious] What is the intent of the initialState assertion? Given you assert that themeOnLoad is called once on line 30 already, do we need to assert on something that only happens in the test? Put another way, does this hook need to know what onLoad does or does it only care that onLoad is called when appropriate?

Similar questions for other uses of initialState in other tests below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, due to is a parameter and not a hook method shouldn't test its functionality (out of the scope).

Comment on lines 67 to 68
default: true,
dark: false,
Copy link
Member

Choose a reason for hiding this comment

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

This config schema has changed on the base branch, e.g.:

global.PARAGON_THEME = {
      paragon: {
        version: '1.0.0',
        themeUrls: {
          core: {
            fileName: 'core.min.css',
          },
          defaults: {
            light: 'light',
          },
          variants: {
            light: {
              fileName: 'light.min.css',
            },
          },
        },
      },
    };

act(() => { themeLinks.forEach((link) => link.onload()); });

expect(themeLinks.length).toBe(4);
expect(initialState).toBeTruthy();
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 other comment above, would recommend asserting that themeOnLoad was called, in place of the side of effect of what themeOnLoad mock is set up to do (i.e., mutate the initialState).

expect(initialState).toBeTruthy();
});

it('should dispatch a log error and fallback to PARAGON_THEME if can not load the core theme link', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Does the test name need to be updated, since we're testing the theme variant links, not the core theme link?

mockRemoveEventListener.mockClear();
});

it('should create the links tags for each theme variant and change the state to true when are loaded', () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: "when are loaded" -> "when all variants are loaded" or similar

expect(initialState).toBeFalsy();
});

it('should configure themes acording with system preference and add the change event listener', () => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo "acording" -> "according"

nit: "configure themes" -> "configure theme variants"

urls: {
default: 'https://cdn.jsdelivr.net/npm/@edx/paragon@$paragonVersion/dist/light.min.css',
brandOverride: 'https://cdn.jsdelivr.net/npm/@edx/brand@$brandVersion/dist/light.min.css',

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra blank line

urls: {
default: 'https://cdn.jsdelivr.net/npm/@edx/paragon@$paragonVersion/dist/dark.min.css',
brandOverride: 'https://cdn.jsdelivr.net/npm/@edx/brand@$brandVersion/dist/dark.min.css',

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra blank line

@adamstankiewicz
Copy link
Member

Thanks for the updates, @dcoa! Your changes LGTM; I will go ahead and merge into the base PR's branch now and see where we're at with any additional coverage required.

@adamstankiewicz adamstankiewicz merged commit e96de6b into openedx:ags/inject-theme-css Jul 21, 2023
5 checks passed
@openedx-webhooks
Copy link

@dcoa 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request Dec 30, 2023
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request Jan 3, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request Apr 4, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request May 8, 2024
chore: update package-lock.json

chore: update package-lock.json take 2

chore: remove console.log statements

fix: ignore system preference change when theme variant set in localstorage

chore: add tests for updates to AppProvider

chore: update react-intl to pass peer dependencies after pinning all deps

chore: split hooks.js up into separate files and begin some related tests

test: add testing to useParagonTheme hooks (openedx#514)

* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request May 14, 2024
chore: update package-lock.json

chore: update package-lock.json take 2

chore: remove console.log statements

fix: ignore system preference change when theme variant set in localstorage

chore: add tests for updates to AppProvider

chore: update react-intl to pass peer dependencies after pinning all deps

chore: split hooks.js up into separate files and begin some related tests

test: add testing to useParagonTheme hooks (openedx#514)

* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
dcoa added a commit to eduNEXT/frontend-platform that referenced this pull request Jun 26, 2024
chore: update package-lock.json

chore: update package-lock.json take 2

chore: remove console.log statements

fix: ignore system preference change when theme variant set in localstorage

chore: add tests for updates to AppProvider

chore: update react-intl to pass peer dependencies after pinning all deps

chore: split hooks.js up into separate files and begin some related tests

test: add testing to useParagonTheme hooks (openedx#514)

* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 9, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 9, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 9, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 9, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 22, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 22, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 22, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
ArturGaspar pushed a commit to open-craft/frontend-platform that referenced this pull request Jul 29, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
bra-i-am pushed a commit to eduNEXT/frontend-platform that referenced this pull request Aug 9, 2024
* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
bra-i-am pushed a commit to eduNEXT/frontend-platform that referenced this pull request Aug 22, 2024
chore: update package-lock.json

chore: update package-lock.json take 2

chore: remove console.log statements

fix: ignore system preference change when theme variant set in localstorage

chore: add tests for updates to AppProvider

chore: update react-intl to pass peer dependencies after pinning all deps

chore: split hooks.js up into separate files and begin some related tests

test: add testing to useParagonTheme hooks (openedx#514)

* test: add testing to useParagonThemeCore
* test: add test to useThemeVariants hook
* fix: Paragon definition and remove onload mock
* test: change test message to be clear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants