-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd64d32
commit 5fb172d
Showing
11 changed files
with
9,323 additions
and
11,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/courseware/course/sequence/Unit/translation-selection/TranslationModal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { shallow } from '@edx/react-unit-test-utils'; | ||
|
||
import TranslationModal from './TranslationModal'; | ||
|
||
jest.mock('./useTranslationSelection', () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
selectedIndex: 0, | ||
setSelectedIndex: jest.fn(), | ||
onSubmit: jest.fn().mockName('onSubmit'), | ||
}), | ||
languages: [['en', 'English'], ['es', 'Spanish']], | ||
})); | ||
jest.mock('@edx/paragon', () => jest.requireActual('@edx/react-unit-test-utils').mockComponents({ | ||
StandardModal: 'StandardModal', | ||
ActionRow: { | ||
Spacer: 'Spacer', | ||
}, | ||
Button: 'Button', | ||
Icon: 'Icon', | ||
ListBox: 'ListBox', | ||
ListBoxOption: 'ListBoxOption', | ||
})); | ||
jest.mock('@edx/paragon/icons', () => ({ | ||
Check: jest.fn().mockName('icons.Check'), | ||
})); | ||
jest.mock('@edx/frontend-platform/i18n', () => { | ||
const i18n = jest.requireActual('@edx/frontend-platform/i18n'); | ||
const { formatMessage } = jest.requireActual('@edx/react-unit-test-utils'); | ||
// this provide consistent for the test on different platform/timezone | ||
const formatDate = jest.fn(date => new Date(date).toISOString()).mockName('useIntl.formatDate'); | ||
return { | ||
...i18n, | ||
useIntl: jest.fn(() => ({ | ||
formatMessage, | ||
formatDate, | ||
})), | ||
defineMessages: m => m, | ||
FormattedMessage: () => 'FormattedMessage', | ||
}; | ||
}); | ||
|
||
describe('TranslationModal', () => { | ||
const props = { | ||
courseId: 'course-v1:edX+DemoX+Demo_Course', | ||
isOpen: true, | ||
close: jest.fn().mockName('close'), | ||
}; | ||
it('renders correctly', () => { | ||
const wrapper = shallow(<TranslationModal {...props} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...e/course/sequence/Unit/translation-selection/__snapshots__/TranslationModal.test.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`TranslationModal renders correctly 1`] = ` | ||
<StandardModal | ||
footerNode={ | ||
<ActionRow> | ||
<Spacer /> | ||
<Button | ||
onClick={[MockFunction close]} | ||
variant="tertiary" | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={[MockFunction onSubmit]} | ||
> | ||
Submit | ||
</Button> | ||
</ActionRow> | ||
} | ||
isOpen={true} | ||
onClose={[MockFunction close]} | ||
title="Translate this course" | ||
> | ||
<ListBox | ||
className="listbox-container" | ||
> | ||
<ListBoxOption | ||
className="d-flex justify-content-between" | ||
key="en" | ||
onSelect={[Function]} | ||
selectedOptionIndex={0} | ||
> | ||
English | ||
<Icon | ||
src={[MockFunction icons.Check]} | ||
/> | ||
</ListBoxOption> | ||
<ListBoxOption | ||
className="d-flex justify-content-between" | ||
key="es" | ||
onSelect={[Function]} | ||
selectedOptionIndex={0} | ||
> | ||
Spanish | ||
</ListBoxOption> | ||
</ListBox> | ||
</StandardModal> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/courseware/course/sequence/Unit/translation-selection/useTranslationSelection.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { mockUseKeyedState } from '@edx/react-unit-test-utils'; | ||
import { | ||
getLocalStorage, | ||
setLocalStorage, | ||
} from '../../../../../data/localStorage'; | ||
|
||
import useTranslationSelection, { stateKeys, languages } from './useTranslationSelection'; | ||
|
||
import { languageMessages } from './messages'; | ||
|
||
const state = mockUseKeyedState(stateKeys); | ||
|
||
jest.mock('react', () => ({ | ||
...jest.requireActual('react'), | ||
useCallback: jest.fn((cb, prereqs) => ({ useCallback: { cb, prereqs } })), | ||
})); | ||
jest.mock('../../../../../data/localStorage', () => ({ | ||
getLocalStorage: jest.fn(), | ||
setLocalStorage: jest.fn(), | ||
})); | ||
|
||
describe('useTranslationSelection', () => { | ||
const props = { courseId: 'some-course-id', close: jest.fn() }; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
state.mock(); | ||
}); | ||
afterEach(() => { | ||
state.resetVals(); | ||
}); | ||
|
||
languages.forEach(([key, value], index) => { | ||
it(`initializes selectedIndex to the index of the selected language (${value})`, () => { | ||
getLocalStorage.mockReturnValueOnce({ [props.courseId]: key }); | ||
const { selectedIndex } = useTranslationSelection(props); | ||
|
||
state.expectInitializedWith(stateKeys.selectedIndex, index); | ||
expect(selectedIndex).toBe(index); | ||
}); | ||
}); | ||
|
||
test('onSubmit behavior', () => { | ||
const { onSubmit } = useTranslationSelection(props); | ||
|
||
onSubmit.useCallback.cb(); | ||
expect(setLocalStorage).toHaveBeenCalled(); | ||
expect(props.close).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('language messages', () => { | ||
it('has a message defined for each language', () => { | ||
languages.forEach(([, value]) => { | ||
expect(languageMessages[value].defaultMessage).toBeDefined(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.