@@ -250,4 +250,99 @@ describe('DevicesComponent', () => {
250250 component . tagFilterChange ( matSelectChange )
251251 expect ( component . filteredTags ( ) ) . toBe ( mockValue )
252252 } )
253+
254+ describe ( 'getProductType' , ( ) => {
255+ it ( 'should return ISM when bit 4 (0x10) is set' , ( ) => {
256+ const device = { ...device01 , deviceInfo : { fwSku : '16' } } as Device // 0x10 = 16
257+ expect ( component . getProductType ( device ) ) . toBe ( 'ISM' )
258+ } )
259+
260+ it ( 'should return vPro when bit 3 (0x08) is set and bit 4 is not' , ( ) => {
261+ const device = { ...device01 , deviceInfo : { fwSku : '8' } } as Device // 0x08 = 8
262+ expect ( component . getProductType ( device ) ) . toBe ( 'vPro' )
263+ } )
264+
265+ it ( 'should return ISM when both bit 4 and bit 3 are set (ISM takes priority)' , ( ) => {
266+ const device = { ...device01 , deviceInfo : { fwSku : '24' } } as Device // 0x18 = 24
267+ expect ( component . getProductType ( device ) ) . toBe ( 'ISM' )
268+ } )
269+
270+ it ( 'should return empty string when neither bit is set' , ( ) => {
271+ const device = { ...device01 , deviceInfo : { fwSku : '4' } } as Device // 0x04 = 4
272+ expect ( component . getProductType ( device ) ) . toBe ( '' )
273+ } )
274+
275+ it ( 'should return empty string when fwSku is undefined' , ( ) => {
276+ const device = { ...device01 , deviceInfo : undefined } as Device
277+ expect ( component . getProductType ( device ) ) . toBe ( '' )
278+ } )
279+
280+ it ( 'should return empty string when fwSku is not a number' , ( ) => {
281+ const device = { ...device01 , deviceInfo : { fwSku : 'notanumber' } } as Device
282+ expect ( component . getProductType ( device ) ) . toBe ( '' )
283+ } )
284+ } )
285+
286+ describe ( 'onTabChange / applyTabFilter' , ( ) => {
287+ beforeEach ( ( ) => {
288+ component . allDevicesData = [
289+ { ...device01 , deviceInfo : { currentMode : 'acm' , discovered : false } } ,
290+ { ...device02 , deviceInfo : { currentMode : 'not activated' , discovered : true } }
291+ ]
292+ } )
293+
294+ it ( 'should show all devices on tab 0' , ( ) => {
295+ component . onTabChange ( 0 )
296+ expect ( component . devices . data . length ) . toBe ( 2 )
297+ } )
298+
299+ it ( 'should filter to activated devices on tab 1' , ( ) => {
300+ component . onTabChange ( 1 )
301+ expect ( component . devices . data . length ) . toBe ( 1 )
302+ expect ( component . devices . data [ 0 ] . guid ) . toBe ( device01 . guid )
303+ } )
304+
305+ it ( 'should filter to discovered devices on tab 2' , ( ) => {
306+ component . onTabChange ( 2 )
307+ expect ( component . devices . data . length ) . toBe ( 1 )
308+ expect ( component . devices . data [ 0 ] . guid ) . toBe ( device02 . guid )
309+ } )
310+
311+ it ( 'should set totalCount to serverTotalCount on tab 0' , ( ) => {
312+ ; ( component as any ) . serverTotalCount = 42
313+ component . onTabChange ( 0 )
314+ expect ( component . totalCount ( ) ) . toBe ( 42 )
315+ } )
316+
317+ it ( 'should set totalCount to filtered length on tab 1' , ( ) => {
318+ component . onTabChange ( 1 )
319+ expect ( component . totalCount ( ) ) . toBe ( 1 )
320+ } )
321+
322+ it ( 'should set totalCount to filtered length on tab 2' , ( ) => {
323+ component . onTabChange ( 2 )
324+ expect ( component . totalCount ( ) ) . toBe ( 1 )
325+ } )
326+ } )
327+
328+ describe ( 'isNoData' , ( ) => {
329+ it ( 'should return false when allDevicesData has entries regardless of totalCount' , ( ) => {
330+ component . allDevicesData = [ device01 ]
331+ component . isLoading . set ( false )
332+ component . totalCount . set ( 0 ) // filtered tab has 0 — should not trigger no-data
333+ expect ( component . isNoData ( ) ) . toBeFalse ( )
334+ } )
335+
336+ it ( 'should return true only when allDevicesData is empty and not loading' , ( ) => {
337+ component . allDevicesData = [ ]
338+ component . isLoading . set ( false )
339+ expect ( component . isNoData ( ) ) . toBeTrue ( )
340+ } )
341+
342+ it ( 'should return false when loading even if allDevicesData is empty' , ( ) => {
343+ component . allDevicesData = [ ]
344+ component . isLoading . set ( true )
345+ expect ( component . isNoData ( ) ) . toBeFalse ( )
346+ } )
347+ } )
253348} )
0 commit comments