Skip to content

Commit d23f8a2

Browse files
fix: some refactor
1 parent 217a46c commit d23f8a2

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/courseware/course/sidebar/common/Sidebar.test.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Factory } from 'rosie';
2+
import userEvent from '@testing-library/user-event';
3+
import { createRef } from 'react';
24

35
import {
46
initializeTestStore,
@@ -7,8 +9,6 @@ import {
79
fireEvent,
810
waitFor,
911
} from '@src/setupTest';
10-
import userEvent from '@testing-library/user-event';
11-
import { createRef } from 'react';
1212
import messages from '@src/courseware/course/messages';
1313
import SidebarContext from '../SidebarContext';
1414
import SidebarBase from './SidebarBase';
@@ -31,16 +31,17 @@ describe('SidebarBase', () => {
3131
let mockHandleKeyDown;
3232
let mockHandleBackBtnKeyDown;
3333

34+
const defaultComponentProps = {
35+
title: 'Test Sidebar Title',
36+
ariaLabel: 'Test Sidebar Aria Label',
37+
sidebarId: SIDEBAR_ID,
38+
className: 'test-class',
39+
children: <div>Sidebar Content</div>,
40+
};
41+
3442
const renderSidebar = (contextProps = {}, componentProps = {}) => {
3543
const fullContextValue = { ...mockContextValue, ...contextProps };
36-
const defaultProps = {
37-
title: 'Test Sidebar Title',
38-
ariaLabel: 'Test Sidebar Aria Label',
39-
sidebarId: SIDEBAR_ID,
40-
className: 'test-class',
41-
children: <div>Sidebar Content</div>,
42-
...componentProps,
43-
};
44+
const defaultProps = { ...defaultComponentProps, ...componentProps };
4445
return render(
4546
<SidebarContext.Provider value={fullContextValue}>
4647
<SidebarBase {...defaultProps} />
@@ -84,7 +85,7 @@ describe('SidebarBase', () => {
8485
it('should render children, title, and close button when visible', () => {
8586
renderSidebar({ currentSidebar: SIDEBAR_ID });
8687
expect(screen.getByText('Sidebar Content')).toBeInTheDocument();
87-
expect(screen.getByText('Test Sidebar Title')).toBeInTheDocument();
88+
expect(screen.getByText(defaultComponentProps.title)).toBeInTheDocument();
8889
expect(screen.getByRole('button', { name: messages.closeNotificationTrigger.defaultMessage })).toBeInTheDocument();
8990
expect(screen.getByTestId(`sidebar-${SIDEBAR_ID}`)).toBeInTheDocument();
9091
expect(screen.getByTestId(`sidebar-${SIDEBAR_ID}`)).not.toHaveClass('d-none');
@@ -99,7 +100,7 @@ describe('SidebarBase', () => {
99100

100101
it('should hide title bar when showTitleBar prop is false', () => {
101102
renderSidebar({ currentSidebar: SIDEBAR_ID }, { showTitleBar: false });
102-
expect(screen.queryByText('Test Sidebar Title')).not.toBeInTheDocument();
103+
expect(screen.queryByText(defaultComponentProps.title)).not.toBeInTheDocument();
103104
expect(screen.queryByRole('button', { name: messages.closeNotificationTrigger.defaultMessage })).not.toBeInTheDocument();
104105
expect(screen.getByText('Sidebar Content')).toBeInTheDocument();
105106
});

src/courseware/course/sidebar/sidebars/notifications/NotificationTray.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { breakpoints } from '@openedx/paragon';
55

66
import MockAdapter from 'axios-mock-adapter';
77
import { Factory } from 'rosie';
8+
89
import messages from '@src/courseware/course/messages';
910
import {
1011
fireEvent, initializeMockApp, render, screen, waitFor,

0 commit comments

Comments
 (0)