diff --git a/src/app/access-control/group-registry/group-form/members-list/members-list.component.spec.ts b/src/app/access-control/group-registry/group-form/members-list/members-list.component.spec.ts index 8d0ddf0a85..4cf018445c 100644 --- a/src/app/access-control/group-registry/group-form/members-list/members-list.component.spec.ts +++ b/src/app/access-control/group-registry/group-form/members-list/members-list.component.spec.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; +import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, fakeAsync, flush, inject, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule, By } from '@angular/platform-browser'; @@ -37,10 +37,10 @@ describe('MembersListComponent', () => { let ePersonDataServiceStub: any; let groupsDataServiceStub: any; let activeGroup; - let allEPersons; - let allGroups; - let epersonMembers; - let subgroupMembers; + let allEPersons: EPerson[]; + let allGroups: Group[]; + let epersonMembers: EPerson[]; + let subgroupMembers: Group[]; let paginationService; beforeEach(waitForAsync(() => { @@ -53,7 +53,7 @@ describe('MembersListComponent', () => { activeGroup: activeGroup, epersonMembers: epersonMembers, subgroupMembers: subgroupMembers, - findListByHref(href: string): Observable>> { + findListByHref(_href: string): Observable>> { return createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), groupsDataServiceStub.getEPersonMembers())); }, searchByScope(scope: string, query: string): Observable>> { @@ -147,6 +147,7 @@ describe('MembersListComponent', () => { }); afterEach(fakeAsync(() => { fixture.destroy(); + fixture.debugElement.nativeElement.remove(); flush(); component = null; })); @@ -167,12 +168,19 @@ describe('MembersListComponent', () => { describe('search', () => { describe('when searching without query', () => { - let epersonsFound; + let epersonsFound: DebugElement[]; beforeEach(fakeAsync(() => { + spyOn(component, 'isMemberOfGroup').and.callFake((ePerson: EPerson) => { + return observableOf(activeGroup.epersons.includes(ePerson)); + }); component.search({ scope: 'metadata', query: '' }); tick(); fixture.detectChanges(); epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr')); + // Stop using the fake spy function (because otherwise the clicking on the buttons will not change anything + // because they don't change the value of activeGroup.epersons) + jasmine.getEnv().allowRespy(true); + spyOn(component, 'isMemberOfGroup').and.callThrough(); })); it('should display all epersons', () => { @@ -181,62 +189,56 @@ describe('MembersListComponent', () => { describe('if eperson is already a eperson', () => { it('should have delete button, else it should have add button', () => { - activeGroup.epersons.map((eperson: EPerson) => { - epersonsFound.map((foundEPersonRowElement) => { - if (foundEPersonRowElement.debugElement !== undefined) { - const epersonId = foundEPersonRowElement.debugElement.query(By.css('td:first-child')); - const addButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-plus')); - const deleteButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-trash-alt')); - if (epersonId.nativeElement.textContent === eperson.id) { - expect(addButton).toBeUndefined(); - expect(deleteButton).toBeDefined(); - } else { - expect(deleteButton).toBeUndefined(); - expect(addButton).toBeDefined(); - } - } - }); + const memberIds: string[] = activeGroup.epersons.map((ePerson: EPerson) => ePerson.id); + epersonsFound.map((foundEPersonRowElement: DebugElement) => { + const epersonId: DebugElement = foundEPersonRowElement.query(By.css('td:first-child')); + const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus')); + const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt')); + if (memberIds.includes(epersonId.nativeElement.textContent)) { + expect(addButton).toBeNull(); + expect(deleteButton).not.toBeNull(); + } else { + expect(deleteButton).toBeNull(); + expect(addButton).not.toBeNull(); + } }); }); }); describe('if first add button is pressed', () => { beforeEach(fakeAsync(() => { - const addButton = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-plus')); + const addButton: DebugElement = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-plus')); addButton.nativeElement.click(); tick(); fixture.detectChanges(); })); - it('all groups in search member of selected group', () => { + it('then all the ePersons are member of the active group', () => { epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr')); expect(epersonsFound.length).toEqual(2); - epersonsFound.map((foundEPersonRowElement) => { - if (foundEPersonRowElement.debugElement !== undefined) { - const addButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-plus')); - const deleteButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-trash-alt')); - expect(addButton).toBeUndefined(); - expect(deleteButton).toBeDefined(); - } + epersonsFound.map((foundEPersonRowElement: DebugElement) => { + const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus')); + const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt')); + expect(addButton).toBeNull(); + expect(deleteButton).not.toBeNull(); }); }); }); describe('if first delete button is pressed', () => { beforeEach(fakeAsync(() => { - const addButton = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-trash-alt')); - addButton.nativeElement.click(); + const deleteButton: DebugElement = fixture.debugElement.query(By.css('#epersonsSearch tbody .fa-trash-alt')); + deleteButton.nativeElement.click(); tick(); fixture.detectChanges(); })); - it('first eperson in search delete button, because now member', () => { + it('then no ePerson is member of the active group', () => { epersonsFound = fixture.debugElement.queryAll(By.css('#epersonsSearch tbody tr')); - epersonsFound.map((foundEPersonRowElement) => { - if (foundEPersonRowElement.debugElement !== undefined) { - const addButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-plus')); - const deleteButton = foundEPersonRowElement.debugElement.query(By.css('td:last-child .fa-trash-alt')); - expect(deleteButton).toBeUndefined(); - expect(addButton).toBeDefined(); - } + expect(epersonsFound.length).toEqual(2); + epersonsFound.map((foundEPersonRowElement: DebugElement) => { + const addButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-plus')); + const deleteButton: DebugElement = foundEPersonRowElement.query(By.css('td:last-child .fa-trash-alt')); + expect(deleteButton).toBeNull(); + expect(addButton).not.toBeNull(); }); }); }); diff --git a/src/app/access-control/group-registry/group-form/members-list/members-list.component.ts b/src/app/access-control/group-registry/group-form/members-list/members-list.component.ts index 169d009d63..c569522be4 100644 --- a/src/app/access-control/group-registry/group-form/members-list/members-list.component.ts +++ b/src/app/access-control/group-registry/group-form/members-list/members-list.component.ts @@ -205,6 +205,7 @@ export class MembersListComponent implements OnInit, OnDestroy { * @param ePerson EPerson we want to delete as member from group that is currently being edited */ deleteMemberFromGroup(ePerson: EpersonDtoModel) { + ePerson.memberOfGroup = false; this.groupDataService.getActiveGroup().pipe(take(1)).subscribe((activeGroup: Group) => { if (activeGroup != null) { const response = this.groupDataService.deleteMemberFromGroup(activeGroup, ePerson.eperson); diff --git a/src/app/access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts b/src/app/access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts index 1ca6c88c5f..ff0fd121af 100644 --- a/src/app/access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts +++ b/src/app/access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts @@ -1,14 +1,6 @@ import { CommonModule } from '@angular/common'; -import { NO_ERRORS_SCHEMA } from '@angular/core'; -import { - ComponentFixture, - fakeAsync, - flush, - inject, - TestBed, - tick, - waitForAsync -} from '@angular/core/testing'; +import { NO_ERRORS_SCHEMA, DebugElement } from '@angular/core'; +import { ComponentFixture, fakeAsync, flush, inject, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule, By } from '@angular/platform-browser'; import { Router } from '@angular/router'; @@ -46,8 +38,8 @@ describe('SubgroupsListComponent', () => { let ePersonDataServiceStub: any; let groupsDataServiceStub: any; let activeGroup; - let subgroups; - let allGroups; + let subgroups: Group[]; + let allGroups: Group[]; let routerStub; let paginationService; @@ -65,7 +57,7 @@ describe('SubgroupsListComponent', () => { getSubgroups(): Group { return this.activeGroup; }, - findListByHref(href: string): Observable>> { + findListByHref(_href: string): Observable>> { return this.subgroups$.pipe( map((currentGroups: Group[]) => { return createSuccessfulRemoteDataObject(buildPaginatedList(new PageInfo(), currentGroups)); @@ -133,6 +125,7 @@ describe('SubgroupsListComponent', () => { }); afterEach(fakeAsync(() => { fixture.destroy(); + fixture.debugElement.nativeElement.remove(); flush(); component = null; })); @@ -152,7 +145,7 @@ describe('SubgroupsListComponent', () => { }); describe('if first group delete button is pressed', () => { - let groupsFound; + let groupsFound: DebugElement[]; beforeEach(fakeAsync(() => { const addButton = fixture.debugElement.query(By.css('#subgroupsOfGroup tbody .deleteButton')); addButton.triggerEventHandler('click', { @@ -170,7 +163,7 @@ describe('SubgroupsListComponent', () => { describe('search', () => { describe('when searching with empty query', () => { - let groupsFound; + let groupsFound: DebugElement[]; beforeEach(fakeAsync(() => { component.search({ query: '' }); groupsFound = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr')); @@ -181,9 +174,9 @@ describe('SubgroupsListComponent', () => { groupsFound = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr')); expect(groupsFound.length).toEqual(2); groupsFound = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr')); - const groupIdsFound = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr td:first-child')); + const groupIdsFound: DebugElement[] = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr td:first-child')); allGroups.map((group: Group) => { - expect(groupIdsFound.find((foundEl) => { + expect(groupIdsFound.find((foundEl: DebugElement) => { return (foundEl.nativeElement.textContent.trim() === group.uuid); })).toBeTruthy(); }); @@ -195,30 +188,30 @@ describe('SubgroupsListComponent', () => { groupsFound = fixture.debugElement.queryAll(By.css('#groupsSearch tbody tr')); const getSubgroups = groupsDataServiceStub.getSubgroups().subgroups; if (getSubgroups !== undefined && getSubgroups.length > 0) { - groupsFound.map((foundGroupRowElement) => { - if (foundGroupRowElement.debugElement !== undefined) { - const addButton = foundGroupRowElement.debugElement.query(By.css('td:last-child .fa-plus')); - const deleteButton = foundGroupRowElement.debugElement.query(By.css('td:last-child .fa-trash-alt')); - expect(addButton).toBeUndefined(); - expect(deleteButton).toBeDefined(); + groupsFound.map((foundGroupRowElement: DebugElement) => { + const groupId: DebugElement = foundGroupRowElement.query(By.css('td:first-child')); + const addButton: DebugElement = foundGroupRowElement.query(By.css('td:last-child .fa-plus')); + const deleteButton: DebugElement = foundGroupRowElement.query(By.css('td:last-child .fa-trash-alt')); + expect(addButton).toBeNull(); + if (activeGroup.id === groupId.nativeElement.textContent) { + expect(deleteButton).toBeNull(); + } else { + expect(deleteButton).not.toBeNull(); } }); } else { - getSubgroups.map((group: Group) => { - groupsFound.map((foundGroupRowElement) => { - if (foundGroupRowElement.debugElement !== undefined) { - const groupId = foundGroupRowElement.debugElement.query(By.css('td:first-child')); - const addButton = foundGroupRowElement.debugElement.query(By.css('td:last-child .fa-plus')); - const deleteButton = foundGroupRowElement.debugElement.query(By.css('td:last-child .fa-trash-alt')); - if (groupId.nativeElement.textContent === group.id) { - expect(addButton).toBeUndefined(); - expect(deleteButton).toBeDefined(); - } else { - expect(deleteButton).toBeUndefined(); - expect(addButton).toBeDefined(); - } - } - }); + const subgroupIds: string[] = activeGroup.subgroups.map((group: Group) => group.id); + groupsFound.map((foundGroupRowElement: DebugElement) => { + const groupId: DebugElement = foundGroupRowElement.query(By.css('td:first-child')); + const addButton: DebugElement = foundGroupRowElement.query(By.css('td:last-child .fa-plus')); + const deleteButton: DebugElement = foundGroupRowElement.query(By.css('td:last-child .fa-trash-alt')); + if (subgroupIds.includes(groupId.nativeElement.textContent)) { + expect(addButton).toBeNull(); + expect(deleteButton).not.toBeNull(); + } else { + expect(deleteButton).toBeNull(); + expect(addButton).not.toBeNull(); + } }); } }); diff --git a/src/app/core/locale/locale.interceptor.spec.ts b/src/app/core/locale/locale.interceptor.spec.ts index 9e298fefcc..e96126d19c 100644 --- a/src/app/core/locale/locale.interceptor.spec.ts +++ b/src/app/core/locale/locale.interceptor.spec.ts @@ -52,7 +52,7 @@ describe(`LocaleInterceptor`, () => { expect(httpRequest.request.headers.has('Accept-Language')); const lang = httpRequest.request.headers.get('Accept-Language'); - expect(lang).toBeDefined(); + expect(lang).not.toBeNull(); expect(lang).toBe(languageList.toString()); }); diff --git a/src/app/core/xsrf/xsrf.interceptor.spec.ts b/src/app/core/xsrf/xsrf.interceptor.spec.ts index 742c4a4a45..4a78b60fc1 100644 --- a/src/app/core/xsrf/xsrf.interceptor.spec.ts +++ b/src/app/core/xsrf/xsrf.interceptor.spec.ts @@ -67,7 +67,7 @@ describe(`XsrfInterceptor`, () => { expect(httpRequest.request.headers.has('X-XSRF-TOKEN')).toBeTrue(); expect(httpRequest.request.withCredentials).toBeTrue(); const token = httpRequest.request.headers.get('X-XSRF-TOKEN'); - expect(token).toBeDefined(); + expect(token).not.toBeNull(); expect(token).toBe(testToken.toString()); httpRequest.flush(mockPayload, { status: mockStatusCode, statusText: mockStatusText }); @@ -116,11 +116,11 @@ describe(`XsrfInterceptor`, () => { // ensure mock XSRF token is in response expect(response.headers.has('DSPACE-XSRF-TOKEN')).toBeTrue(); const token = response.headers.get('DSPACE-XSRF-TOKEN'); - expect(token).toBeDefined(); + expect(token).not.toBeNull(); expect(token).toBe(mockNewXSRFToken.toString()); // ensure our XSRF-TOKEN cookie exists & has the same value as the new DSPACE-XSRF-TOKEN header - expect(cookieService.get('XSRF-TOKEN')).toBeDefined(); + expect(cookieService.get('XSRF-TOKEN')).not.toBeNull(); expect(cookieService.get('XSRF-TOKEN')).toBe(mockNewXSRFToken.toString()); done(); @@ -153,7 +153,7 @@ describe(`XsrfInterceptor`, () => { expect(error.statusText).toBe(mockErrorText); // ensure our XSRF-TOKEN cookie exists & has the same value as the new DSPACE-XSRF-TOKEN header - expect(cookieService.get('XSRF-TOKEN')).toBeDefined(); + expect(cookieService.get('XSRF-TOKEN')).not.toBeNull(); expect(cookieService.get('XSRF-TOKEN')).toBe(mockNewXSRFToken.toString()); done(); diff --git a/src/app/item-page/full/full-item-page.component.spec.ts b/src/app/item-page/full/full-item-page.component.spec.ts index 66c6488b8e..53e36be1d1 100644 --- a/src/app/item-page/full/full-item-page.component.spec.ts +++ b/src/app/item-page/full/full-item-page.component.spec.ts @@ -104,9 +104,13 @@ describe('FullItemPageComponent', () => { fixture.detectChanges(); })); + afterEach(() => { + fixture.debugElement.nativeElement.remove(); + }); + it('should display the item\'s metadata', () => { const table = fixture.debugElement.query(By.css('table')); - for (const metadatum of mockItem.allMetadata([])) { + for (const metadatum of mockItem.allMetadata(Object.keys(mockItem.metadata))) { expect(table.nativeElement.innerHTML).toContain(metadatum.value); } }); @@ -137,7 +141,7 @@ describe('FullItemPageComponent', () => { it('should display the item', () => { const objectLoader = fixture.debugElement.query(By.css('.full-item-info')); - expect(objectLoader.nativeElement).toBeDefined(); + expect(objectLoader.nativeElement).not.toBeNull(); }); }); describe('when the item is withdrawn and the user is not an admin', () => { @@ -161,7 +165,7 @@ describe('FullItemPageComponent', () => { it('should display the item', () => { const objectLoader = fixture.debugElement.query(By.css('.full-item-info')); - expect(objectLoader.nativeElement).toBeDefined(); + expect(objectLoader).not.toBeNull(); }); }); @@ -173,7 +177,7 @@ describe('FullItemPageComponent', () => { it('should display the item', () => { const objectLoader = fixture.debugElement.query(By.css('.full-item-info')); - expect(objectLoader.nativeElement).toBeDefined(); + expect(objectLoader).not.toBeNull(); }); }); }); diff --git a/src/app/item-page/mirador-viewer/mirador-viewer.component.spec.ts b/src/app/item-page/mirador-viewer/mirador-viewer.component.spec.ts index 40ad0fd5d0..2727391dff 100644 --- a/src/app/item-page/mirador-viewer/mirador-viewer.component.spec.ts +++ b/src/app/item-page/mirador-viewer/mirador-viewer.component.spec.ts @@ -253,7 +253,7 @@ describe('MiradorViewerComponent in development mode', () => { it('should show message', (() => { const value = fixture.debugElement .nativeElement.querySelector('#viewer-message'); - expect(value).toBeDefined(); + expect(value).not.toBeNull(); })); }); diff --git a/src/app/item-page/simple/field-components/file-section/file-section.component.spec.ts b/src/app/item-page/simple/field-components/file-section/file-section.component.spec.ts index 2d185aef9c..a90abe9c90 100644 --- a/src/app/item-page/simple/field-components/file-section/file-section.component.spec.ts +++ b/src/app/item-page/simple/field-components/file-section/file-section.component.spec.ts @@ -143,7 +143,7 @@ describe('FileSectionComponent', () => { it('should contain a view less link', () => { const viewLess = fixture.debugElement.query(By.css('.bitstream-collapse')); - expect(viewLess).toBeDefined(); + expect(viewLess).not.toBeNull(); }); it('clicking on the view less link should reset the pages and call getNextPage()', () => { diff --git a/src/app/item-page/simple/field-components/specific-field/abstract/item-page-abstract-field.component.spec.ts b/src/app/item-page/simple/field-components/specific-field/abstract/item-page-abstract-field.component.spec.ts index 53f0522f39..bf1815c6b6 100644 --- a/src/app/item-page/simple/field-components/specific-field/abstract/item-page-abstract-field.component.spec.ts +++ b/src/app/item-page/simple/field-components/specific-field/abstract/item-page-abstract-field.component.spec.ts @@ -41,6 +41,6 @@ describe('ItemPageAbstractFieldComponent', () => { })); it('should render a ds-metadata-values', () => { - expect(fixture.debugElement.query(By.css('ds-metadata-values'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-metadata-values'))).not.toBeNull(); }); }); diff --git a/src/app/shared/browse-by/browse-by.component.spec.ts b/src/app/shared/browse-by/browse-by.component.spec.ts index 43a3910216..83bbe15801 100644 --- a/src/app/shared/browse-by/browse-by.component.spec.ts +++ b/src/app/shared/browse-by/browse-by.component.spec.ts @@ -47,7 +47,7 @@ import { getMockThemeService } from '../mocks/theme-service.mock'; @listableObjectComponent(BrowseEntry, ViewMode.ListElement, DEFAULT_CONTEXT, 'custom') @Component({ - selector: 'ds-browse-entry-list-element', + selector: '', template: '' }) class MockThemedBrowseEntryListElementComponent { @@ -147,19 +147,21 @@ describe('BrowseByComponent', () => { it('should display a loading message when objects is empty', () => { (comp as any).objects = undefined; fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('ds-themed-loading'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-themed-loading'))).not.toBeNull(); }); it('should display results when objects is not empty', () => { - (comp as any).objects = observableOf({ - payload: { - page: { - length: 1 - } - } - }); + comp.objects$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [ + Object.assign(new BrowseEntry(), { + type: ITEM, + authority: 'authority key 1', + value: 'browse entry 1', + language: null, + count: 1, + }), + ])); fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('ds-viewable-collection'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-viewable-collection'))).not.toBeNull(); }); describe('when showPaginator is true and browseEntries are provided', () => { @@ -231,15 +233,24 @@ describe('BrowseByComponent', () => { describe('reset filters button', () => { it('should not be present when no startsWith or value is present ', () => { - const button = fixture.debugElement.query(By.css('reset')); + const button = fixture.debugElement.query(By.css('.reset')); expect(button).toBeNull(); }); it('should be present when a startsWith or value is present ', () => { + comp.objects$ = createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [ + Object.assign(new BrowseEntry(), { + type: ITEM, + authority: 'authority key 1', + value: 'browse entry 1', + language: null, + count: 1, + }), + ])); comp.shouldDisplayResetButton$ = observableOf(true); fixture.detectChanges(); - const button = fixture.debugElement.query(By.css('reset')); - expect(button).toBeDefined(); + const button = fixture.debugElement.query(By.css('.reset')); + expect(button).not.toBeNull(); }); }); describe('back', () => { diff --git a/src/app/shared/lang-switch/lang-switch.component.spec.ts b/src/app/shared/lang-switch/lang-switch.component.spec.ts index 7757622f4c..6d3c847086 100644 --- a/src/app/shared/lang-switch/lang-switch.component.spec.ts +++ b/src/app/shared/lang-switch/lang-switch.component.spec.ts @@ -109,7 +109,7 @@ describe('LangSwitchComponent', () => { })); it('should define the main A HREF in the UI', (() => { - expect(langSwitchElement.querySelector('a')).toBeDefined(); + expect(langSwitchElement.querySelector('a')).not.toBeNull(); })); describe('when selecting a language', () => { diff --git a/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.spec.ts index ce67da1349..b15e246f53 100644 --- a/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/approve/claimed-task-actions-approve.component.spec.ts @@ -72,7 +72,7 @@ describe('ClaimedTaskActionsApproveComponent', () => { it('should display approve button', () => { const btn = fixture.debugElement.query(By.css('.btn-success')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display spin icon when approve is pending', () => { @@ -81,7 +81,7 @@ describe('ClaimedTaskActionsApproveComponent', () => { const span = fixture.debugElement.query(By.css('.btn-success .fa-spin')); - expect(span).toBeDefined(); + expect(span).not.toBeNull(); }); describe('submitTask', () => { diff --git a/src/app/shared/mydspace-actions/claimed-task/edit-metadata/claimed-task-actions-edit-metadata.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/edit-metadata/claimed-task-actions-edit-metadata.component.spec.ts index 5bcddc9b11..7bdf57561f 100644 --- a/src/app/shared/mydspace-actions/claimed-task/edit-metadata/claimed-task-actions-edit-metadata.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/edit-metadata/claimed-task-actions-edit-metadata.component.spec.ts @@ -66,7 +66,7 @@ describe('ClaimedTaskActionsEditMetadataComponent', () => { it('should display edit button', () => { const btn = fixture.debugElement.query(By.css('.btn-primary')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); }); diff --git a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts index 2ccb671d83..b3ea5e1258 100644 --- a/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/reject/claimed-task-actions-reject.component.spec.ts @@ -89,7 +89,7 @@ describe('ClaimedTaskActionsRejectComponent', () => { it('should display reject button', () => { const btn = fixture.debugElement.query(By.css('.btn-danger')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display spin icon when reject is pending', () => { @@ -98,7 +98,7 @@ describe('ClaimedTaskActionsRejectComponent', () => { const span = fixture.debugElement.query(By.css('.btn-danger .fa-spin')); - expect(span).toBeDefined(); + expect(span).not.toBeNull(); }); it('should call openRejectModal on reject button click', () => { diff --git a/src/app/shared/mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component.spec.ts b/src/app/shared/mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component.spec.ts index 46e89d9d3a..765849f0ae 100644 --- a/src/app/shared/mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component.spec.ts +++ b/src/app/shared/mydspace-actions/claimed-task/return-to-pool/claimed-task-actions-return-to-pool.component.spec.ts @@ -72,7 +72,7 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => { it('should display return to pool button', () => { const btn = fixture.debugElement.query(By.css('.btn-secondary')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display spin icon when return to pool action is pending', () => { @@ -81,7 +81,7 @@ describe('ClaimedTaskActionsReturnToPoolComponent', () => { const span = fixture.debugElement.query(By.css('.btn-secondary .fa-spin')); - expect(span).toBeDefined(); + expect(span).not.toBeNull(); }); describe('actionExecution', () => { diff --git a/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.spec.ts b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.spec.ts index 385dea73f3..cb0799caa6 100644 --- a/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/pool-task/pool-task-actions.component.spec.ts @@ -131,13 +131,13 @@ describe('PoolTaskActionsComponent', () => { it('should display claim task button', () => { const btn = fixture.debugElement.query(By.css('.btn-info')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display view button', () => { - const btn = fixture.debugElement.query(By.css('button [data-test="view-btn"]')); + const btn = fixture.debugElement.query(By.css('button[data-test="view-btn"]')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should call claim task with href of getPoolTaskEndpointById', ((done) => { diff --git a/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.spec.ts index 79aece892e..9f266d054e 100644 --- a/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workflowitem/workflowitem-actions.component.spec.ts @@ -107,9 +107,9 @@ describe('WorkflowitemActionsComponent', () => { }); it('should display view button', () => { - const btn = fixture.debugElement.query(By.css('button [data-test="view-btn"]')); + const btn = fixture.debugElement.query(By.css('button[data-test="view-btn"]')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); }); diff --git a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts index 7299c28df2..14d3c07650 100644 --- a/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts +++ b/src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.spec.ts @@ -123,19 +123,19 @@ describe('WorkspaceitemActionsComponent', () => { it('should display edit button', () => { const btn = fixture.debugElement.query(By.css('.btn-primary')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display delete button', () => { const btn = fixture.debugElement.query(By.css('.btn-danger')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); it('should display view button', () => { - const btn = fixture.debugElement.query(By.css('button [data-test="view-btn"]')); + const btn = fixture.debugElement.query(By.css('button[data-test="view-btn"]')); - expect(btn).toBeDefined(); + expect(btn).not.toBeNull(); }); describe('on discard confirmation', () => { diff --git a/src/app/shared/object-collection/object-collection.component.spec.ts b/src/app/shared/object-collection/object-collection.component.spec.ts index c28df74aa7..1619e56b0d 100644 --- a/src/app/shared/object-collection/object-collection.component.spec.ts +++ b/src/app/shared/object-collection/object-collection.component.spec.ts @@ -30,27 +30,34 @@ describe('ObjectCollectionComponent', () => { }).compileComponents(); // compile template and css })); - beforeEach(waitForAsync(() => { + beforeEach(() => { fixture = TestBed.createComponent(ObjectCollectionComponent); objectCollectionComponent = fixture.componentInstance; - })); + fixture.detectChanges(); + }); it('should only show the grid component when the viewmode is set to grid', () => { objectCollectionComponent.currentMode$ = observableOf(ViewMode.GridElement); + fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeDefined(); - expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeNull(); + expect(fixture.debugElement.query(By.css('ds-object-grid'))).not.toBeNull(); + expect(fixture.debugElement.query(By.css('ds-themed-object-list'))).toBeNull(); }); it('should only show the list component when the viewmode is set to list', () => { objectCollectionComponent.currentMode$ = observableOf(ViewMode.ListElement); + fixture.detectChanges(); - expect(fixture.debugElement.query(By.css('ds-object-list'))).toBeDefined(); + expect(fixture.debugElement.query(By.css('ds-themed-object-list'))).not.toBeNull(); expect(fixture.debugElement.query(By.css('ds-object-grid'))).toBeNull(); }); - it('should set fallback placeholder font size during test', () => { - objectCollectionComponent.currentMode$ = observableOf(ViewMode.ListElement); - expect(fixture.debugElement.query(By.css('thumb-font-3'))).toBeDefined(); + it('should set fallback placeholder font size during test', async () => { + objectCollectionComponent.currentMode$ = observableOf(ViewMode.ListElement); + fixture.detectChanges(); + + const comp = fixture.debugElement.query(By.css('ds-themed-object-list')); + expect(comp).not.toBeNull(); + expect(comp.nativeElement.classList).not.toContain('hide-placeholder-text'); }); }); diff --git a/src/app/shared/object-collection/shared/mydspace-item-status/my-dspace-item-status.component.spec.ts b/src/app/shared/object-collection/shared/mydspace-item-status/my-dspace-item-status.component.spec.ts index 44e6a44b70..f3d1e868b7 100644 --- a/src/app/shared/object-collection/shared/mydspace-item-status/my-dspace-item-status.component.spec.ts +++ b/src/app/shared/object-collection/shared/mydspace-item-status/my-dspace-item-status.component.spec.ts @@ -48,7 +48,7 @@ describe('MyDSpaceItemStatusComponent', () => { it('should display badge', () => { const badge = fixture.debugElement.query(By.css('span')); - expect(badge).toBeDefined(); + expect(badge).not.toBeNull(); }); it('should init badge content and class', () => { diff --git a/src/app/shared/object-collection/shared/mydspace-item-submitter/item-submitter.component.spec.ts b/src/app/shared/object-collection/shared/mydspace-item-submitter/item-submitter.component.spec.ts index 227db9ec82..cf1de597f6 100644 --- a/src/app/shared/object-collection/shared/mydspace-item-submitter/item-submitter.component.spec.ts +++ b/src/app/shared/object-collection/shared/mydspace-item-submitter/item-submitter.component.spec.ts @@ -63,7 +63,7 @@ describe('ItemSubmitterComponent', () => { it('should show a badge with submitter name', () => { const badge = fixture.debugElement.query(By.css('.badge')); - expect(badge).toBeDefined(); + expect(badge).not.toBeNull(); expect(badge.nativeElement.innerHTML).toBe(EPersonMock.name); }); }); diff --git a/src/app/shared/page-size-selector/page-size-selector.component.spec.ts b/src/app/shared/page-size-selector/page-size-selector.component.spec.ts index 67947c3425..80956e7184 100644 --- a/src/app/shared/page-size-selector/page-size-selector.component.spec.ts +++ b/src/app/shared/page-size-selector/page-size-selector.component.spec.ts @@ -72,9 +72,9 @@ describe('PageSizeSelectorComponent', () => { }); it('it should show the size settings with the respective selectable options', (done) => { - (comp as any).paginationOptions$.pipe(first()).subscribe((options) => { + comp.paginationOptions$.pipe(first()).subscribe((options: PaginationComponentOptions) => { const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); - expect(pageSizeSetting).toBeDefined(); + expect(pageSizeSetting).not.toBeNull(); const childElements = pageSizeSetting.queryAll(By.css('option')); expect(childElements.length).toEqual(options.pageSizeOptions.length); done(); @@ -83,10 +83,11 @@ describe('PageSizeSelectorComponent', () => { }); it('should have the proper rpp value selected by default', (done) => { - (comp as any).paginationOptions$.pipe(take(1)).subscribe((options) => { + comp.paginationOptions$.pipe(take(1)).subscribe(() => { const pageSizeSetting = fixture.debugElement.query(By.css('div.page-size-settings')); - const childElementToBeSelected = pageSizeSetting.query(By.css('option[value="10"][selected="selected"]')); - expect(childElementToBeSelected).toBeDefined(); + const childElementToBeSelected = pageSizeSetting.query(By.css('option[value="10"]')); + expect(childElementToBeSelected).not.toBeNull(); + expect(childElementToBeSelected.nativeElement.selected).toBeTrue() done(); }); }); diff --git a/src/app/shared/search/search-settings/search-settings.component.spec.ts b/src/app/shared/search/search-settings/search-settings.component.spec.ts index 06e506ddb0..d0b51f04b1 100644 --- a/src/app/shared/search/search-settings/search-settings.component.spec.ts +++ b/src/app/shared/search/search-settings/search-settings.component.spec.ts @@ -107,6 +107,7 @@ describe('SearchSettingsComponent', () => { new SortOptions('dc.title', SortDirection.ASC), new SortOptions('dc.title', SortDirection.DESC) ]; + comp.currentSortOption = new SortOptions('score', SortDirection.DESC); // SearchPageComponent test instance fixture.detectChanges(); @@ -133,7 +134,8 @@ describe('SearchSettingsComponent', () => { it('should have the proper order value selected by default', () => { fixture.detectChanges(); const orderSetting = fixture.debugElement.query(By.css('div.result-order-settings')); - const childElementToBeSelected = orderSetting.query(By.css('option[value="score,DESC"][selected="selected"]')); - expect(childElementToBeSelected).toBeDefined(); + const childElementToBeSelected = orderSetting.query(By.css('option[value="score,DESC"]')); + expect(childElementToBeSelected).not.toBeNull(); + expect(childElementToBeSelected.nativeElement.selected).toBeTrue(); }); }); diff --git a/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.spec.ts b/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.spec.ts index fadde46e53..8fc178c67a 100644 --- a/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.spec.ts +++ b/src/app/shared/search/search-switch-configuration/search-switch-configuration.component.spec.ts @@ -78,7 +78,7 @@ describe('SearchSwitchConfigurationComponent', () => { it('should display select field properly', () => { const selectField = fixture.debugElement.query(By.css('.form-control')); - expect(selectField).toBeDefined(); + expect(selectField).not.toBeNull(); const childElements = selectField.children; expect(childElements.length).toEqual(comp.configurationList.length); diff --git a/src/app/submission/form/section-add/submission-form-section-add.component.spec.ts b/src/app/submission/form/section-add/submission-form-section-add.component.spec.ts index 971b15d7b0..a8ad7fbe49 100644 --- a/src/app/submission/form/section-add/submission-form-section-add.component.spec.ts +++ b/src/app/submission/form/section-add/submission-form-section-add.component.spec.ts @@ -96,6 +96,7 @@ describe('SubmissionFormSectionAddComponent Component', () => { afterEach(() => { testFixture.destroy(); + testFixture.debugElement.nativeElement.remove(); }); it('should create SubmissionFormSectionAddComponent', inject([SubmissionFormSectionAddComponent], (app: SubmissionFormSectionAddComponent) => { @@ -163,7 +164,7 @@ describe('SubmissionFormSectionAddComponent Component', () => { it('should have dropdown menu closed', () => { - expect(dropdowBtn).not.toBeUndefined(); + expect(dropdowBtn).not.toBeNull(); expect(dropdownMenu.nativeElement.classList).not.toContain('show'); }); diff --git a/src/app/submission/sections/container/section-container.component.spec.ts b/src/app/submission/sections/container/section-container.component.spec.ts index 7568b17ea7..8a4b3ebc56 100644 --- a/src/app/submission/sections/container/section-container.component.spec.ts +++ b/src/app/submission/sections/container/section-container.component.spec.ts @@ -137,7 +137,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { const section = fixture.debugElement.query(By.css('[id^=\'sectionContent_\']')); expect(comp.getSectionContent).toHaveBeenCalled(); - expect(section).toBeDefined(); + expect(section).not.toBeNull(); }); it('should call removeSection properly', () => { @@ -165,7 +165,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { fixture.detectChanges(); sectionErrorsDiv = fixture.debugElement.query(By.css('[id^=\'sectionGenericError_\']')); - expect(sectionErrorsDiv).toBeDefined(); + expect(sectionErrorsDiv).not.toBeNull(); }); it('should display warning icon', () => { @@ -180,7 +180,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { const iconWarn = fixture.debugElement.query(By.css('i.text-warning')); const iconErr = fixture.debugElement.query(By.css('i.text-danger')); const iconSuccess = fixture.debugElement.query(By.css('i.text-success')); - expect(iconWarn).toBeDefined(); + expect(iconWarn).not.toBeNull(); expect(iconErr).toBeNull(); expect(iconSuccess).toBeNull(); }); @@ -198,7 +198,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { const iconErr = fixture.debugElement.query(By.css('i.text-danger')); const iconSuccess = fixture.debugElement.query(By.css('i.text-success')); expect(iconWarn).toBeNull(); - expect(iconErr).toBeDefined(); + expect(iconErr).not.toBeNull(); expect(iconSuccess).toBeNull(); }); @@ -216,7 +216,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { const iconSuccess = fixture.debugElement.query(By.css('i.text-success')); expect(iconWarn).toBeNull(); expect(iconErr).toBeNull(); - expect(iconSuccess).toBeDefined(); + expect(iconSuccess).not.toBeNull(); }); }); @@ -224,7 +224,7 @@ describe('SubmissionSectionContainerComponent test suite', () => { // declare a test component @Component({ - selector: 'ds-test-cmp', + selector: '', template: `` }) class TestComponent {