Skip to content

Commit

Permalink
chore: Minor adjustments on unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Oct 19, 2023
1 parent 554a6fd commit 9dc1a99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/course-home/courseware-search/CoursewareSearch.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,11 @@ describe('CoursewareSearch', () => {
});

it('Should have a "--modal-top-position" CSS variable matching the CourseTabsNavigation top position', () => {
renderComponent();

const section = screen.getByTestId('courseware-search-section');
expect(section.style.getPropertyValue('--modal-top-position')).toBe(`${tabsTopPosition}px`);
});

it('Should dispatch setShowSearch(true) when clicking the close button', () => {
renderComponent();
const button = screen.getByTestId('courseware-search-close-button');
fireEvent.click(button);

Expand Down
16 changes: 8 additions & 8 deletions src/course-home/courseware-search/hooks.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe('CoursewareSearch Hooks', () => {
return hook;
};

test('should return true if feature is enabled', async () => {
it('should return true if feature is enabled', async () => {
const hook = await renderTestHook();
await hook.waitFor(() => expect(fetchCoursewareSearchSettings).toBeCalledTimes(1));
expect(hook.result.current).toBe(true);
});

test('should return false if feature is disabled', async () => {
it('should return false if feature is disabled', async () => {
const hook = await renderTestHook(false);
await hook.waitFor(() => expect(fetchCoursewareSearchSettings).toBeCalledTimes(1));
expect(hook.result.current).toBe(false);
Expand All @@ -56,13 +56,13 @@ describe('CoursewareSearch Hooks', () => {
return hook;
};

test('should return show: true if feature is enabled and showSearch is true', async () => {
it('should return show: true if feature is enabled and showSearch is true', async () => {
const hook = await renderTestHook({ enabled: true, showSearch: true });

expect(hook.result.current).toEqual({ show: true });
});

test('should return show: false in any other case', async () => {
it('should return show: false in any other case', async () => {
let hook;

hook = await renderTestHook({ enabled: true, showSearch: false });
Expand Down Expand Up @@ -103,30 +103,30 @@ describe('CoursewareSearch Hooks', () => {
describe('when element is present', () => {
const mockedInfo = { top: 128 };

test('should bind resize and scroll events on mount', async () => {
it('should bind resize and scroll events on mount', async () => {
await renderTestHook({ elementId: 'test', mockedInfo });

expect(addEventListenerSpy).toHaveBeenCalledWith('resize', expect.anything());
expect(addEventListenerSpy).toHaveBeenCalledWith('scroll', expect.anything());
});

test('should unbindbind resize and scroll events when unmounted', async () => {
it('should unbindbind resize and scroll events when unmounted', async () => {
const hook = await renderTestHook({ elementId: 'test', mockedInfo });
hook.unmount();

expect(removeEventListenerSpy).toHaveBeenCalledWith('resize', expect.anything());
expect(removeEventListenerSpy).toHaveBeenCalledWith('scroll', expect.anything());
});

test('should return the element bounding box', async () => {
it('should return the element bounding box', async () => {
const hook = await renderTestHook({ elementId: 'test', mockedInfo });

hook.waitFor(() => expect(getBoundingClientRectSpy).toHaveBeenCalled());

expect(hook.result.current).toEqual(mockedInfo);
});

test('should call getBoundingClientRect on window resize', async () => {
it('should call getBoundingClientRect on window resize', async () => {
const hook = await renderTestHook({ elementId: 'test', mockedInfo });

act(() => {
Expand Down

0 comments on commit 9dc1a99

Please sign in to comment.