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

HeaderLogo is missing unit tests for onClick #4692

Open
AMoo-Miki opened this issue Aug 8, 2023 · 7 comments
Open

HeaderLogo is missing unit tests for onClick #4692

AMoo-Miki opened this issue Aug 8, 2023 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers OSCI Open Source Contributor Initiative test:unit

Comments

@AMoo-Miki
Copy link
Collaborator

AMoo-Miki commented Aug 8, 2023

HeaderLogo doesn't have sufficient unit tests to validate the complicated onClick.

Requirements

  • Add more unit tests around the functionality exposed onClick
@AMoo-Miki AMoo-Miki added enhancement New feature or request test:unit labels Aug 8, 2023
@kavilla kavilla added good first issue Good for newcomers OSCI Open Source Contributor Initiative labels Aug 8, 2023
@subhajit20
Copy link

@AMoo-Miki can you give some more info?

@vvavdiya
Copy link
Contributor

I'd like to take a look at this.
@AMoo-Miki can you please help with more context/details of the issue?

@AMoo-Miki
Copy link
Collaborator Author

If you look at the bottom of header_logo.test.tsx, you would notice that the test for onClick only checks the scenario where forceNavigation is false. There are two other exit paths that are untested: (1) reload and (2) no intervention which results in the URL being loaded.

@vvavdiya
Copy link
Contributor

@AMoo-Miki
I am new to testing, but I have tried to following code.

// Case 1: Reload

    it('reloads the page when reload is specified to true', () => {
      const props = {
        ...mockProps(),
        navigateToApp: jest.fn(),
        reload: true, // Set reload to true
      };
      const component = mountWithIntl(<HeaderLogo {...props} />);
      component.find('.logoContainer img').simulate('click');

      // Expect that navigateToApp is not called when reload is true
      expect(props.navigateToApp).not.toHaveBeenCalled();
      // Expect that window.location.reload is called exactly once
      expect(props.navigateToApp).toHaveBeenCalledTimes(1);
    });

// Case 2: No Intervention Resulting in URL Loading

    it('No Intervention Resulting in URL Loading-does not reload the page when reload is set to false', () => {
      const props = {
        ...mockProps(),
        navigateToApp: jest.fn(),
        reload: false, // Set reload to false
      };
      const component = mountWithIntl(<HeaderLogo {...props} />);
      component.find('.logoContainer img').simulate('click');

      expect(props.navigateToApp).not.toHaveBeenCalled();
    });

@BigSamu
Copy link
Contributor

BigSamu commented Oct 23, 2023

ou would notice that the test for onClick only checks the scenario where forceNavigation is false. There are two other exit paths that are untested: (1) reload and (2) no intervention which results in the URL being loaded.

@AMoo-Miki, for the cases you mentioned, are you expecting unit tests using the forceNavigation prop equal to true or not? If correct, I just wonder in which cases you are going to pass that sort of prop. You mentioned 1) a reload and 2) no intervention, which results in the URL being loaded. What do you mean by these 2 scenarios? 1) Click in the reload button of the browser? and 2) an update in the URL bar with the same current address (without considering URL fragments)?

Regards,

Samuel

@BigSamu
Copy link
Contributor

BigSamu commented Oct 25, 2023

@AMoo-Miki,

I want to review PR #5342 from @vvavdiya. Just want to double-check my understanding of my previous message. Would really appreciate it if you could clarify the unit tests you are expecting for this case.

Many thanks,

Samuel

@BigSamu
Copy link
Contributor

BigSamu commented Nov 28, 2023

@joshuarrrr, @AMoo-Miki

May I take this issue? Saw that the PR from @vvavdiya was sent to draft.

@vvavdiya, Do you want to work together on this?

Regards,

Samuel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers OSCI Open Source Contributor Initiative test:unit
Projects
None yet
Development

No branches or pull requests

5 participants