Skip to content

Commit e7a2c4f

Browse files
authored
refactor: update imports step 1 (DSP-1882) (#516)
* refactor: update imports * fix(test): fix login comp tests * fix(test): fix resource-class-form comp test * fix(test): fixes header comp tests * fix(test): fixes remaining failing unit tests * refactor(resource-class-form): updates the components used from the one found in the dsp-ui to the ones migrated to dsp-app
1 parent d793fb8 commit e7a2c4f

106 files changed

Lines changed: 352 additions & 397 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/app/app.component.spec.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@ import { MatMenuModule } from '@angular/material/menu';
66
import { MatToolbarModule } from '@angular/material/toolbar';
77
import { RouterTestingModule } from '@angular/router/testing';
88
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
9-
import {
10-
AppInitService,
11-
DspActionModule,
12-
DspApiConfigToken,
13-
DspApiConnectionToken,
14-
DspSearchModule
15-
} from '@dasch-swiss/dsp-ui';
9+
import { AppInitService, DspActionModule, DspSearchModule } from '@dasch-swiss/dsp-ui';
1610
import { TranslateModule } from '@ngx-translate/core';
1711
import { TestConfig } from 'test.config';
1812
import { AppComponent } from './app.component';
13+
import { DspApiConfigToken, DspApiConnectionToken } from './main/declarations/dsp-api-tokens';
1914
import { HeaderComponent } from './main/header/header.component';
2015
import { SelectLanguageComponent } from './main/select-language/select-language.component';
2116
import { UserMenuComponent } from './user/user-menu/user-menu.component';

‎src/app/app.module.ts‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
77
import { BrowserModule } from '@angular/platform-browser';
88
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
99
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
10-
import {
11-
DspActionModule,
12-
DspApiConfigToken,
13-
DspApiConnectionToken,
14-
DspCoreModule,
15-
DspSearchModule,
16-
DspViewerModule
17-
} from '@dasch-swiss/dsp-ui';
10+
import { DspActionModule, DspCoreModule, DspSearchModule, DspViewerModule } from '@dasch-swiss/dsp-ui';
1811
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
1912
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
2013
import { AngularSplitModule } from 'angular-split';
@@ -166,6 +159,7 @@ import { ResourceAndPropertySelectionComponent } from './workspace/search/advanc
166159
import { SearchSelectPropertyComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/search-select-property.component';
167160
import { SearchSelectResourceClassComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-resource-class/search-select-resource-class.component';
168161
import { SearchSelectOntologyComponent } from './workspace/search/advanced-search/search-select-ontology/search-select-ontology.component';
162+
import { DspApiConfigToken, DspApiConnectionToken } from './main/declarations/dsp-api-tokens';
169163

170164
// translate: AoT requires an exported function for factories
171165
export function httpLoaderFactory(httpClient: HttpClient) {

‎src/app/main/cache/cache.service.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { TestBed } from '@angular/core/testing';
22
import { MatDialogModule } from '@angular/material/dialog';
33
import { MatSnackBarModule } from '@angular/material/snack-bar';
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5-
import { DspActionModule, DspApiConnectionToken, DspCoreModule } from '@dasch-swiss/dsp-ui';
5+
import { DspActionModule, DspCoreModule } from '@dasch-swiss/dsp-ui';
6+
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
67
import { CacheService } from './cache.service';
78

89
describe('CacheService', () => {

‎src/app/main/error/error-handler.service.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { TestBed } from '@angular/core/testing';
22
import { MatDialogModule } from '@angular/material/dialog';
33
import { MatSnackBarModule } from '@angular/material/snack-bar';
44
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
5-
import { DspActionModule, DspApiConnectionToken, DspCoreModule } from '@dasch-swiss/dsp-ui';
5+
import { DspActionModule, DspCoreModule } from '@dasch-swiss/dsp-ui';
6+
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
67
import { ErrorHandlerService } from './error-handler.service';
78

89
describe('ErrorHandlerService', () => {

‎src/app/main/error/error-handler.service.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Inject, Injectable } from '@angular/core';
22
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
33
import { ApiResponseData, ApiResponseError, KnoraApiConnection, LogoutResponse } from '@dasch-swiss/dsp-js';
4-
import { DspApiConnectionToken, NotificationService, SessionService } from '@dasch-swiss/dsp-ui';
4+
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
55
import { DialogComponent } from '../dialog/dialog.component';
6+
import { NotificationService } from '../services/notification.service';
7+
import { SessionService } from '../services/session.service';
68

79
@Injectable({
810
providedIn: 'root'

‎src/app/main/guard/auth.guard.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable } from '@angular/core';
22
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
33
import { Observable } from 'rxjs';
4-
import { SessionService } from '@dasch-swiss/dsp-ui';
4+
import { SessionService } from '../services/session.service';
55

66
@Injectable({
77
providedIn: 'root'

‎src/app/main/header/header.component.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ <h1 class="mat-headline phone-tablet-only">DSP</h1>
1313
<!-- search-panel (in desktop and tablet version) -->
1414
<span class="action">
1515
<!-- button to reactivate when dsp-app will be used as a research platform again: -->
16-
<dsp-search-panel
16+
<app-search-panel
1717
[projectfilter]="true"
1818
[advanced]="true"
1919
[expert]="true"
2020
(search)="doSearch($event)">
21-
</dsp-search-panel>
21+
</app-search-panel>
2222

2323
</span>
2424

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HttpClientModule } from '@angular/common/http';
2+
import { Component, Input, OnInit, ViewChild } from '@angular/core';
23
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
34
import { MatIconModule } from '@angular/material/icon';
45
import { MatListModule } from '@angular/material/list';
@@ -8,38 +9,62 @@ import { By } from '@angular/platform-browser';
89
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
910
import { RouterTestingModule } from '@angular/router/testing';
1011
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
11-
import {
12-
AppInitService,
13-
DspActionModule,
14-
DspApiConfigToken,
15-
DspApiConnectionToken,
16-
DspCoreModule,
17-
DspSearchModule
18-
} from '@dasch-swiss/dsp-ui';
12+
import { DspActionModule, DspSearchModule } from '@dasch-swiss/dsp-ui';
1913
import { TranslateModule } from '@ngx-translate/core';
14+
import { AppInitService } from 'src/app/app-init.service';
2015
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';
2116
import { UserMenuComponent } from 'src/app/user/user-menu/user-menu.component';
2217
import { TestConfig } from 'test.config';
18+
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
2319
import { SelectLanguageComponent } from '../select-language/select-language.component';
2420
import { HeaderComponent } from './header.component';
2521

22+
/**
23+
* test host component to simulate parent component.
24+
*/
25+
@Component({
26+
template: '<app-header #header></app-header>'
27+
})
28+
class TestHostHeaderComponent {
29+
@ViewChild('header') headerComp: HeaderComponent;
30+
}
31+
32+
/**
33+
* test component to simulate search panel component.
34+
*/
35+
@Component({
36+
selector: 'app-search-panel',
37+
template: ''
38+
})
39+
class TestSearchPanelComponent {
40+
@Input() projectfilter?: boolean = false;
41+
@Input() filterbyproject?: string;
42+
@Input() limitToProject?: string;
43+
@Input() advanced?: boolean = false;
44+
@Input() expert?: boolean = false;
45+
}
46+
2647
describe('HeaderComponent', () => {
27-
let component: HeaderComponent;
28-
let fixture: ComponentFixture<HeaderComponent>;
48+
let testHostComponent: TestHostHeaderComponent;
49+
let testHostFixture: ComponentFixture<TestHostHeaderComponent>;
50+
let hostCompDe;
51+
let headerCompDe;
52+
2953
let componentCommsService: ComponentCommunicationEventService;
3054

3155
beforeEach(waitForAsync(() => {
3256
TestBed.configureTestingModule({
3357
declarations: [
3458
HeaderComponent,
59+
TestHostHeaderComponent,
60+
TestSearchPanelComponent,
3561
SelectLanguageComponent,
3662
UserMenuComponent
3763
],
3864
imports: [
3965
BrowserAnimationsModule,
4066
HttpClientModule,
4167
DspActionModule,
42-
DspCoreModule,
4368
DspSearchModule,
4469
MatIconModule,
4570
MatListModule,
@@ -66,55 +91,59 @@ describe('HeaderComponent', () => {
6691
}));
6792

6893
beforeEach(() => {
69-
fixture = TestBed.createComponent(HeaderComponent);
70-
component = fixture.componentInstance;
71-
fixture.detectChanges();
94+
testHostFixture = TestBed.createComponent(TestHostHeaderComponent);
95+
testHostComponent = testHostFixture.componentInstance;
96+
testHostFixture.detectChanges();
97+
98+
hostCompDe = testHostFixture.debugElement;
99+
headerCompDe = hostCompDe.query(By.directive(HeaderComponent));
72100
});
73101

74102
it('should create', () => {
75-
expect(component).toBeTruthy();
103+
expect(testHostComponent).toBeTruthy();
76104
});
77105

78106
it('should display the lamp icon button', () => {
79-
const lampIconBtn = fixture.debugElement.query(By.css('button.home-button'));
80-
expect(lampIconBtn).toBeDefined();
107+
const lampIconBtn = testHostFixture.debugElement.query(By.css('button.home-button'));
108+
expect(lampIconBtn).toBeTruthy();
81109
});
82110

83111
it('should display the link to the help page', () => {
84-
const helpBtn = fixture.debugElement.query(By.css('button.help'));
85-
expect(helpBtn).toBeDefined();
112+
const helpBtn = testHostFixture.debugElement.query(By.css('button.help'));
113+
expect(helpBtn).toBeTruthy();
86114

87115
const helpBtnLabel = helpBtn.nativeElement.innerHTML;
88116
expect(helpBtnLabel).toEqual('Help');
89117
});
90118

91119
it('should display the login button', () => {
92-
const loginBtn = fixture.debugElement.query(By.css('button.login-button'));
93-
expect(loginBtn).toBeDefined();
120+
const loginBtn = testHostFixture.debugElement.query(By.css('button.login-button'));
121+
expect(loginBtn).toBeTruthy();
94122

95123
const loginBtnLabel = loginBtn.nativeElement.innerHTML;
96124
expect(loginBtnLabel).toEqual('LOGIN');
97125
});
98126

99-
it('should display fulltext-search', () => {
100-
const searchPanel = fixture.debugElement.query(By.css('dsp-fulltext-search-panel'));
101-
expect(searchPanel).toBeDefined();
127+
it('should display search panel', () => {
128+
const searchPanel = testHostFixture.debugElement.query(By.css('app-search-panel'));
129+
expect(searchPanel).toBeTruthy();
102130
});
103131

104132
it('should subscribe to component communication when the loginSuccess event is emitted', () => {
105133
componentCommsService.emit(new EmitEvent(Events.loginSuccess));
106-
fixture.detectChanges();
107-
expect(component.componentCommsSubscription.closed).toBe(false);
134+
testHostFixture.detectChanges();
135+
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(false);
108136
});
109137

110138
it('should unsubscribe from changes on destruction', () => {
111139

112-
expect(component.componentCommsSubscription.closed).toBe(false);
140+
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(false);
113141

114-
fixture.destroy();
142+
testHostFixture.destroy();
115143

116-
expect(component.componentCommsSubscription.closed).toBe(true);
144+
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(true);
117145

118146
});
119147

120148
});
149+

‎src/app/main/header/header.component.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
33
import { MatIconRegistry } from '@angular/material/icon';
44
import { DomSanitizer } from '@angular/platform-browser';
55
import { NavigationStart, Router } from '@angular/router';
6-
import { NotificationService, SearchParams, SessionService } from '@dasch-swiss/dsp-ui';
6+
import { SearchParams } from '@dasch-swiss/dsp-ui';
77
import { Subscription } from 'rxjs';
88
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
99
import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service';
10+
import { NotificationService } from '../services/notification.service';
11+
import { SessionService } from '../services/session.service';
1012

1113
const { version: appVersion } = require('../../../../package.json');
1214

‎src/app/main/help/help.component.spec.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
66
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
77
import { RouterTestingModule } from '@angular/router/testing';
88
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
9-
import { AppInitService, DspApiConfigToken, DspApiConnectionToken } from '@dasch-swiss/dsp-ui';
9+
import { AppInitService } from '@dasch-swiss/dsp-ui';
1010
import { TestConfig } from 'test.config';
11+
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
1112
import { DialogComponent } from '../dialog/dialog.component';
1213
import { ErrorComponent } from '../error/error.component';
1314
import { FooterComponent } from '../footer/footer.component';

0 commit comments

Comments
 (0)