Przeglądaj źródła

fix: added reducer test

Torkel Ödegaard 7 lat temu
rodzic
commit
8096cd8f33
1 zmienionych plików z 31 dodań i 6 usunięć
  1. 31 6
      public/app/features/folders/state/reducers.test.ts

+ 31 - 6
public/app/features/folders/state/reducers.test.ts

@@ -1,17 +1,42 @@
 import { Action, ActionTypes } from './actions';
+import { FolderDTO } from 'app/types';
 import { inititalState, folderReducer } from './reducers';
 
+function getTestFolder(): FolderDTO {
+  return {
+    id: 1,
+    title: 'test folder',
+    uid: 'asd',
+    url: 'url',
+    canSave: true,
+    version: 0,
+  };
+}
+
 describe('folder reducer', () => {
-  it('should set teams', () => {
-    const payload = [getMockTeam()];
+  it('should load folder and set hasChanged to false', () => {
+    const folder = getTestFolder();
+
+    const action: Action = {
+      type: ActionTypes.LoadFolder,
+      payload: folder,
+    };
+
+    const state = folderReducer(inititalState, action);
+
+    expect(state.hasChanged).toEqual(false);
+    expect(state.title).toEqual('test folder');
+  });
 
+  it('should set title', () => {
     const action: Action = {
-      type: ActionTypes.LoadTeams,
-      payload,
+      type: ActionTypes.SetFolderTitle,
+      payload: 'new title',
     };
 
-    const result = teamsReducer(initialTeamsState, action);
+    const state = folderReducer(inititalState, action);
 
-    expect(result.teams).toEqual(payload);
+    expect(state.hasChanged).toEqual(true);
+    expect(state.title).toEqual('new title');
   });
 });