Skip to content

Commit 7f1e509

Browse files
test: Deprecate react-unit-test-utils 12/15 (#671)
1 parent 31c5445 commit 7f1e509

File tree

4 files changed

+84
-205
lines changed

4 files changed

+84
-205
lines changed

src/containers/CourseCard/components/CourseCardMenu/__snapshots__/index.test.jsx.snap

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/containers/CourseCard/components/CourseCardMenu/hooks.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { useKeyedState } from '@edx/react-unit-test-utils';
2-
31
import track from 'tracking';
42
import { reduxHooks } from 'hooks';
3+
import { useState } from 'react';
4+
import { StrictDict } from 'utils';
55

6-
export const stateKeys = {
7-
isUnenrollConfirmVisible: 'isUnenrollConfirmVisible',
8-
isEmailSettingsVisible: 'isEmailSettingsVisible',
9-
};
6+
export const state = StrictDict({
7+
isUnenrollConfirmVisible: (val) => useState(val), // eslint-disable-line
8+
isEmailSettingsVisible: (val) => useState(val), // eslint-disable-line
9+
});
1010

1111
export const useUnenrollData = () => {
12-
const [isVisible, setIsVisible] = useKeyedState(stateKeys.isUnenrollConfirmVisible, false);
12+
const [isVisible, setIsVisible] = state.isUnenrollConfirmVisible(false);
1313
return {
1414
show: () => setIsVisible(true),
1515
hide: () => setIsVisible(false),
@@ -18,7 +18,7 @@ export const useUnenrollData = () => {
1818
};
1919

2020
export const useEmailSettings = () => {
21-
const [isVisible, setIsVisible] = useKeyedState(stateKeys.isEmailSettingsVisible, false);
21+
const [isVisible, setIsVisible] = state.isEmailSettingsVisible(false);
2222
return {
2323
show: () => setIsVisible(true),
2424
hide: () => setIsVisible(false),

src/containers/CourseCard/components/CourseCardMenu/hooks.test.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { mockUseKeyedState } from '@edx/react-unit-test-utils';
2-
31
import { reduxHooks } from 'hooks';
42
import track from 'tracking';
3+
import { MockUseState } from 'testUtils';
54

65
import * as hooks from './hooks';
76

@@ -19,7 +18,7 @@ reduxHooks.useTrackCourseEvent.mockReturnValue(trackCourseEvent);
1918
const cardId = 'test-card-id';
2019
let out;
2120

22-
const state = mockUseKeyedState(hooks.stateKeys);
21+
const state = new MockUseState(hooks);
2322

2423
describe('CourseCardMenu hooks', () => {
2524
beforeEach(() => {
@@ -28,7 +27,6 @@ describe('CourseCardMenu hooks', () => {
2827
});
2928
describe('useUnenrollData', () => {
3029
beforeEach(() => {
31-
state.mockVals({ isUnenrollConfirmVisible: true });
3230
out = hooks.useUnenrollData();
3331
});
3432
describe('behavior', () => {
@@ -37,9 +35,6 @@ describe('CourseCardMenu hooks', () => {
3735
});
3836
});
3937
describe('output', () => {
40-
test('state is loaded from current state value', () => {
41-
expect(out.isVisible).toEqual(true);
42-
});
4338
test('show sets state value to true', () => {
4439
out.show();
4540
expect(state.setState.isUnenrollConfirmVisible).toHaveBeenCalledWith(true);
@@ -53,7 +48,6 @@ describe('CourseCardMenu hooks', () => {
5348

5449
describe('useEmailSettings', () => {
5550
beforeEach(() => {
56-
state.mockVals({ isEmailSettingsVisible: true });
5751
out = hooks.useEmailSettings();
5852
});
5953
describe('behavior', () => {
@@ -62,9 +56,6 @@ describe('CourseCardMenu hooks', () => {
6256
});
6357
});
6458
describe('output', () => {
65-
test('state is loaded from current state value', () => {
66-
expect(out.isVisible).toEqual(state.values.isEmailSettingsVisible);
67-
});
6859
test('show sets state value to true', () => {
6960
out.show();
7061
expect(state.setState.isEmailSettingsVisible).toHaveBeenCalledWith(true);

0 commit comments

Comments
 (0)