• 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

94.87
/src/js/reducers/deviceReducer.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 DeviceConstants from '../constants/deviceConstants';
15
import { RECEIVE_DEVICE_MONITOR_CONFIG } from '../constants/monitorConstants';
16
import { duplicateFilter } from '../helpers';
17

18
export const initialState = {
184✔
19
  byId: {
20
    // [deviceId]: {
21
    //   ...,
22
    //   twinsByIntegration: { [external.provider.id]: twinData }
23
    // }
24
  },
25
  byStatus: {
26
    [DeviceConstants.DEVICE_STATES.accepted]: { deviceIds: [], total: 0 },
27
    active: { deviceIds: [], total: 0 },
28
    inactive: { deviceIds: [], total: 0 },
29
    [DeviceConstants.DEVICE_STATES.pending]: { deviceIds: [], total: 0 },
30
    [DeviceConstants.DEVICE_STATES.preauth]: { deviceIds: [], total: 0 },
31
    [DeviceConstants.DEVICE_STATES.rejected]: { deviceIds: [], total: 0 }
32
  },
33
  deviceList: {
34
    deviceIds: [],
35
    ...DeviceConstants.DEVICE_LIST_DEFAULTS,
36
    selectedAttributes: [],
37
    selectedIssues: [],
38
    selection: [],
39
    sort: [
40
      // { direction: SORTING_OPTIONS.desc, key: null, scope: null }
41
    ],
42
    state: DeviceConstants.DEVICE_STATES.accepted,
43
    total: 0
44
  },
45
  filters: [
46
    // { key: 'device_type', value: 'raspberry', operator: '$eq', scope: 'inventory' }
47
  ],
48
  filteringAttributes: { identityAttributes: [], inventoryAttributes: [], systemAttributes: [], tagAttributes: [] },
49
  filteringAttributesLimit: 10,
50
  filteringAttributesConfig: {
51
    attributes: {
52
      // inventory: ['some_attribute']
53
    },
54
    count: 0,
55
    limit: 100
56
  },
57
  reports: [
58
    // { items: [{ key: "someKey", count: 42  }], otherCount: 123, total: <otherCount + itemsCount> }
59
  ],
60
  total: 0,
61
  limit: 0,
62
  groups: {
63
    byId: {
64
      // groupName: { deviceIds: [], total: 0, filters: [] },
65
      // dynamo: { deviceIds: [], total: 3, filters: [{ a: 1 }] }
66
    },
67
    selectedGroup: undefined
68
  }
69
};
70

