Skip to content

Commit

Permalink
test: fix current test
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Nov 4, 2024
1 parent 869d231 commit f8a53ad
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/editors/data/redux/thunkActions/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StrictDict, camelizeKeys } from '../../../utils';
import { isLibraryKey } from '../../../../generic/key-utils';
import * as requests from './requests';
// This 'module' self-import hack enables mocking during tests.
// See src/editors/decisions/0005-internal-editor-testability-decisions.md. The whole approach to how hooks are tested
Expand All @@ -8,7 +9,6 @@ import * as module from './app';
import { actions as appActions } from '../app';
import { actions as requestsActions } from '../requests';
import { RequestKeys } from '../../constants/requests';
import { isLibrary } from '../app/selectors';

// Similar to `import { actions } from '..';` but avoid circular imports:
const actions = {
Expand Down Expand Up @@ -103,7 +103,7 @@ export const initialize = (data) => (dispatch) => {
dispatch(module.fetchCourseDetails());
break;
case 'html':
if (isLibrary) { dispatch(actions.app.resetImages()); }
if (isLibraryKey(data.learningContextId)) { dispatch(actions.app.resetImages()); }
dispatch(module.fetchImages({ pageNumber: 0 }));
break;
default:
Expand Down
41 changes: 28 additions & 13 deletions src/editors/data/redux/thunkActions/requests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('requests thunkActions module', () => {
let loadImages;
let dispatchedAction;
const expectedArgs = {
blockId: selectors.app.blockId(testState),
studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
learningContextId: selectors.app.learningContextId(testState),
};
Expand Down Expand Up @@ -316,19 +317,33 @@ describe('requests thunkActions module', () => {
});
describe('uploadAsset', () => {
const asset = 'SoME iMage CoNtent As String';
testNetworkRequestAction({
action: requests.uploadAsset,
args: { asset, ...fetchParams },
expectedString: 'with uploadAsset promise',
expectedData: {
...fetchParams,
requestKey: RequestKeys.uploadAsset,
promise: api.uploadAsset({
learningContextId: selectors.app.learningContextId(testState),
asset,
studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
}),
},
let uploadAsset;
let dispatchedAction;
const expectedArgs = {
learningContextId: selectors.app.learningContextId(testState),
studioEndpointUrl: selectors.app.studioEndpointUrl(testState),
blockId: selectors.app.blockId(testState),
asset,
};
beforeEach(() => {
uploadAsset = jest.fn((args) => new Promise((resolve) => {
resolve({ data: { asset: args } });
}));
jest.spyOn(api, apiKeys.uploadAsset).mockImplementationOnce(uploadAsset);
requests.uploadAsset({
asset, ...fetchParams, onSuccess, onFailure,
})(dispatch, () => testState);
[[dispatchedAction]] = dispatch.mock.calls;
});
it('dispatches networkRequest', () => {
expect(dispatchedAction.networkRequest).not.toEqual(undefined);
});
test('forwards onSuccess and onFailure', () => {
expect(dispatchedAction.networkRequest.onSuccess).toEqual(onSuccess);
expect(dispatchedAction.networkRequest.onFailure).toEqual(onFailure);
});
test('api.fetchImages promise called with studioEndpointUrl and learningContextId', () => {
expect(uploadAsset).toHaveBeenCalledWith(expectedArgs);
});
});
describe('uploadThumbnail', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/editors/sharedComponents/SelectionModal/GalleryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const GalleryCard = ({
/>
</div>
)}
{asset.dateAdded && (
<p className="text-gray-500" style={{ fontSize: '11px' }}>
<FormattedMessage
{...messages.addedDate}
Expand All @@ -84,6 +85,7 @@ const GalleryCard = ({
}}
/>
</p>
)}
</div>
</div>
</SelectableBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ exports[`TinyMceWidget snapshots ImageUploadModal is not rendered 1`] = `
],
},
"initializeEditor": undefined,
"isLibrary": true,
"learningContextId": "course+org+run",
"isLibrary": false,
"learningContextId": "library-v1:org+t01",
"lmsEndpointUrl": "sOmEvaLue.cOm",
"minHeight": undefined,
"openImgModal": [MockFunction modal.openModal],
Expand Down
2 changes: 1 addition & 1 deletion src/editors/sharedComponents/TinyMceWidget/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('TinyMceWidget', () => {
expect(wrapper.instance.findByType(SourceCodeModal).length).toBe(0);
});
test('ImageUploadModal is not rendered', () => {
const wrapper = shallow(<TinyMceWidget {...props} isLibrary />);
const wrapper = shallow(<TinyMceWidget {...props} learningContextId="library-v1:org+t01" />);
expect(wrapper.snapshot).toMatchSnapshot();
expect(wrapper.instance.findByType(ImageUploadModal).length).toBe(0);
});
Expand Down

0 comments on commit f8a53ad

Please sign in to comment.