Skip to content

Commit

Permalink
feat: [IOCOM-1821] Tests for actions/reducer/selectors on FIMS' histo…
Browse files Browse the repository at this point in the history
…ry (#6366)

## Short description
This PR adds tests for actions, reducer and selector on FIMS' history

## List of changes proposed in this pull request
On FIMS' history, tests for:
- actions
- reducer
- selectors
- `isFimsHistoryExportingSelector` internal behaviour changed to use
`isLoading` function instead of checking the instance's `kind` property

## How to test
CI tests should succeed

---------

Co-authored-by: Martino Cesari Tomba <[email protected]>
  • Loading branch information
Vangaorth and forrest57 authored Nov 21, 2024
1 parent 6211c48 commit 6759423
Show file tree
Hide file tree
Showing 6 changed files with 743 additions and 3 deletions.
101 changes: 101 additions & 0 deletions ts/features/fims/history/store/actions/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {
fimsHistoryExport,
fimsHistoryGet,
resetFimsHistoryExportState,
resetFimsHistoryState
} from "..";
import { Access } from "../../../../../../../definitions/fims_history/Access";
import { FimsExportSuccessStates } from "../../reducer";

describe("fimsHistoryGet.request", () => {
[undefined, "01JBVCKDNW4Y2YMACBP56H9E2Z"].forEach(continuationToken =>
[undefined, false, true].forEach(shouldReloadFromScratch => {
it("Should have a type of 'FIMS_GET_HISTORY_REQUEST' and match expected 'continuationToken' and 'shouldReloadFromScratch' payload", () => {
const fimsHistoryGetRequest = fimsHistoryGet.request({
continuationToken,
shouldReloadFromScratch
});
expect(fimsHistoryGetRequest.type).toBe("FIMS_GET_HISTORY_REQUEST");
expect(fimsHistoryGetRequest.payload).toEqual({
continuationToken,
shouldReloadFromScratch
});
});
})
);
});

describe("fimsHistoryGet.success", () => {
(
[[], [{}, {}, {}]] as unknown as ReadonlyArray<ReadonlyArray<Access>>
).forEach(data =>
[undefined, "01JBVCKDNW4Y2YMACBP56H9E2Z"].forEach(next => {
it("Should have a type of 'FIMS_GET_HISTORY_SUCCESS' and match expected 'items' and 'continuationToken' payload", () => {
const fimsHistoryGetSuccess = fimsHistoryGet.success({
data,
next
});
expect(fimsHistoryGetSuccess.type).toBe("FIMS_GET_HISTORY_SUCCESS");
expect(fimsHistoryGetSuccess.payload).toEqual({
data,
next
});
});
})
);
});

describe("fimsHistoryGet.failure", () => {
it("Should have a type of 'FIMS_GET_HISTORY_FAILURE' and match expected string input payload", () => {
const failureReason = "A random reason";
const fimsHistoryGetFailure = fimsHistoryGet.failure(failureReason);
expect(fimsHistoryGetFailure.type).toBe("FIMS_GET_HISTORY_FAILURE");
expect(fimsHistoryGetFailure.payload).toBe(failureReason);
});
});

describe("fimsHistoryExport.request", () => {
it("Should have a type of 'FIMS_HISTORY_EXPORT_REQUEST' and no payload", () => {
const fimsHistoryExportRequest = fimsHistoryExport.request();
expect(fimsHistoryExportRequest.type).toBe("FIMS_HISTORY_EXPORT_REQUEST");
expect(fimsHistoryExportRequest.payload).toBeUndefined();
});
});

describe("fimsHistoryExport.success", () =>
(
[
"SUCCESS",
"ALREADY_EXPORTING"
] as unknown as ReadonlyArray<FimsExportSuccessStates>
).forEach(successState => {
it("Should have a type of 'FIMS_HISTORY_EXPORT_SUCCESS' and expected value for input 'FimsExportSuccessStates' payload", () => {
const fimsHistoryExportSuccess = fimsHistoryExport.success(successState);
expect(fimsHistoryExportSuccess.type).toBe("FIMS_HISTORY_EXPORT_SUCCESS");
expect(fimsHistoryExportSuccess.payload).toBe(successState);
});
}));

describe("fimsHistoryExport.failure", () => {
it("Should have a type of 'FIMS_HISTORY_EXPORT_FAILURE' and no payload", () => {
const fimsHistoryExportFailure = fimsHistoryExport.failure();
expect(fimsHistoryExportFailure.type).toBe("FIMS_HISTORY_EXPORT_FAILURE");
expect(fimsHistoryExportFailure.payload).toBeUndefined();
});
});

describe("resetFimsHistoryState", () => {
it("Should have a type of 'RESET_FIMS_HISTORY_STATE'", () => {
const resetFimsHistory = resetFimsHistoryState();
expect(resetFimsHistory.type).toBe("RESET_FIMS_HISTORY_STATE");
expect(resetFimsHistory.payload).toBeUndefined();
});
});

describe("resetFimsHistoryExportState", () => {
it("Should have a type of 'RESET_FIMS_HISTORY'", () => {
const resetFimsHistoryExport = resetFimsHistoryExportState();
expect(resetFimsHistoryExport.type).toBe("RESET_FIMS_HISTORY");
expect(resetFimsHistoryExport.payload).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`INITIAL_STATE Should match snapshot 1`] = `
{
"consentsList": {
"kind": "PotNone",
},
"historyExportState": {
"kind": "undefined",
},
}
`;
Loading

0 comments on commit 6759423

Please sign in to comment.