Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/containers/Node/Node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ export function Node() {
if (isDiskPagesAvailable) {
actulaNodeTabs = actulaNodeTabs.filter((el) => el.id !== 'structure');
}
// Filter out threads tab if there's no thread data in the API response
if (!node?.Threads || node.Threads.length === 0) {
actulaNodeTabs = actulaNodeTabs.filter((el) => el.id !== 'threads');
}

const actualActiveTab =
actulaNodeTabs.find(({id}) => id === activeTabId) ?? actulaNodeTabs[0];

return {activeTab: actualActiveTab, nodeTabs: actulaNodeTabs};
}, [isStorageNode, isDiskPagesAvailable, activeTabId]);
}, [isStorageNode, isDiskPagesAvailable, activeTabId, node?.Threads]);

const tenantName = node?.Tenants?.[0] || tenantNameFromQuery?.toString();

Expand Down
84 changes: 84 additions & 0 deletions src/containers/Node/__tests__/Node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {NODE_TABS} from '../NodePages';

describe('Node tab filtering logic', () => {
it('should filter out threads tab when no thread data is provided', () => {
// Simulate the filtering logic that happens in the Node component
const isStorageNode = false;
const isDiskPagesAvailable = false;
const node: {Threads?: any[]} = {
// No Threads property
};

let actualNodeTabs = isStorageNode
? NODE_TABS
: NODE_TABS.filter((el) => el.id !== 'storage');

if (isDiskPagesAvailable) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
}

// Filter out threads tab if there's no thread data in the API response
if (!node.Threads || node.Threads.length === 0) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
}

// Should not include threads tab
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false);
// Should include other tabs
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
});

it('should include threads tab when thread data is provided', () => {
// Simulate the filtering logic that happens in the Node component
const isStorageNode = false;
const isDiskPagesAvailable = false;
const node: {Threads?: any[]} = {
Threads: [{Name: 'TestPool', Threads: 4}],
};

let actualNodeTabs = isStorageNode
? NODE_TABS
: NODE_TABS.filter((el) => el.id !== 'storage');

if (isDiskPagesAvailable) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
}

// Filter out threads tab if there's no thread data in the API response
if (!node.Threads || node.Threads.length === 0) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
}

// Should include threads tab
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(true);
// Should include other tabs
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
});

it('should filter out threads tab when thread data is empty array', () => {
// Simulate the filtering logic that happens in the Node component
const isStorageNode = false;
const isDiskPagesAvailable = false;
const node: {Threads?: any[]} = {
Threads: [], // Empty array
};

let actualNodeTabs = isStorageNode
? NODE_TABS
: NODE_TABS.filter((el) => el.id !== 'storage');

if (isDiskPagesAvailable) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'structure');
}

// Filter out threads tab if there's no thread data in the API response
if (!node.Threads || node.Threads.length === 0) {
actualNodeTabs = actualNodeTabs.filter((el) => el.id !== 'threads');
}

// Should not include threads tab
expect(actualNodeTabs.some((tab) => tab.id === 'threads')).toBe(false);
// Should include other tabs
expect(actualNodeTabs.some((tab) => tab.id === 'tablets')).toBe(true);
});
});