Skip to content

Commit a500e3a

Browse files
feat: refactor tests
1 parent 3ff5757 commit a500e3a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/courseware/course/sequence/sequence-navigation/UnitButton.test.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import {
55
} from '../../../../setupTest';
66
import UnitButton from './UnitButton';
77

8+
jest.mock('react-router-dom', () => {
9+
const actual = jest.requireActual('react-router-dom');
10+
return {
11+
...actual,
12+
useLocation: () => ({ pathname: '/preview/anything' }),
13+
};
14+
});
15+
816
describe('Unit Button', () => {
917
let mockData;
1018
const courseMetadata = Factory.build('courseMetadata');
@@ -31,6 +39,10 @@ describe('Unit Button', () => {
3139
};
3240
});
3341

42+
afterEach(() => {
43+
jest.resetModules();
44+
});
45+
3446
it('hides title by default', () => {
3547
render(<UnitButton {...mockData} />, { wrapWithRouter: true });
3648
expect(screen.getByRole('tab')).not.toHaveTextContent(unit.display_name);
@@ -99,4 +111,19 @@ describe('Unit Button', () => {
99111

100112
expect(screen.getByRole('tab')).toBeInTheDocument();
101113
});
114+
115+
it('prepends /preview to the unit path if in preview mode', () => {
116+
const onClick = jest.fn();
117+
118+
render(
119+
<UnitButton {...mockData} onClick={onClick} />,
120+
{
121+
wrapWithRouter: true,
122+
initialEntries: ['/preview/some/path'],
123+
},
124+
);
125+
126+
const button = screen.getByRole('tab');
127+
expect(button.closest('a')).toHaveAttribute('href', expect.stringContaining('/preview/course/'));
128+
});
102129
});

0 commit comments

Comments
 (0)