|
| 1 | +import {NODE_TABS} from '../NodePages'; |
| 2 | + |
| 3 | +describe('Node tab filtering logic', () => { |
| 4 | + it('should filter out threads tab when no thread data is provided', () => { |
| 5 | + // Simulate the filtering logic that happens in the Node component |
| 6 | + const isStorageNode = false; |
| 7 | + const isDiskPagesAvailable = false; |
| 8 | + const node: {Threads?: any[]} = { |
| 9 | + // No Threads property |
| 10 | + }; |
| 11 | + |
| 12 | + let actualNodeTabs = isStorageNode |
| 13 | + ? NODE_TABS |
| 14 | + : NODE_TABS.filter((el) => el.id !== 'storage'); |
| 15 | + |
| 16 | + if (isDiskPagesAvailable) { |
| 17 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure'); |
| 18 | + } |
| 19 | + |
| 20 | + // Filter out threads tab if there's no thread data in the API response |
| 21 | + if (!node.Threads || node.Threads.length === 0) { |
| 22 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads'); |
| 23 | + } |
| 24 | + |
| 25 | + // Should not include threads tab |
| 26 | + expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false); |
| 27 | + // Should include other tabs |
| 28 | + expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should include threads tab when thread data is provided', () => { |
| 32 | + // Simulate the filtering logic that happens in the Node component |
| 33 | + const isStorageNode = false; |
| 34 | + const isDiskPagesAvailable = false; |
| 35 | + const node: {Threads?: any[]} = { |
| 36 | + Threads: [{Name: 'TestPool', Threads: 4}], |
| 37 | + }; |
| 38 | + |
| 39 | + let actualNodeTabs = isStorageNode |
| 40 | + ? NODE_TABS |
| 41 | + : NODE_TABS.filter((el) => el.id !== 'storage'); |
| 42 | + |
| 43 | + if (isDiskPagesAvailable) { |
| 44 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure'); |
| 45 | + } |
| 46 | + |
| 47 | + // Filter out threads tab if there's no thread data in the API response |
| 48 | + if (!node.Threads || node.Threads.length === 0) { |
| 49 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads'); |
| 50 | + } |
| 51 | + |
| 52 | + // Should include threads tab |
| 53 | + expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(true); |
| 54 | + // Should include other tabs |
| 55 | + expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should filter out threads tab when thread data is empty array', () => { |
| 59 | + // Simulate the filtering logic that happens in the Node component |
| 60 | + const isStorageNode = false; |
| 61 | + const isDiskPagesAvailable = false; |
| 62 | + const node: {Threads?: any[]} = { |
| 63 | + Threads: [], // Empty array |
| 64 | + }; |
| 65 | + |
| 66 | + let actualNodeTabs = isStorageNode |
| 67 | + ? NODE_TABS |
| 68 | + : NODE_TABS.filter((el) => el.id !== 'storage'); |
| 69 | + |
| 70 | + if (isDiskPagesAvailable) { |
| 71 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure'); |
| 72 | + } |
| 73 | + |
| 74 | + // Filter out threads tab if there's no thread data in the API response |
| 75 | + if (!node.Threads || node.Threads.length === 0) { |
| 76 | + actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads'); |
| 77 | + } |
| 78 | + |
| 79 | + // Should not include threads tab |
| 80 | + expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false); |
| 81 | + // Should include other tabs |
| 82 | + expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true); |
| 83 | + }); |
| 84 | +}); |
0 commit comments