Skip to content

Commit

Permalink
fix: test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Syed-Ali-Abbas-Zaidi committed Jul 14, 2023
1 parent ff415bd commit fde01e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/catalog-search/src/tests/FacetListBase.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SearchData from '../SearchContext';
const mockedNavigator = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useLocation: jest.fn(),
useNavigate: () => mockedNavigator,
}));
Expand Down
16 changes: 3 additions & 13 deletions packages/catalog-search/src/tests/SearchSuggestionItem.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import SearchSuggestionItem from '../SearchSuggestionItem';

const mockedNavigator = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedNavigator,
useLocation: () => ({
pathname: '/',
}),
}));

describe('<SeachSuggestionItem />', () => {
test('renders course data', () => {
const mockData = {
Expand Down Expand Up @@ -71,7 +61,7 @@ describe('<SeachSuggestionItem />', () => {
expect(screen.getByText('Professional Program')).not.toBeNull();
});

test('redirects on click if disableSuggestionRedirect is false', () => {
test.only('redirects on click if disableSuggestionRedirect is false', () => {
const mockData = {
program: {
url: '/test-enterprise/program/456',
Expand All @@ -87,14 +77,14 @@ describe('<SeachSuggestionItem />', () => {
},
};

const { container, history } = renderWithRouter(<SearchSuggestionItem
const { container } = renderWithRouter(<SearchSuggestionItem
url={mockData.program.url}
suggestionItemHandler={mockData.program.suggestionItemHandler}
hit={mockData.program.hit}
disableSuggestionRedirect={mockData.program.disableSuggestionRedirect}
/>);
userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
expect(history.location.pathname).toBe(mockData.program.url);
expect(window.location.pathname).toBe(mockData.program.url);
});

test('fires callback on click if disableSuggestionRedirect is true', () => {
Expand Down
22 changes: 13 additions & 9 deletions packages/catalog-search/src/tests/SearchSuggestions.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { renderWithRouter } from '@edx/frontend-enterprise-utils';
import React from 'react';
import { screen } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { BrowserRouter } from 'react-router-dom';
import SearchSuggestions from '../SearchSuggestions';
import { COURSE_TYPE_EXECUTIVE_EDUCATION } from '../data/constants';

Expand Down Expand Up @@ -100,16 +101,19 @@ describe('<SeachSuggestions />', () => {
});

test.only('redirects to correct page on course click', () => {
const { container } = renderWithRouter(
<SearchSuggestions
enterpriseSlug="test-enterprise"
autoCompleteHits={fakeSuggestionsData.hits}
handleSubmit={handleSubmit}
/>,
const { container } = render(
<BrowserRouter location={{ pathname: '/' }}>
<SearchSuggestions
enterpriseSlug="test-enterprise"
autoCompleteHits={fakeSuggestionsData.hits}
handleSubmit={handleSubmit}
/>
</BrowserRouter>,
);

userEvent.click(container.getElementsByClassName('suggestion-item')[0]);
expect(true).toBe(true);
// expect(window.location.pathname).toBe('/test-enterprise/course/edX+courseX');
expect(container.getElementsByClassName('suggestion-item')[0].href).toContain('/test-enterprise/course/edX+courseX');
expect(window.location.pathname).toBe('/test-enterprise/course/edX+courseX');
});

test('redirects to correct page on program click', () => {
Expand Down

0 comments on commit fde01e2

Please sign in to comment.