| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| import { ContactsListComponent } from '@pages/contacts/contacts-list/contacts-list.component'; |
| import { Globals } from '@shared/constants/globals'; |
| import { ModifiedContacts } from '@shared/models/modifiedContacts.model'; |
| |
| describe('ContactsListComponent', () => { |
| let component: ContactsListComponent; |
| let contactsSandbox: any = {}; |
| let userModuleAssignmentSandbox: any = {}; |
| let router: any = {}; |
| |
| beforeEach(() => { |
| router = { navigateByUrl() {}, navigate() {} } as any; |
| component = new ContactsListComponent(contactsSandbox, userModuleAssignmentSandbox, router); |
| }); |
| |
| it('should create', () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it('should define gridOptions onInit', () => { |
| component.ngOnInit(); |
| |
| expect(component.gridOptions).toBeDefined(); |
| expect(component.gridOptions.context).toBeDefined(); |
| }); |
| |
| it('should _navigateToDetails if BusEvents is edit ', () => { |
| const spy = spyOn(component as any, '_navigateToDetails'); |
| const event: any = { type: 'edit' }; |
| (component as any)._handleBusEvents(event); |
| |
| expect(spy).toHaveBeenCalled(); |
| }); |
| |
| it('should do nothing(TODO:) if BusEvents is delete ', () => { |
| const event: any = { type: 'delete' }; |
| (component as any)._handleBusEvents(event); |
| |
| expect().nothing(); |
| }); |
| |
| it('should do nothing if BusEvents is undefined ', () => { |
| const event: any = { type: undefined }; |
| (component as any)._handleBusEvents(event); |
| |
| expect().nothing(); |
| }); |
| |
| it('should navigate to the right url', () => { |
| const spy = spyOn(router, 'navigate'); |
| const url = '/test'; |
| component.navigateTo(url); |
| |
| expect(spy).toHaveBeenCalledWith([url]); |
| }); |
| |
| it('should navigate to the external person details page', () => { |
| const event: any = { |
| data: { |
| contactType: Globals.CONTACT_TYPE_ID.EXTERNAL_PERSON, |
| uuid: 'uuid', |
| }, |
| }; |
| const spy = spyOn(router, 'navigate'); |
| (component as any)._navigateToDetails(event); |
| const url = `/${Globals.PATH.PERSONS}/${Globals.PATH.EXTERNAL}/`; |
| |
| expect(spy).toHaveBeenCalledWith([url, event.data.uuid]); |
| }); |
| |
| it('should navigate to the internal person details page', () => { |
| const event: any = { |
| data: { |
| contactType: Globals.CONTACT_TYPE_ID.INTERNAL_PERSON, |
| uuid: 'uuid', |
| }, |
| }; |
| const spy = spyOn(router, 'navigate'); |
| (component as any)._navigateToDetails(event); |
| const url = `/${Globals.PATH.PERSONS}/${Globals.PATH.INTERNAL}/`; |
| |
| expect(spy).toHaveBeenCalledWith([url, event.data.uuid]); |
| }); |
| |
| it('should navigate to the contact person details page', () => { |
| const event: any = { |
| data: { |
| contactType: Globals.CONTACT_TYPE_ID.CONTACT_PERSON, |
| uuid: 'uuid', |
| companyId: 'x', |
| }, |
| }; |
| const spy = spyOn(router, 'navigate'); |
| (component as any)._navigateToDetails(event); |
| const url = `/${Globals.PATH.COMPANY}/${event.data.companyId}/${Globals.PATH.CONTACT_PERSON}/`; |
| |
| expect(spy).toHaveBeenCalledWith([url, event.data.uuid]); |
| }); |
| |
| it('should navigate to the company details page', () => { |
| const event: any = { |
| data: { |
| contactType: Globals.CONTACT_TYPE_ID.COMPANY, |
| uuid: 'uuid', |
| }, |
| }; |
| const spy = spyOn(router, 'navigate'); |
| (component as any)._navigateToDetails(event); |
| const url = `/${Globals.PATH.COMPANY}/`; |
| |
| expect(spy).toHaveBeenCalledWith([url, event.data.uuid]); |
| }); |
| |
| it('should navigate to the overview if contactType undefined', () => { |
| const event: any = { |
| data: { |
| contactType: undefined, |
| uuid: 'uuid', |
| }, |
| }; |
| const spy = spyOn(router, 'navigate'); |
| (component as any)._navigateToDetails(event); |
| const url = '/overview'; |
| |
| expect(spy).toHaveBeenCalledWith([url]); |
| }); |
| |
| it('checks if function searchContacts() would be called and works', () => { |
| const modificationContacts = new ModifiedContacts(); |
| component.modifiedContacts = modificationContacts; |
| const event: any = { type: 'click' }; |
| component.searchContacts(event); |
| expect(component.modifiedContacts).not.toEqual(modificationContacts); |
| }); |
| |
| it('checks if function sortContacts() works', () => { |
| const setModifiedContactsSortSpy = spyOn(component as any, '_setModifiedContactsSort'); |
| component.sortContacts(); |
| expect(setModifiedContactsSortSpy).toHaveBeenCalledTimes(1); |
| }); |
| |
| it('checks if function setModifiedContactsSearchText() works', () => { |
| component.setModifiedContactsSearchText('big'); |
| expect(component.modifiedContacts.searchText).toBe('big'); |
| }); |
| |
| it('checks if function setModifiedContactsContactTypeId() works', () => { |
| component.setModifiedContactsContactTypeId('I_P'); |
| expect(component.modifiedContacts.contactTypeId).toBe('I_P'); |
| }); |
| |
| it('checks if function setSortingContactType() works', () => { |
| component.setSortingContactType('name'); |
| expect((component as any)._sortingContactType).toBe('name'); |
| }); |
| |
| it('checks if function setSortingOrder() works', () => { |
| component.setSortingOrder('asc'); |
| expect((component as any)._sortingOrder).toBe('asc'); |
| }); |
| |
| it('checks if function _setModifiedContactsSort() works', () => { |
| component.setSortingContactType('name'); |
| (component as any)._setModifiedContactsSort(); |
| expect(component.modifiedContacts.sort).toBe('name,asc'); |
| |
| (component as any)._sortingOrder = null; |
| (component as any)._setModifiedContactsSort(); |
| expect(component.modifiedContacts.sort).toBe(null); |
| |
| (component as any)._sortingContactType = null; |
| (component as any)._setModifiedContactsSort(); |
| expect(component.modifiedContacts.sort).toBe(null); |
| }); |
| |
| it('checks if function setModifiedContactsExpiryDateFilter() works', () => { |
| expect(component.modifiedContacts.expiringDataInPast).toBeFalsy(); |
| component.setModifiedContactsExpiryDateFilter(); |
| expect(component.modifiedContacts.expiringDataInPast).toBeTruthy(); |
| }); |
| |
| it('checks if function setModifiedContactsDeletionLockExceedFilter() works', () => { |
| expect(component.modifiedContacts.deletionLockExceeded).toBeFalsy(); |
| component.setModifiedContactsDeletionLockExceedFilter(); |
| expect(component.modifiedContacts.deletionLockExceeded).toBeTruthy(); |
| }); |
| |
| it('checks if function setModifiedContactsModuleAssignmentFilter() works', () => { |
| let moduleName = '-1'; |
| component.setModifiedContactsModuleAssignmentFilter(moduleName); |
| expect(component.modifiedContacts.moduleName).toBe(null); |
| expect(component.modifiedContacts.withoutAssignedModule).toBeTruthy(); |
| moduleName = ''; |
| component.setModifiedContactsModuleAssignmentFilter(moduleName); |
| expect(component.modifiedContacts.moduleName).toBe(null); |
| expect(component.modifiedContacts.withoutAssignedModule).toBeFalsy(); |
| moduleName = 'Betriebstagebuch'; |
| component.setModifiedContactsModuleAssignmentFilter(moduleName); |
| expect(component.modifiedContacts.moduleName).toBe(moduleName); |
| expect(component.modifiedContacts.withoutAssignedModule).toBeFalsy(); |
| }); |
| }); |