|
| 1 | +import assert from "yeoman-assert"; |
| 2 | +import helpers from "yeoman-test"; |
| 3 | + |
| 4 | +describe("yo codibly-ts:structure-store", () => { |
| 5 | + beforeAll(async () => { |
| 6 | + await helpers |
| 7 | + .run(require("../generators/structure"), { |
| 8 | + resolved: require.resolve("../generators/structure/index.js"), |
| 9 | + namespace: "codibly-ts:structure" |
| 10 | + }) |
| 11 | + .withLocalConfig({ rootDir: "tmp" }) |
| 12 | + .withPrompts({ |
| 13 | + task: "store", |
| 14 | + isTaskNameSameAsModule: false, |
| 15 | + module: "UserDetails", |
| 16 | + name: "User" |
| 17 | + }); |
| 18 | + }); |
| 19 | + |
| 20 | + const path = "tmp/UserDetails/store/User/User"; |
| 21 | + |
| 22 | + const actionPath = `${path}.action.ts`; |
| 23 | + const detectorPath = `${path}.detector.ts`; |
| 24 | + const reducerPath = `${path}.reducer.ts`; |
| 25 | + const selectorPath = `${path}.selector.ts`; |
| 26 | + const statePath = `${path}.state.ts`; |
| 27 | + |
| 28 | + it("generates required files", () => { |
| 29 | + assert.file([ |
| 30 | + actionPath, |
| 31 | + detectorPath, |
| 32 | + reducerPath, |
| 33 | + selectorPath, |
| 34 | + statePath |
| 35 | + ]); |
| 36 | + }); |
| 37 | + |
| 38 | + it("creates proper content in Action", () => { |
| 39 | + assert.fileContent(actionPath, "namespace UserAction {}"); |
| 40 | + }); |
| 41 | + |
| 42 | + it("creates proper content in Detector", () => { |
| 43 | + assert.fileContent(detectorPath, "const userDetector;"); |
| 44 | + }); |
| 45 | + |
| 46 | + it("creates proper content in Reducer", () => { |
| 47 | + assert.fileContent( |
| 48 | + reducerPath, |
| 49 | + "import { UserState } from './User.state';" |
| 50 | + ); |
| 51 | + assert.fileContent( |
| 52 | + reducerPath, |
| 53 | + "export const userReducer = combineReducers<UserState>({});" |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it("create proper content in Selector", () => { |
| 58 | + assert.fileContent( |
| 59 | + selectorPath, |
| 60 | + "import { UserMountedState, UserState } from './User.state';" |
| 61 | + ); |
| 62 | + assert.fileContent(selectorPath, "namespace UserSelector"); |
| 63 | + assert.fileContent( |
| 64 | + selectorPath, |
| 65 | + "const getDomain = (state?: UserMountedState) => (state && state.user) || ({} as UserState)" |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + it("create proper content in State", () => { |
| 70 | + assert.fileContent(statePath, "namespace UserState"); |
| 71 | + assert.fileContent(statePath, "const INITIAL: UserState = {};"); |
| 72 | + assert.fileContent(statePath, 'const DOMAIN = "USER";'); |
| 73 | + assert.fileContent(statePath, "type UserMountedState"); |
| 74 | + }); |
| 75 | +}); |
0 commit comments