Skip to content

Commit a514b6e

Browse files
[DURACOM-426] fix tests and lint
1 parent 9c5e6bb commit a514b6e

20 files changed

Lines changed: 202 additions & 207 deletions

File tree

src/app/core/data/base/identifiable-data.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* http://www.dspace.org/license/
77
*/
8+
import { RequestParam } from '@dspace/core/cache/models/request-param.model';
89
import { Observable } from 'rxjs';
910
import {
1011
map,
@@ -17,11 +18,10 @@ import { CacheableObject } from '../../cache/cacheable-object.model';
1718
import { ObjectCacheService } from '../../cache/object-cache.service';
1819
import { FollowLinkConfig } from '../../shared/follow-link-config.model';
1920
import { HALEndpointService } from '../../shared/hal-endpoint.service';
21+
import { FindListOptions } from '../find-list-options.model';
2022
import { RemoteData } from '../remote-data';
2123
import { RequestService } from '../request.service';
2224
import { BaseDataService } from './base-data.service';
23-
import { FindListOptions } from "../find-list-options.model";
24-
import { RequestParam } from "@dspace/core/cache/models/request-param.model";
2525

2626
/**
2727
* Shorthand type for the method to construct an ID endpoint.

src/app/shared/entity-icon/entity-icon.directive.spec.ts

Lines changed: 93 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,107 @@
1-
import { Component } from '@angular/core';
2-
import {
3-
ComponentFixture,
4-
TestBed,
5-
} from '@angular/core/testing';
6-
7-
import { EntityIconDirective } from './entity-icon.directive';
8-
9-
describe('EntityIconDirective', () => {
10-
let component: TestComponent;
11-
let fixture: ComponentFixture<TestComponent>;
12-
13-
beforeEach(async () => {
14-
await TestBed.configureTestingModule({
15-
imports: [
16-
EntityIconDirective,
17-
TestComponent
18-
],
19-
}).compileComponents();
1+
import { Component } from '@angular/core';
2+
import {
3+
ComponentFixture,
4+
TestBed,
5+
} from '@angular/core/testing';
6+
7+
import { EntityIconDirective } from './entity-icon.directive';
8+
9+
describe('EntityIconDirective', () => {
10+
let component: TestComponent;
11+
let fixture: ComponentFixture<TestComponent>;
12+
13+
beforeEach(async () => {
14+
await TestBed.configureTestingModule({
15+
imports: [
16+
EntityIconDirective,
17+
TestComponent,
18+
],
19+
}).compileComponents();
20+
});
21+
22+
describe('with default value provided', () => {
23+
beforeEach(() => {
24+
fixture = TestBed.createComponent(TestComponent);
25+
component = fixture.componentInstance;
26+
fixture.detectChanges();
2027
});
2128

22-
describe('with default value provided', () => {
23-
beforeEach(() => {
24-
fixture = TestBed.createComponent(TestComponent);
25-
component = fixture.componentInstance;
26-
fixture.detectChanges();
27-
});
28-
29-
it('should create', () => {
30-
expect(component).toBeTruthy();
31-
});
32-
33-
it('should display a text-success icon', () => {
34-
const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success');
35-
expect(successIcon).toBeTruthy();
36-
});
37-
38-
it('should display a text-success icon after span', () => {
39-
const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success');
40-
const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]');
41-
// position 1 because the icon is after the span
42-
expect(entityElement.children[1]).toBe(successIcon);
43-
});
29+
it('should create', () => {
30+
expect(component).toBeTruthy();
4431
});
4532

46-
describe('with primary value provided', () => {
47-
beforeEach(() => {
48-
fixture = TestBed.createComponent(TestComponent);
49-
component = fixture.componentInstance;
50-
component.metadata.entityType = 'person';
51-
component.metadata.entityStyle = 'personStaff';
52-
component.iconPosition = 'before';
53-
fixture.detectChanges();
54-
});
55-
56-
it('should display a text-primary icon', () => {
57-
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary');
58-
expect(primaryIcon).toBeTruthy();
59-
});
60-
61-
it('should display a text-primary icon before span', () => {
62-
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary');
63-
const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]');
64-
// position 0 because the icon is before the span
65-
expect(entityElement.children[0]).toBe(primaryIcon);
66-
});
33+
it('should display a text-success icon', () => {
34+
const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success');
35+
expect(successIcon).toBeTruthy();
6736
});
6837

69-
describe('when given type doesn\'t exist and fallback on default disabled', () => {
70-
beforeEach(() => {
71-
fixture = TestBed.createComponent(TestComponent);
72-
component = fixture.componentInstance;
73-
component.fallbackOnDefault = false;
74-
component.metadata.entityType = 'TESTFAKE';
75-
component.metadata.entityStyle = 'personFallback';
76-
component.iconPosition = 'before';
77-
fixture.detectChanges();
78-
});
79-
80-
it('should not display a text-primary icon', () => {
81-
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i');
82-
expect(primaryIcon).toBeFalsy();
83-
});
38+
it('should display a text-success icon after span', () => {
39+
const successIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-success');
40+
const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]');
41+
// position 1 because the icon is after the span
42+
expect(entityElement.children[1]).toBe(successIcon);
43+
});
44+
});
45+
46+
describe('with primary value provided', () => {
47+
beforeEach(() => {
48+
fixture = TestBed.createComponent(TestComponent);
49+
component = fixture.componentInstance;
50+
component.metadata.entityType = 'person';
51+
component.metadata.entityStyle = 'personStaff';
52+
component.iconPosition = 'before';
53+
fixture.detectChanges();
8454
});
8555

86-
describe('when given style doesn\'t exist and fallback on default disabled', () => {
87-
beforeEach(() => {
88-
fixture = TestBed.createComponent(TestComponent);
89-
component = fixture.componentInstance;
90-
component.fallbackOnDefault = false;
91-
component.metadata.entityType = 'person';
92-
component.metadata.entityStyle = 'personFallback';
93-
component.iconPosition = 'before';
94-
fixture.detectChanges();
95-
});
96-
97-
it('should not display a text-primary icon', () => {
98-
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i');
99-
expect(primaryIcon).toBeFalsy();
100-
});
56+
it('should display a text-primary icon', () => {
57+
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary');
58+
expect(primaryIcon).toBeTruthy();
10159
});
10260

61+
it('should display a text-primary icon before span', () => {
62+
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i.text-primary');
63+
const entityElement = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]');
64+
// position 0 because the icon is before the span
65+
expect(entityElement.children[0]).toBe(primaryIcon);
66+
});
10367
});
10468

69+
describe('when given type doesn\'t exist and fallback on default disabled', () => {
70+
beforeEach(() => {
71+
fixture = TestBed.createComponent(TestComponent);
72+
component = fixture.componentInstance;
73+
component.fallbackOnDefault = false;
74+
component.metadata.entityType = 'TESTFAKE';
75+
component.metadata.entityStyle = 'personFallback';
76+
component.iconPosition = 'before';
77+
fixture.detectChanges();
78+
});
79+
80+
it('should not display a text-primary icon', () => {
81+
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i');
82+
expect(primaryIcon).toBeFalsy();
83+
});
84+
});
85+
86+
describe('when given style doesn\'t exist and fallback on default disabled', () => {
87+
beforeEach(() => {
88+
fixture = TestBed.createComponent(TestComponent);
89+
component = fixture.componentInstance;
90+
component.fallbackOnDefault = false;
91+
component.metadata.entityType = 'person';
92+
component.metadata.entityStyle = 'personFallback';
93+
component.iconPosition = 'before';
94+
fixture.detectChanges();
95+
});
96+
97+
it('should not display a text-primary icon', () => {
98+
const primaryIcon = fixture.nativeElement.querySelector('[data-test="entityTestComponent"]').querySelector('i');
99+
expect(primaryIcon).toBeFalsy();
100+
});
101+
});
102+
103+
});
104+
105105
// declare a test component
106106
@Component({
107107
selector: 'ds-test-cmp',
@@ -112,12 +112,11 @@
112112
[entityType]="metadata.entityType"
113113
[entityStyle]="metadata.entityStyle"
114114
[fallbackOnDefault]="fallbackOnDefault">{{ metadata.value }}</span></div>`,
115-
standalone: true,
116115
imports: [
117116
EntityIconDirective,
118117
],
119118
})
120-
class TestComponent {
119+
class TestComponent {
121120

122121
metadata = {
123122
authority: null,

src/app/shared/entity-icon/entity-icon.directive.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
Input,
55
OnInit,
66
} from '@angular/core';
7-
87
import {
98
CrisRefConfig,
109
CrisRefEntityStyleConfig,
1110
} from '@dspace/config/layout-config.interfaces';
11+
import {
12+
isEmpty,
13+
isNotEmpty,
14+
} from '@dspace/shared/utils/empty.util';
15+
1216
import { environment } from '../../../environments/environment';
13-
import { isEmpty, isNotEmpty } from "@dspace/shared/utils/empty.util";
1417

1518

1619
/**

src/app/shared/metadata-link-view/metadata-link-view-avatar-popover/metadata-link-view-avatar-popover.component.spec.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
/* tslint:disable:no-unused-variable */
2-
import { EventEmitter } from '@angular/core';
31
import {
42
ComponentFixture,
53
TestBed,
64
waitForAsync,
75
} from '@angular/core/testing';
8-
import { TranslateModule, TranslateService } from '@ngx-translate/core';
9-
import {
10-
of as observableOf,
11-
of,
12-
} from 'rxjs';
13-
146
import { AuthService } from '@dspace/core/auth/auth.service';
157
import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service';
168
import { FileService } from '@dspace/core/shared/file.service';
9+
import { TranslateModule } from '@ngx-translate/core';
10+
import { of } from 'rxjs';
11+
1712
import { ThemedLoadingComponent } from '../../loading/themed-loading.component';
1813
import { MetadataLinkViewAvatarPopoverComponent } from './metadata-link-view-avatar-popover.component';
1914

@@ -23,24 +18,18 @@ describe('MetadataLinkViewAvatarPopoverComponent', () => {
2318
let authService;
2419
let authorizationService;
2520
let fileService;
26-
let translateServiceStub;
2721

2822
beforeEach(waitForAsync(() => {
2923
authService = jasmine.createSpyObj('AuthService', {
30-
isAuthenticated: observableOf(true),
24+
isAuthenticated: of(true),
3125
});
3226
authorizationService = jasmine.createSpyObj('AuthorizationService', {
33-
isAuthorized: observableOf(true),
27+
isAuthorized: of(true),
3428
});
3529
fileService = jasmine.createSpyObj('FileService', {
3630
retrieveFileDownloadLink: null,
3731
});
38-
translateServiceStub = {
39-
get: () => of('translated-text'),
40-
onLangChange: new EventEmitter(),
41-
onTranslationChange: new EventEmitter(),
42-
onDefaultLangChange: new EventEmitter(),
43-
};
32+
4433
TestBed.configureTestingModule({
4534
imports: [
4635
MetadataLinkViewAvatarPopoverComponent,
@@ -50,7 +39,6 @@ describe('MetadataLinkViewAvatarPopoverComponent', () => {
5039
{ provide: AuthService, useValue: authService },
5140
{ provide: AuthorizationDataService, useValue: authorizationService },
5241
{ provide: FileService, useValue: fileService },
53-
{ provide: TranslateService, useValue: translateServiceStub },
5442
],
5543
})
5644
.overrideComponent(MetadataLinkViewAvatarPopoverComponent, { remove: { imports: [ThemedLoadingComponent] } }).compileComponents();

src/app/shared/metadata-link-view/metadata-link-view-avatar-popover/metadata-link-view-avatar-popover.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { AsyncPipe, NgClass } from '@angular/common';
1+
import {
2+
AsyncPipe,
3+
NgClass,
4+
} from '@angular/common';
25
import {
36
Component,
47
Input,
@@ -8,22 +11,21 @@ import { TranslateModule } from '@ngx-translate/core';
811
import { Observable } from 'rxjs';
912
import { ThumbnailComponent } from 'src/app/thumbnail/thumbnail.component';
1013

14+
import { getDefaultImageUrlByEntityType } from '../../image.utils';
1115
import { ThemedLoadingComponent } from '../../loading/themed-loading.component';
1216
import { SafeUrlPipe } from '../../utils/safe-url-pipe';
13-
import { getDefaultImageUrlByEntityType } from "../../image.utils";
1417

1518
@Component({
1619
selector: 'ds-metadata-link-view-avatar-popover',
1720
templateUrl: './metadata-link-view-avatar-popover.component.html',
1821
styleUrls: ['./metadata-link-view-avatar-popover.component.scss'],
1922
imports: [
20-
ThemedLoadingComponent,
23+
AsyncPipe,
24+
NgClass,
2125
SafeUrlPipe,
26+
ThemedLoadingComponent,
2227
TranslateModule,
23-
NgClass,
24-
AsyncPipe
25-
],
26-
standalone: true,
28+
],
2729
})
2830
export class MetadataLinkViewAvatarPopoverComponent extends ThumbnailComponent implements OnInit {
2931

src/app/shared/metadata-link-view/metadata-link-view-orcid/metadata-link-view-orcid.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import {
33
TestBed,
44
} from '@angular/core/testing';
55
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
6+
import { ConfigurationDataService } from '@dspace/core/data/configuration-data.service';
7+
import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock';
8+
import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils';
69
import {
710
TranslateLoader,
811
TranslateModule,
912
} from '@ngx-translate/core';
1013
import { Item } from 'src/app/core/shared/item.model';
1114
import { MetadataValue } from 'src/app/core/shared/metadata.models';
1215

13-
import { ConfigurationDataService } from '@dspace/core/data/configuration-data.service';
1416
import { MetadataLinkViewOrcidComponent } from './metadata-link-view-orcid.component';
15-
import { TranslateLoaderMock } from "@dspace/core/testing/translate-loader.mock";
16-
import { createSuccessfulRemoteDataObject$ } from "@dspace/core/utilities/remote-data.utils";
1717

1818
describe('MetadataLinkViewOrcidComponent', () => {
1919
let component: MetadataLinkViewOrcidComponent;

0 commit comments

Comments
 (0)