client/src/selectors/__tests__/syncSelectors.test.js
changeset 168 ea92f4fe783d
equal deleted inserted replaced
167:1f340f3597a8 168:ea92f4fe783d
       
     1 import {
       
     2   getLastSync,
       
     3   isSynchronizing,
       
     4   isSynchronized
       
     5 } from '../syncSelectors';
       
     6 
       
     7 import { ActionEnum } from '../../constants';
       
     8 
       
     9 describe('Sync selector test', () => {
       
    10 
       
    11   test('getLastSync', ()  => {
       
    12     const inputState = {
       
    13       status: {
       
    14         isSynchronizing: false,
       
    15         online: false
       
    16       },
       
    17       authStatus: {
       
    18         token: '',
       
    19         isAuthenticated: false,
       
    20         clientId: null,
       
    21         lastSync: 110,
       
    22         currentUser: null,
       
    23         currentGroup: null
       
    24       },
       
    25     };
       
    26 
       
    27     expect(getLastSync(inputState)).toBe(110);
       
    28   });
       
    29 
       
    30   test('getLastSyncAbsent', ()  => {
       
    31     const inputState = {
       
    32       status: {
       
    33         isSynchronizing: false,
       
    34         online: false
       
    35       },
       
    36       authStatus: {
       
    37         token: '',
       
    38         isAuthenticated: false,
       
    39         clientId: null,
       
    40         currentUser: null,
       
    41         currentGroup: null
       
    42       },
       
    43     };
       
    44 
       
    45     expect(getLastSync(inputState)).toBe(0);
       
    46   });
       
    47 
       
    48 
       
    49   test('getLastSyncAuthStatusAbsent', ()  => {
       
    50     const inputState = {
       
    51       status: {
       
    52         isSynchronizing: false,
       
    53         online: false
       
    54       },
       
    55     };
       
    56 
       
    57     expect(getLastSync(inputState)).toBe(0);
       
    58   });
       
    59 
       
    60   test('isSynchronizingFalse', ()  => {
       
    61     const inputState = {
       
    62       status: {
       
    63         isSynchronizing: false,
       
    64         online: false
       
    65       },
       
    66       authStatus: {
       
    67         token: '',
       
    68         isAuthenticated: false,
       
    69         clientId: null,
       
    70         lastSync: 110,
       
    71         currentUser: null,
       
    72         currentGroup: null
       
    73       },
       
    74     };
       
    75 
       
    76     expect(isSynchronizing(inputState)).toBe(false);
       
    77   });
       
    78 
       
    79 
       
    80   test('isSynchronizingTrue', ()  => {
       
    81     const inputState = {
       
    82       status: {
       
    83         isSynchronizing: true,
       
    84         online: false
       
    85       },
       
    86       authStatus: {
       
    87         token: '',
       
    88         isAuthenticated: false,
       
    89         clientId: null,
       
    90         lastSync: 110,
       
    91         currentUser: null,
       
    92         currentGroup: null
       
    93       },
       
    94     };
       
    95 
       
    96     expect(isSynchronizing(inputState)).toBe(true);
       
    97   });
       
    98 
       
    99   test('isSynchronizedEmpty', ()  => {
       
   100     const inputState = {
       
   101       status: {
       
   102         isSynchronizing: true,
       
   103         online: false
       
   104       },
       
   105       authStatus: {
       
   106         token: '',
       
   107         isAuthenticated: false,
       
   108         clientId: null,
       
   109         lastSync: 110,
       
   110         currentUser: null,
       
   111         currentGroup: null
       
   112       },
       
   113       notes: [],
       
   114       sessions: []
       
   115     };
       
   116 
       
   117     expect(isSynchronized(inputState)).toBe(true);
       
   118   });
       
   119 
       
   120 
       
   121   test('isSynchronizedOk', ()  => {
       
   122     const inputState = {
       
   123       status: {
       
   124         isSynchronizing: true,
       
   125         online: false
       
   126       },
       
   127       authStatus: {
       
   128         token: '',
       
   129         isAuthenticated: false,
       
   130         clientId: null,
       
   131         lastSync: 110,
       
   132         currentUser: null,
       
   133         currentGroup: null
       
   134       },
       
   135       notes: [ { title: 'note1', action: ActionEnum.NONE }, { title: 'note2', action: ActionEnum.NONE }, { title: 'note3', action: ActionEnum.NONE } ],
       
   136       sessions: [ { title: 'session1', action: ActionEnum.NONE }, { title: 'session2', action: ActionEnum.NONE }, { title: 'session3', action: ActionEnum.NONE } ]
       
   137     };
       
   138 
       
   139     expect(isSynchronized(inputState)).toBe(true);
       
   140   });
       
   141 
       
   142 
       
   143   test('isSynchronizedKo', ()  => {
       
   144     const inputState = {
       
   145       status: {
       
   146         isSynchronizing: true,
       
   147         online: false
       
   148       },
       
   149       authStatus: {
       
   150         token: '',
       
   151         isAuthenticated: false,
       
   152         clientId: null,
       
   153         lastSync: 110,
       
   154         currentUser: null,
       
   155         currentGroup: null
       
   156       },
       
   157       notes: [ { title: 'note1', action: ActionEnum.NONE }, { title: 'note2', action: ActionEnum.UPDATED }, { title: 'note3', action: ActionEnum.NONE } ],
       
   158       sessions: [ { title: 'session1', action: ActionEnum.NONE }, { title: 'session2', action: ActionEnum.DELETED }, { title: 'session3', action: ActionEnum.NONE } ]
       
   159     };
       
   160 
       
   161     expect(isSynchronized(inputState)).toBe(false);
       
   162   });
       
   163 
       
   164 
       
   165   test('isSynchronizedJustOne', ()  => {
       
   166     const inputState = {
       
   167       status: {
       
   168         isSynchronizing: true,
       
   169         online: false
       
   170       },
       
   171       authStatus: {
       
   172         token: '',
       
   173         isAuthenticated: false,
       
   174         clientId: null,
       
   175         lastSync: 110,
       
   176         currentUser: null,
       
   177         currentGroup: null
       
   178       },
       
   179       notes: [ { title: 'note1', action: ActionEnum.NONE }, { title: 'note2', action: ActionEnum.UPDATED }, { title: 'note3', action: ActionEnum.NONE } ],
       
   180       sessions: [ { title: 'session1', action: ActionEnum.NONE }, { title: 'session2', action: ActionEnum.NONE }, { title: 'session3', action: ActionEnum.NONE } ]
       
   181     };
       
   182 
       
   183     expect(isSynchronized(inputState)).toBe(false);
       
   184   });
       
   185 
       
   186 })