• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/src/js/reducers/userReducer.js
1
// Copyright 2019 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import * as UserConstants from '../constants/userConstants';
15

16
export const initialState = {
184✔
17
  byId: {},
18
  currentUser: null,
19
  customColumns: [],
20
  currentSession: {
21
    // { token: window.localStorage.getItem('JWT'), expiresAt: '2023-01-01T00:15:00.000Z' | undefined }, // expiresAt depending on the stay logged in setting
22
  },
23
  qrCode: null,
24
  globalSettings: {
25
    id_attribute: undefined,
26
    previousFilters: [],
27
    previousPhases: [],
28
    retries: 0
29
  },
30
  permissionSetsById: {
31
    ...UserConstants.defaultPermissionSets
32
  },
33
  rolesById: {
34
    ...UserConstants.rolesById
35
  },
36
  showConnectDeviceDialog: false,
37
  showStartupNotification: false,
38
  tooltips: {
39
    byId: {
40
      // <id>: { readState: <read|unread> } // this object is getting enhanced by the tooltip texts in the app constants
41
    }
42
  },
43
  userSettings: {
44
    columnSelection: [],
45
    onboarding: {}
46
  }
47
};
48

49
const userReducer = (state = initialState, action) => {
184✔
50
  switch (action.type) {
3,798!
51
    case UserConstants.RECEIVED_QR_CODE:
52
      return {
3✔
53
        ...state,
54
        qrCode: action.value
55
      };
56
    case UserConstants.SUCCESSFULLY_LOGGED_IN:
57
      return {
11✔
58
        ...state,
59
        currentSession: action.value
60
      };
61
    case UserConstants.RECEIVED_USER_LIST:
62
      return {
14✔
63
        ...state,
64
        byId: { ...action.users }
65
      };
66
    case UserConstants.RECEIVED_ACTIVATION_CODE:
67
      return {
2✔
68
        ...state,
69
        activationCode: action.code
70
      };
71
    case UserConstants.RECEIVED_USER:
72
      return {
7✔
73
        ...state,
74
        byId: {
75
          ...state.byId,
76
          [action.user.id]: {
77
            ...action.user
78
          }
79
        },
80
        currentUser: action.user.id
81
      };
82
    case UserConstants.CREATED_USER:
83
      // the new user gets a 0 as id, since this will be overwritten by the retrieved userlist anyway + there is no way to know the id before
84
      return {
3✔
85
        ...state,
86
        byId: {
87
          ...state.byId,
88
          0: action.user
89
        }
90
      };
91
    case UserConstants.REMOVED_USER: {
92
      // eslint-disable-next-line no-unused-vars
93
      const { [action.userId]: removedUser, ...byId } = state.byId;
2✔
94
      return {
2✔
95
        ...state,
96
        byId,
97
        currentUser: state.currentUser === action.userId ? null : state.currentUser
2!
98
      };
99
    }
100
    case UserConstants.UPDATED_USER:
101
      return {
15✔
102
        ...state,
103
        byId: {
104
          ...state.byId,
105
          [action.userId]: {
106
            ...state.byId[action.userId],
107
            ...action.user
108
          }
109
        }
110
      };
111
    case UserConstants.RECEIVED_PERMISSION_SETS:
112
      return {
4✔
113
        ...state,
114
        permissionSetsById: action.value
115
      };
116
    case UserConstants.RECEIVED_ROLES:
117
    case UserConstants.REMOVED_ROLE:
118
      return {
9✔
119
        ...state,
120
        rolesById: action.value
121
      };
122
    case UserConstants.CREATED_ROLE:
123
    case UserConstants.UPDATED_ROLE:
124
      return {
5✔
125
        ...state,
126
        rolesById: {
127
          ...state.rolesById,
128
          [action.roleId]: {
129
            ...state.rolesById[action.roleId],
130
            ...action.role
131
          }
132
        }
133
      };
134
    case UserConstants.SET_CUSTOM_COLUMNS:
135
      return {
8✔
136
        ...state,
137
        customColumns: action.value
138
      };
139
    case UserConstants.SET_GLOBAL_SETTINGS:
140
      return {
14✔
141
        ...state,
142
        settingsInitialized: true,
143
        globalSettings: {
144
          ...state.globalSettings,
145
          ...action.settings
146
        }
147
      };
148
    case UserConstants.SET_USER_SETTINGS:
149
      return {
50✔
150
        ...state,
151
        userSettingsInitialized: true,
152
        userSettings: {
153
          ...state.userSettings,
154
          ...action.settings
155
        }
156
      };
157
    case UserConstants.SET_SHOW_CONNECT_DEVICE:
158
      return {
2✔
159
        ...state,
160
        showConnectDeviceDialog: action.show
161
      };
162
    case UserConstants.SET_SHOW_STARTUP_NOTIFICATION:
163
      return {
2✔
164
        ...state,
165
        showStartupNotification: action.value
166
      };
167
    case UserConstants.SET_TOOLTIP_STATE:
UNCOV
168
      return {
×
169
        ...state,
170
        tooltips: {
171
          ...state.tooltips,
172
          byId: {
173
            ...state.tooltips.byId,
174
            [action.id]: action.value
175
          }
176
        }
177
      };
178
    case UserConstants.SET_TOOLTIPS_STATE:
179
      return {
2✔
180
        ...state,
181
        tooltips: {
182
          ...state.tooltips,
183
          byId: action.value
184
        }
185
      };
186
    default:
187
      return state;
3,645✔
188
  }
189
};
190

191
export default userReducer;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc