mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
Fixed false positive tests caused by fixture.debugElement.query().toBeDefined()
This commit is contained in:
@@ -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<RemoteData<PaginatedList<EPerson>>> {
|
||||
findListByHref(_href: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
return createSuccessfulRemoteDataObject$(buildPaginatedList<EPerson>(new PageInfo(), groupsDataServiceStub.getEPersonMembers()));
|
||||
},
|
||||
searchByScope(scope: string, query: string): Observable<RemoteData<PaginatedList<EPerson>>> {
|
||||
@@ -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();
|
||||
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).toBeUndefined();
|
||||
expect(addButton).toBeDefined();
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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);
|
||||
|
@@ -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<RemoteData<PaginatedList<Group>>> {
|
||||
findListByHref(_href: string): Observable<RemoteData<PaginatedList<Group>>> {
|
||||
return this.subgroups$.pipe(
|
||||
map((currentGroups: Group[]) => {
|
||||
return createSuccessfulRemoteDataObject(buildPaginatedList<Group>(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();
|
||||
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).toBeUndefined();
|
||||
expect(addButton).toBeDefined();
|
||||
expect(deleteButton).toBeNull();
|
||||
expect(addButton).not.toBeNull();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -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());
|
||||
});
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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();
|
||||
}));
|
||||
|
||||
});
|
||||
|
@@ -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()', () => {
|
||||
|
@@ -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();
|
||||
});
|
||||
});
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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"]'));
|
||||
|
||||
expect(btn).toBeDefined();
|
||||
expect(btn).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should call claim task with href of getPoolTaskEndpointById', ((done) => {
|
||||
|
@@ -109,7 +109,7 @@ describe('WorkflowitemActionsComponent', () => {
|
||||
it('should display view button', () => {
|
||||
const btn = fixture.debugElement.query(By.css('button[data-test="view-btn"]'));
|
||||
|
||||
expect(btn).toBeDefined();
|
||||
expect(btn).not.toBeNull();
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -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"]'));
|
||||
|
||||
expect(btn).toBeDefined();
|
||||
expect(btn).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('on discard confirmation', () => {
|
||||
|
@@ -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');
|
||||
});
|
||||
});
|
||||
|
@@ -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', () => {
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
|
@@ -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();
|
||||
});
|
||||
});
|
||||
|
@@ -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();
|
||||
});
|
||||
});
|
||||
|
@@ -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);
|
||||
|
@@ -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');
|
||||
|
||||
});
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user