diff --git a/awx/ui/src/screens/TopologyView/utils/helpers__RTL.test.js b/awx/ui/src/screens/TopologyView/utils/helpers__RTL.test.js index 4b0ec8cd40..38a0c55931 100644 --- a/awx/ui/src/screens/TopologyView/utils/helpers__RTL.test.js +++ b/awx/ui/src/screens/TopologyView/utils/helpers__RTL.test.js @@ -3,11 +3,16 @@ import { renderLabelText, renderNodeType, renderNodeIcon, + renderLabelIcons, + renderIconPosition, + renderLinkState, redirectToDetailsPage, getHeight, getWidth, } from './helpers'; +import { ICONS } from '../constants'; + describe('renderStateColor', () => { test('returns correct node state color', () => { expect(renderStateColor('ready')).toBe('#3E8635'); @@ -26,13 +31,13 @@ describe('renderNodeType', () => { test('returns correct node type', () => { expect(renderNodeType('control')).toBe('C'); }); - test('returns empty string if state is not found', () => { + test('returns empty string if type is not found', () => { expect(renderNodeType('foo')).toBe(''); }); - test('returns empty string if state is null', () => { + test('returns empty string if type is null', () => { expect(renderNodeType(null)).toBe(''); }); - test('returns empty string if state is zero/integer', () => { + test('returns empty string if type is zero/integer', () => { expect(renderNodeType(0)).toBe(''); }); }); @@ -43,13 +48,58 @@ describe('renderNodeIcon', () => { test('returns empty string if state is not found', () => { expect(renderNodeIcon('foo')).toBe(''); }); - test('returns empty string if state is null', () => { + test('returns false if state is null', () => { expect(renderNodeIcon(null)).toBe(false); }); - test('returns empty string if state is zero/integer', () => { + test('returns false if state is zero/integer', () => { expect(renderNodeIcon(0)).toBe(false); }); }); +describe('renderLabelIcons', () => { + test('returns correct label icon', () => { + expect(renderLabelIcons('ready')).toBe(ICONS['checkmark']); + }); + test('returns empty string if state is not found', () => { + expect(renderLabelIcons('foo')).toBe(''); + }); + test('returns false if state is null', () => { + expect(renderLabelIcons(null)).toBe(false); + }); + test('returns false if state is zero/integer', () => { + expect(renderLabelIcons(0)).toBe(false); + }); +}); +describe('renderIconPosition', () => { + const bbox = { x: 400, y: 400, width: 10, height: 20 }; + test('returns correct label icon', () => { + expect(renderIconPosition('ready', bbox)).toBe( + `translate(${bbox.x - 15}, ${bbox.y + 3}), scale(0.02)` + ); + }); + test('returns empty string if state is not found', () => { + expect(renderIconPosition('foo', bbox)).toBe(''); + }); + test('returns false if state is null', () => { + expect(renderIconPosition(null)).toBe(false); + }); + test('returns false if state is zero/integer', () => { + expect(renderIconPosition(0)).toBe(false); + }); +}); +describe('renderLinkState', () => { + test('returns correct link state', () => { + expect(renderLinkState('adding')).toBe(3); + }); + test('returns null string if state is not found', () => { + expect(renderLinkState('foo')).toBe(null); + }); + test('returns null if state is null', () => { + expect(renderLinkState(null)).toBe(null); + }); + test('returns null if state is zero/integer', () => { + expect(renderLinkState(0)).toBe(null); + }); +}); describe('getWidth', () => { test('returns 700 if selector is null', () => { expect(getWidth(null)).toBe(700);