Files
frontend-app-gradebook/src/data/actions/utils.test.js
Ben Warzeski a4df8f7238 refactor: update test coverage (#202)
* clean up and test segment integration

* add tests for action utils

* add tests for store aggregator and utils

* clean up un-used paths in thunkAction testUtils

* clean up filter reducer coverage

* add filter reducer tests for filterMenu actions

* clean up grades selectors coverage

* separate App and add unit tests

* ignore external files in coverage analysis

* remove old/unused code from StrictDict and clean up tests

* clean up FileUploadForm coverage

* more cleanup for StrictDict tests

* clean up GradesTab test coverage

* clean up GradesTab coverage

* ignore reducer-mapping for unit-test coverage

* clean up AssignmentFilter test coverage

* add index-level test coverage

* temp remove snapshots

* re-add App snapshot

* v1.4.41
2021-07-02 12:32:18 -04:00

35 lines
1.2 KiB
JavaScript

import { createAction } from '@reduxjs/toolkit';
import * as utils from './utils';
jest.mock('@reduxjs/toolkit', () => ({
createAction: (key, ...args) => ({ action: key, args }),
}));
describe('redux action utils', () => {
describe('formatDateForDisplay', () => {
it('returns the datetime as a formatted string', () => {
expect(utils.formatDateForDisplay(new Date('Jun 3 2021 11:59 AM EDT'))).toEqual(
'June 3, 2021 at 03:59 PM UTC',
);
});
});
describe('sortAlphaAsc', () => {
it('returns sorting value (-1, 0, 1) by uppercase username', () => {
const sort = (v1, v2) => utils.sortAlphaAsc({ username: v1 }, { username: v2 });
expect(sort('aName', 'ANAme')).toEqual(0);
expect(sort('aName', 'laterName')).toEqual(-1);
expect(sort('laterName', 'aName')).toEqual(1);
});
});
describe('createActionFactory', () => {
it('returns an action creator with the data key', () => {
const dataKey = 'part-of-the-model';
const actionKey = 'an-action';
const args = ['some', 'args'];
expect(utils.createActionFactory(dataKey)(actionKey, ...args)).toEqual(
createAction(`${dataKey}/${actionKey}`, ...args),
);
});
});
});