import { Ibdd_in, IPartialInterface, OT } from "testeranto/src/Types"; import { ITestImplementation } from "testeranto/src/Types"; import { ActionCreatorWithNonInferrablePayload, ActionCreatorWithoutPayload, ActionCreatorWithPayload, Reducer, Store, } from "@reduxjs/toolkit"; import { createStore, AnyAction, StoreEnhancerStoreCreator } from "redux"; import { IPM } from "testeranto/src/lib/types"; export type WhenShape = [ ( | ActionCreatorWithNonInferrablePayload | ActionCreatorWithoutPayload ), object ]; export type IINput = Reducer; export type IReduxIn = Ibdd_in< IINput, Reducer, Store, IStoreState, StoreEnhancerStoreCreator, WhenShape, (x: IStoreState, pm: IPM) => IStoreState >; export type BaseImplementation< IStoreShape, bddout extends OT > = ITestImplementation< IReduxIn, bddout, { givens: { [K in keyof bddout["givens"]]: IStoreShape; }; whens: { [K in keyof bddout["whens"]]: ( ...x ) => | [string, string?] | [ActionCreatorWithoutPayload] | [ActionCreatorWithPayload, string]; }; checks: { [K in keyof bddout["checks"]]: IStoreShape; }; thens: { [K in keyof bddout["thens"]]: ( ...It: bddout["thens"][K] ) => (ssel: IReduxIn["iselection"], utils: IPM) => void; }; } >; export const ReduxTesterantoInterface = < IStoreShape // iAppOut extends Ibdd_out >() => // testInput: Reducer, // testSpecifications: ITestSpecification, // testImplementations: BaseImplementation { const testInterface: IPartialInterface> = { beforeEach: async function (subject, initializer) { return createStore( subject, initializer ); }, andWhen: async function (store, whenCB) { const [action, payload] = whenCB; store.dispatch(payload ? action(payload) : action()); return store; }, butThen: async function (store, actioner, t, p) { return actioner(store.getState(), p); }, }; return testInterface; };