100% tests coverage
parent
4595953fc1
commit
f41549dd0d
|
@ -5,7 +5,7 @@
|
||||||
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
|
||||||
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
|
||||||
"testEnvironment": "jsdom",
|
"testEnvironment": "jsdom",
|
||||||
"collectCoverage": false,
|
"collectCoverage": true,
|
||||||
"coverageThreshold": {
|
"coverageThreshold": {
|
||||||
"global": {
|
"global": {
|
||||||
"branches": 50,
|
"branches": 50,
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { reducer, dispatchActions } from "../src/reducer";
|
||||||
|
import { TuitioToken } from "@flare/tuitio-client";
|
||||||
|
import { TuitioReactState, TuitioDispatchActions } from "../src/types";
|
||||||
|
import { initialState } from "../src/initialState";
|
||||||
|
import { Dispatch } from "react";
|
||||||
|
|
||||||
|
describe("reducer", () => {
|
||||||
|
it("should return the initial state by default", () => {
|
||||||
|
const result = reducer(undefined, { type: "UNKNOWN_ACTION" });
|
||||||
|
expect(result).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle the "onLoginSuccess" action', () => {
|
||||||
|
const token: TuitioToken = { raw: "abc123", validFrom: new Date(), validUntil: new Date() };
|
||||||
|
const result = reducer(initialState, { type: "onLoginSuccess", token, userName: "user" });
|
||||||
|
expect(result).toEqual({ ...initialState, token, userName: "user" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle the "onLogout" action', () => {
|
||||||
|
const state: TuitioReactState = { ...initialState, configuration: { tuitioUrl: "https://test.com/api" } };
|
||||||
|
const result = reducer(state, { type: "onLogout" });
|
||||||
|
expect(result).toEqual({ ...initialState, configuration: state.configuration });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("dispatchActions", () => {
|
||||||
|
let dispatch: jest.Mocked<Dispatch<any>>;
|
||||||
|
let actions: TuitioDispatchActions;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
dispatch = jest.fn();
|
||||||
|
actions = dispatchActions(dispatch);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should dispatch an action with type 'onLoginSuccess' and payload when 'onLoginSuccess' is called", () => {
|
||||||
|
const token: TuitioToken = { raw: "test", validFrom: new Date(), validUntil: new Date() };
|
||||||
|
const userName = "test";
|
||||||
|
actions.onLoginSuccess(token, userName);
|
||||||
|
expect(dispatch).toHaveBeenCalledWith({ type: "onLoginSuccess", token, userName });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should dispatch an action with type 'onLogout' when 'onLogout' is called", () => {
|
||||||
|
actions.onLogout();
|
||||||
|
expect(dispatch).toHaveBeenCalledWith({ type: "onLogout" });
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue