import * as SL from './SearchLayout'; import { IField } from './Field'; describe('SearchLayoutForEntity', () => { const displayName = 'Test Name'; const devName = 'Test_Name'; const fields: IField[] = [ { FieldName: 'aField', DisplayName: 'A Field', Value: 'A Value' } ]; test('Constructor, Setters, Getters', () => { const searchLayoutForEntity = new SL.SearchLayoutForEntity('A', 'B'); expect(searchLayoutForEntity.getDisplayName()).toEqual('A'); expect(searchLayoutForEntity.getDevName()).toEqual('B'); searchLayoutForEntity.setDisplayName(displayName); expect(searchLayoutForEntity.getDisplayName()).toEqual(displayName); searchLayoutForEntity.setDevName(devName); expect(searchLayoutForEntity.getDevName()).toEqual(devName); searchLayoutForEntity.setDisplayFields(fields); expect(searchLayoutForEntity.getDisplayFields()).toEqual(fields); searchLayoutForEntity.setPhoneFields(fields); expect(searchLayoutForEntity.getPhoneFields()).toEqual(fields); searchLayoutForEntity.setEmailFields(fields); expect(searchLayoutForEntity.getEmailFields()).toEqual(fields); searchLayoutForEntity.setSocialFields(fields); expect(searchLayoutForEntity.getSocialFields()).toEqual(fields); searchLayoutForEntity.setNameFields(fields); expect(searchLayoutForEntity.getNameFields()).toEqual(fields); }); test('Constructor complete', () => { const searchLayoutForEntity = new SL.SearchLayoutForEntity(displayName, devName, fields, fields, fields, fields, fields); expect(searchLayoutForEntity.getDisplayName()).toEqual(displayName); expect(searchLayoutForEntity.getDevName()).toEqual(devName); expect(searchLayoutForEntity.getDisplayFields()).toEqual(fields); expect(searchLayoutForEntity.getPhoneFields()).toEqual(fields); expect(searchLayoutForEntity.getEmailFields()).toEqual(fields); expect(searchLayoutForEntity.getSocialFields()).toEqual(fields); expect(searchLayoutForEntity.getNameFields()).toEqual(fields); }); test('fromJSON', () => { const searchLayoutForEntity = new SL.SearchLayoutForEntity(displayName, devName, fields, fields, fields, fields, fields); const searchLayoutForEntityJSON = JSON.parse(JSON.stringify(searchLayoutForEntity)); const searchLayoutForEntity2 = SL.SearchLayoutForEntity.fromJSON(searchLayoutForEntityJSON); expect(searchLayoutForEntity2).toEqual(searchLayoutForEntity); }); }); describe('SearchLayout', () => { const fields: IField[] = [ { FieldName: 'aField', DisplayName: 'A Field', Value: 'A Value' } ]; const searchLayoutForEntityArray = [new SL.SearchLayoutForEntity('DisplayName', 'DevName', fields, fields, fields, fields, fields)]; test('Constructor, Getters, Setters, fromJSON', () => { const searchLayout = new SL.SearchLayout(true, searchLayoutForEntityArray.concat(searchLayoutForEntityArray)); expect(searchLayout.getOpenInNewWindow()).toBe(true); expect(searchLayout.getDefault()).toEqual(searchLayoutForEntityArray.concat(searchLayoutForEntityArray)); searchLayout.setOpenInNewWindow(false); expect(searchLayout.getOpenInNewWindow()).toBe(false); searchLayout.setDefault(searchLayoutForEntityArray); expect(searchLayout.getDefault()).toEqual(searchLayoutForEntityArray); searchLayout.setInbound(searchLayoutForEntityArray); expect(searchLayout.getInbound()).toEqual(searchLayoutForEntityArray); searchLayout.setInternal(searchLayoutForEntityArray); expect(searchLayout.getInternal()).toEqual(searchLayoutForEntityArray); searchLayout.setOutbound(searchLayoutForEntityArray); expect(searchLayout.getOutbound()).toEqual(searchLayoutForEntityArray); const singleMatch = { type: SL.SINGLE_MATCH_POP_TYPES.PopToUrl, data: 'http://example.com/single' }; expect(searchLayout.getSingleMatch()).toEqual({ type: SL.SINGLE_MATCH_POP_TYPES.NoPop }); searchLayout.setSingleMatch(singleMatch); expect(searchLayout.getSingleMatch()).toEqual(singleMatch); const multiMatch = { type: SL.MULTI_MATCH_POP_TYPES.PopToUrl, data: 'http://example.com/multi' }; expect(searchLayout.getMultiMatch()).toEqual({ type: SL.MULTI_MATCH_POP_TYPES.NoPop }); searchLayout.setMultiMatch(multiMatch); expect(searchLayout.getMultiMatch()).toEqual(multiMatch); const noMatch = { type: SL.NO_MATCH_POP_TYPES.PopToUrl, data: 'http://example.com/no' }; expect(searchLayout.getNoMatch()).toEqual({ type: SL.NO_MATCH_POP_TYPES.NoPop }); searchLayout.setNoMatch(noMatch); expect(searchLayout.getNoMatch()).toEqual(noMatch); const searchLayoutJSON = JSON.parse(JSON.stringify(searchLayout)); const searchLayoutFromJSON = SL.SearchLayout.fromJSON(searchLayoutJSON); expect(searchLayoutFromJSON).toEqual(searchLayout); }); }); describe('SearchLayouts', () => { const fields: IField[] = [ { FieldName: 'aField', DisplayName: 'A Field', Value: 'A Value' } ]; const searchLayoutForEntityArray = [new SL.SearchLayoutForEntity('DisplayName', 'DevName', fields, fields, fields, fields, fields)]; const searchLayout = new SL.SearchLayout(true, searchLayoutForEntityArray); test('Constructor', () => { const layouts = { Layout1: searchLayout, Layout2: searchLayout }; let searchLayouts = new SL.SearchLayouts(); expect(searchLayouts.getAllLayouts()).toEqual({}); searchLayouts = new SL.SearchLayouts(layouts); expect(searchLayouts.getAllLayouts()).toEqual(layouts); }); test('setLayout, getLayout', () => { const searchLayouts = new SL.SearchLayouts(); searchLayouts.setLayout([], searchLayout); expect(searchLayouts.getAllLayouts()).toEqual({}); searchLayouts.setLayout(['Layout0'], searchLayout); expect(searchLayouts.getLayout('Layout0')).toEqual(searchLayout); searchLayouts.setLayout(['Layout1', 'Layout2'], searchLayout); expect(searchLayouts.getLayout('Layout1')).toEqual(searchLayout); expect(searchLayouts.getLayout('Layout2')).toEqual(searchLayout); expect(searchLayouts.getLayout('Layout4')).toEqual(undefined); }); test('toJSON, fromJSON', () => { const layouts = { Layout1: searchLayout, Layout2: searchLayout }; const searchLayouts = new SL.SearchLayouts(layouts); expect(searchLayouts.toJSON()).toEqual(layouts); expect(SL.SearchLayouts.fromJSON(searchLayouts.toJSON())).toEqual(searchLayouts); }); });