From 75597ac2b51ba62bee33f72a7b55a549cf43a16f Mon Sep 17 00:00:00 2001 From: "Arul.Nambi" Date: Wed, 11 Jul 2018 14:19:41 -0400 Subject: Refactoring test scripts Moving the test scripts under one folder and restucting them so that the clutter can be avoided in the src folder. Issue-ID: AAI-1371 Change-Id: I41b34acbe79a7a3409f2990f11492614f7ef9c5a Signed-off-by: Arul.Nambi --- test/tierSupport/SelectedNodeDetails.test.js | 141 +++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/tierSupport/SelectedNodeDetails.test.js (limited to 'test/tierSupport/SelectedNodeDetails.test.js') diff --git a/test/tierSupport/SelectedNodeDetails.test.js b/test/tierSupport/SelectedNodeDetails.test.js new file mode 100644 index 0000000..5f97626 --- /dev/null +++ b/test/tierSupport/SelectedNodeDetails.test.js @@ -0,0 +1,141 @@ +import React from 'react'; +import { shallow, mount } from 'enzyme'; +import {Provider} from 'react-redux' +import configureStore from 'redux-mock-store'; +import Table from 'react-bootstrap/lib/Table'; + +import ConnectedSelectedNodeDetails, { SelectedNodeDetails } from 'app/tierSupport/selectedNodeDetails/SelectedNodeDetails.jsx'; +import { SELECTED_NODE_TABLE_COLUMN_NAMES } from 'app/tierSupport/selectedNodeDetails/SelectedNodeDetailsConstants.js'; +import LaunchInContext from 'app/tierSupport/launchExternalResource/LaunchExternalResource.jsx'; + +describe('SelectedNodeDetails - Shallow render of component', () => { + let wrapper; + const nodeTypeProp = 'VNF'; + const uidProp = 'SomeValidUIDName'; + const nodeDataProp = { + 'interface-role': 'MPLS', + 'in-maint': 'false', + 'interface-type': 'WAN', + 'port-description': 'MPLS port on 10_NSG16_location4', + 'resource-version': '123456789', + 'interface-name': '10_port1_location4', + 'uri': 'network/pnfs/pnf/10_NSG14_location4/p-interfaces/p-interface/10_port1_location4' + }; + + beforeEach( () => { + wrapper = shallow( + ); + }) + + it('Render basic component', () => { + expect(wrapper.length).toEqual(1); + }); + + it('Verify node type is displayed as a header', () => { + expect(wrapper.contains(

{nodeTypeProp}

)).toBe(true); + expect(wrapper.find('h2')).toHaveLength(1); + }); + + it('Verify uid is displayed', () => { + expect(wrapper.contains({uidProp} )).toBe(true); + }); + + it('Verify node data table is displayed', () => { + // verify table has a row for each node data prop plus one row for the column headers + expect(wrapper.find(Table)).toHaveLength(1); + expect(wrapper.find(Table).props().bsClass).toEqual('ts-selected-node-table'); + expect(wrapper.find(Table).children()).toHaveLength(2); // thead and tbody + + // validate the table header content + expect(wrapper.find('thead')).toHaveLength(1); + let cellClassName; + for (let index = 1; index <= SELECTED_NODE_TABLE_COLUMN_NAMES.length; index++) { + cellClassName = (index % 2 ? 'left-column-cell' : 'right-column-cell'); + expect(wrapper.contains( + {SELECTED_NODE_TABLE_COLUMN_NAMES[index-1]} + )).toBe(true); + } + + // validate the table body content + expect(wrapper.find('tbody')).toHaveLength(1); + expect(wrapper.find('tbody').children()).toHaveLength(7); // 1 row for each of the 7 properties + for (let prop in nodeDataProp) { + expect(wrapper.contains( + {prop} + )).toBe(true); + expect(wrapper.contains( + {nodeDataProp[prop]} + )).toBe(true); + } + }); +}) + +describe('SelectedNodeDetails - Shallow render of component with no node data', () => { + let wrapper; + const nodeTypeProp = 'VNF'; + const uidProp = 'SomeValidUIDName'; + const nodeDataProp = {}; + + beforeEach( () => { + wrapper = shallow( + ); + }) + + it('Render basic component', () => { + expect(wrapper.length).toEqual(1); + }); + + it('Verify node data table is hidden', () => { + // verify table is hidden + expect(wrapper.find(Table)).toHaveLength(1); + expect(wrapper.find(Table).props().bsClass).toEqual('hidden'); + }); +}) + +describe('SelectedNodeDetails - Render React Component (wrapped in )', () => { + const initialState = { + tierSupport: { + launchExternalResourceReducer: { + externalResourcePayload: {} + }, + selectedNodeDetails: { + nodeType: 'VNF', + uid: 'AAI/CLYMR/000509/SD_WAN', + nodeData: { + 'interface-role': 'MPLS', + 'in-maint': 'false', + 'interface-type': 'WAN', + 'port-description': 'MPLS port on 10_NSG16_location4', + 'resource-version': '123456789', + 'interface-name': '10_port1_location4', + 'uri': 'network/pnfs/pnf/10_NSG14_location4/p-interfaces/p-interface/10_port1_location4' + } + } + } + }; + const mockStore = configureStore(); + let store, wrapper; + + beforeEach( () => { + store = mockStore(initialState); + wrapper = mount(); + }) + + it('Render the connected component', () => { + expect(wrapper.find(ConnectedSelectedNodeDetails).length).toEqual(1); + }); + + it('Validate props from store', () => { + expect(wrapper.find(SelectedNodeDetails).props().uid).toEqual(initialState.tierSupport.selectedNodeDetails.uid); + expect(wrapper.find(SelectedNodeDetails).props().nodeType).toEqual(initialState.tierSupport.selectedNodeDetails.nodeType); + expect(wrapper.find(SelectedNodeDetails).props().nodeData).toEqual(initialState.tierSupport.selectedNodeDetails.nodeData); + }); +}) -- cgit 1.2.3-korg