71
const deviceReducer = (state = initialState, action) => {
184✔
72
  switch (action.type) {
3,830✔
73
    case DeviceConstants.RECEIVE_GROUPS:
74
    case DeviceConstants.RECEIVE_DYNAMIC_GROUPS:
75
    case DeviceConstants.REMOVE_STATIC_GROUP:
76
    case DeviceConstants.REMOVE_DYNAMIC_GROUP:
77
      return {
49✔
78
        ...state,
79
        groups: {
80
          ...state.groups,
81
          byId: action.groups
82
        }
83
      };
84
    case DeviceConstants.ADD_TO_GROUP: {
85
      let group = {
2✔
86
        deviceIds: action.deviceIds,
87
        filters: [],
88
        total: 1
89
      };
90
      if (state.groups.byId[action.group]) {
2!
UNCOV
91
        group = {
×
92
          filters: [],
93
          ...state.groups.byId[action.group],
94
          deviceIds: [...state.groups.byId[action.group].deviceIds, ...action.deviceIds],
95
          total: state.groups.byId[action.group].total + 1
96
        };
UNCOV
97
        group.deviceIds.filter(duplicateFilter);
×
98
      }
99
      return {
2✔
100
        ...state,
101
        groups: {
102
          ...state.groups,
103
          byId: {
104
            ...state.groups.byId,
105
            [action.group]: group
106
          }
107
        }
108
      };
109
    }
110
    case DeviceConstants.REMOVE_FROM_GROUP: {
111
      const { deviceIds = [], total = 0, ...maybeExistingGroup } = state.groups.byId[action.group] || {};
3✔
112
      const group = {
3✔
113
        ...maybeExistingGroup,
114
        deviceIds: deviceIds.filter(id => !action.deviceIds.includes(id)),
4✔
115
        total: Math.max(total - action.deviceIds.length, 0)
116
      };
117
      let byId = {};
3✔
118
      let selectedGroup = state.groups.selectedGroup;
3✔
119
      if (group.total || group.deviceIds.length) {
3✔
120
        byId = {
1✔
121
          ...state.groups.byId,
122
          [action.group]: group
123
        };
124
      } else if (state.groups.selectedGroup === action.group) {
2✔
125
        selectedGroup = undefined;
1✔
126
        // eslint-disable-next-line no-unused-vars
127
        const { [action.group]: removal, ...remainingById } = state.groups.byId;
1✔
128
        byId = remainingById;
1✔
129
      }
130
      return {
3✔
131
        ...state,
132
        groups: {
133
          ...state.groups,
134
          byId,
135
          selectedGroup
136
        }
137
      };
138
    }
139
    case DeviceConstants.ADD_DYNAMIC_GROUP:
140
    case DeviceConstants.ADD_STATIC_GROUP:
141
    case DeviceConstants.RECEIVE_GROUP_DEVICES:
142
      return {
24✔
143
        ...state,
144
        groups: {
145
          ...state.groups,
146
          byId: { ...state.groups.byId, [action.groupName]: action.group }
147
        }
148
      };
149
    case DeviceConstants.SELECT_GROUP:
150
      return {
1✔
151
        ...state,
152
        deviceList: {
153
          ...state.deviceList,
154
          deviceIds: state.groups.byId[action.group] && state.groups.byId[action.group].deviceIds.length > 0 ? state.groups.byId[action.group].deviceIds : []
3!
155
        },
156
        groups: {
157
          ...state.groups,
158
          selectedGroup: action.group
159
        }
160
      };
161
    case DeviceConstants.SET_DEVICE_LIST_STATE:
162
      return { ...state, deviceList: action.state };
28✔
163
    case DeviceConstants.SET_FILTER_ATTRIBUTES:
164
      return { ...state, filteringAttributes: action.attributes };
17✔
165
    case DeviceConstants.SET_FILTERABLES_CONFIG:
166
      return {
3✔
167
        ...state,
168
        filteringAttributesConfig: {
169
          attributes: action.attributes,
170
          count: action.count,
171
          limit: action.limit
172
        }
173
      };
174
    case DeviceConstants.RECEIVE_DEVICES:
175
      return {
78✔
176
        ...state,
177
        byId: {
178
          ...state.byId,
179
          ...action.devicesById
180
        }
181
      };
182
    case DeviceConstants.SET_DEVICE_FILTERS: {
183
      const filters = action.filters.filter(filter => filter.key && filter.operator && filter.scope && typeof filter.value !== 'undefined');
2✔
184
      return {
2✔
185
        ...state,
186
        filters
187
      };
188
    }
189

190
    case DeviceConstants.SET_INACTIVE_DEVICES:
191
      return {
12✔
192
        ...state,
193
        byStatus: {
194
          ...state.byStatus,
195
          active: {
196
            total: action.activeDeviceTotal
197
          },
198
          inactive: {
199
            total: action.inactiveDeviceTotal
200
          }
201
        }
202
      };
203
    case DeviceConstants.SET_DEVICE_REPORTS:
204
      return {
24✔
205
        ...state,
206
        reports: action.reports
207
      };
208
    case DeviceConstants.SET_PENDING_DEVICES:
209
    case DeviceConstants.SET_REJECTED_DEVICES:
210
    case DeviceConstants.SET_PREAUTHORIZED_DEVICES:
211
    case DeviceConstants.SET_ACCEPTED_DEVICES: {
212
      const statusDeviceInfo = action.total || action.forceUpdate ? { deviceIds: action.deviceIds, total: action.total } : state.byStatus[action.status];
35✔
213
      return {
35✔
214
        ...state,
215
        byStatus: {
216
          ...state.byStatus,
217
          [action.status]: {
218
            ...statusDeviceInfo
219
          }
220
        }
221
      };
222
    }
223

224
    case DeviceConstants.SET_ACCEPTED_DEVICES_COUNT:
225
    case DeviceConstants.SET_PENDING_DEVICES_COUNT:
226
    case DeviceConstants.SET_REJECTED_DEVICES_COUNT:
227
    case DeviceConstants.SET_PREAUTHORIZED_DEVICES_COUNT:
228
      return {
779✔
229
        ...state,
230
        byStatus: {
231
          ...state.byStatus,
232
          [action.status]: {
233
            ...state.byStatus[action.status],
234
            total: action.count
235
          }
236
        }
237
      };
238
    case DeviceConstants.SET_TOTAL_DEVICES:
239
      return { ...state, total: action.count };
2✔
240
    case DeviceConstants.SET_DEVICE_LIMIT:
241
      return { ...state, limit: action.limit };
4✔
242
    case DeviceConstants.RECEIVE_DEVICE:
243
    case DeviceConstants.RECEIVE_DEVICE_CONFIG:
244
    case DeviceConstants.RECEIVE_DEVICE_CONNECT:
245
    case RECEIVE_DEVICE_MONITOR_CONFIG: {
246
      const { device } = action;
11✔
247
      return {
11✔
248
        ...state,
249
        byId: {
250
          ...state.byId,
251
          [device.id]: {
252
            ...state.byId[device.id],
253
            ...device
254
          }
255
        }
256
      };
257
    }
258
    default:
259
      return state;
2,756✔
260
  }
261
};
262

263
export default deviceReducer;
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