Skip to content
Permalink
Browse files
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
  • Loading branch information
mdelez committed Sep 3, 2021
1 parent d793fb8 commit e7a2c4f750ed166b23753ea8e34c4f695fad83e2
Showing with 352 additions and 397 deletions.
  1. +2 −7 src/app/app.component.spec.ts
  2. +2 −8 src/app/app.module.ts
  3. +2 −1 src/app/main/cache/cache.service.spec.ts
  4. +2 −1 src/app/main/error/error-handler.service.spec.ts
  5. +3 −1 src/app/main/error/error-handler.service.ts
  6. +1 −1 src/app/main/guard/auth.guard.ts
  7. +2 −2 src/app/main/header/header.component.html
  8. +58 −29 src/app/main/header/header.component.spec.ts
  9. +3 −1 src/app/main/header/header.component.ts
  10. +2 −1 src/app/main/help/help.component.spec.ts
  11. +1 −1 src/app/main/help/help.component.ts
  12. +1 −1 src/app/main/login/login.component.html
  13. +41 −17 src/app/main/login/login.component.spec.ts
  14. +3 −1 src/app/main/main.component.spec.ts
  15. +2 −1 src/app/main/main.component.ts
  16. +2 −1 src/app/project/board/board.component.spec.ts
  17. +2 −1 src/app/project/board/board.component.ts
  18. +2 −7 src/app/project/collaboration/add-user/add-user.component.spec.ts
  19. +2 −2 src/app/project/collaboration/add-user/add-user.component.ts
  20. +2 −7 src/app/project/collaboration/collaboration.component.spec.ts
  21. +2 −2 src/app/project/collaboration/collaboration.component.ts
  22. +2 −6 src/app/project/collaboration/select-group/select-group.component.spec.ts
  23. +2 −1 src/app/project/collaboration/select-group/select-group.component.ts
  24. +5 −5 src/app/project/list/list-info-form/list-info-form.component.html
  25. +2 −5 src/app/project/list/list-info-form/list-info-form.component.spec.ts
  26. +1 −1 src/app/project/list/list-info-form/list-info-form.component.ts
  27. +5 −5 src/app/project/list/list-item-form/edit-list-item/edit-list-item.component.html
  28. +2 −1 src/app/project/list/list-item-form/edit-list-item/edit-list-item.component.spec.ts
  29. +1 −1 src/app/project/list/list-item-form/edit-list-item/edit-list-item.component.ts
  30. +6 −6 src/app/project/list/list-item-form/list-item-form.component.html
  31. +7 −5 src/app/project/list/list-item-form/list-item-form.component.spec.ts
  32. +1 −1 src/app/project/list/list-item-form/list-item-form.component.ts
  33. +2 −4 src/app/project/list/list-item/list-item.component.spec.ts
  34. +1 −1 src/app/project/list/list-item/list-item.component.ts
  35. +9 −9 src/app/project/list/list.component.html
  36. +8 −8 src/app/project/list/list.component.spec.ts
  37. +2 −1 src/app/project/list/list.component.ts
  38. +2 −7 src/app/project/ontology/ontology-form/ontology-form.component.spec.ts
  39. +2 −1 src/app/project/ontology/ontology-form/ontology-form.component.ts
  40. +2 −7 src/app/project/ontology/ontology-visualizer/ontology-visualizer.component.spec.ts
  41. +1 −1 src/app/project/ontology/ontology-visualizer/ontology-visualizer.component.ts
  42. +3 −5 src/app/project/ontology/ontology.component.spec.ts
  43. +3 −1 src/app/project/ontology/ontology.component.ts
  44. +6 −6 src/app/project/ontology/property-form/property-form.component.html
  45. +2 −1 src/app/project/ontology/property-form/property-form.component.spec.ts
  46. +2 −1 src/app/project/ontology/property-form/property-form.component.ts
  47. +2 −1 src/app/project/ontology/property-info/property-info.component.spec.ts
  48. +1 −1 src/app/project/ontology/property-info/property-info.component.ts
  49. +6 −6 src/app/project/ontology/resource-class-form/resource-class-form.component.html
  50. +13 −7 src/app/project/ontology/resource-class-form/resource-class-form.component.spec.ts
  51. +1 −1 src/app/project/ontology/resource-class-form/resource-class-form.component.ts
  52. +2 −1 src/app/project/ontology/resource-class-info/resource-class-info.component.spec.ts
  53. +2 −1 src/app/project/ontology/resource-class-info/resource-class-info.component.ts
  54. +2 −6 src/app/project/permission/permission.component.spec.ts
  55. +2 −3 src/app/project/permission/permission.component.ts
  56. +4 −4 src/app/project/project-form/project-form.component.html
  57. +2 −7 src/app/project/project-form/project-form.component.spec.ts
  58. +3 −1 src/app/project/project-form/project-form.component.ts
  59. +2 −7 src/app/project/project.component.spec.ts
  60. +2 −1 src/app/project/project.component.ts
  61. +2 −7 src/app/system/projects/projects-list/projects-list.component.spec.ts
  62. +3 −6 src/app/system/projects/projects-list/projects-list.component.ts
  63. +2 −7 src/app/system/projects/projects.component.spec.ts
  64. +2 −1 src/app/system/projects/projects.component.ts
  65. +3 −1 src/app/system/system.component.spec.ts
  66. +1 −1 src/app/system/system.component.ts
  67. +2 −7 src/app/system/users/users-list/users-list.component.spec.ts
  68. +3 −2 src/app/system/users/users-list/users-list.component.ts
  69. +2 −7 src/app/system/users/users.component.spec.ts
  70. +1 −1 src/app/system/users/users.component.ts
  71. +2 −7 src/app/user/account/account.component.spec.ts
  72. +2 −1 src/app/user/account/account.component.ts
  73. +2 −7 src/app/user/dashboard/dashboard.component.spec.ts
  74. +2 −1 src/app/user/dashboard/dashboard.component.ts
  75. +2 −7 src/app/user/membership/membership.component.spec.ts
  76. +3 −1 src/app/user/membership/membership.component.ts
  77. +2 −7 src/app/user/profile/profile.component.spec.ts
  78. +2 −1 src/app/user/profile/profile.component.ts
  79. +2 −7 src/app/user/user-form/password-form/password-form.component.spec.ts
  80. +3 −1 src/app/user/user-form/password-form/password-form.component.ts
  81. +2 −7 src/app/user/user-form/user-form.component.spec.ts
  82. +3 −1 src/app/user/user-form/user-form.component.ts
  83. +2 −7 src/app/user/user-menu/user-menu.component.spec.ts
  84. +2 −1 src/app/user/user-menu/user-menu.component.ts
  85. +2 −7 src/app/user/user.component.spec.ts
  86. +2 −1 src/app/user/user.component.ts
  87. +2 −1 src/app/workspace/intermediate/intermediate.component.spec.ts
  88. +1 −1 src/app/workspace/resource/incoming.service.spec.ts
  89. +1 −1 src/app/workspace/resource/incoming.service.ts
  90. +2 −1 src/app/workspace/resource/project.service.spec.ts
  91. +2 −1 src/app/workspace/resource/project.service.ts
  92. +1 −5 src/app/workspace/resource/properties/properties.component.spec.ts
  93. +2 −2 src/app/workspace/resource/properties/properties.component.ts
  94. +1 −1 src/app/workspace/resource/representation/upload/upload-file.service.spec.ts
  95. +1 −1 src/app/workspace/resource/representation/upload/upload-file.service.ts
  96. +1 −1 src/app/workspace/resource/representation/upload/upload.component.ts
  97. +3 −8 src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts
  98. +1 −3 src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts
  99. +2 −4 src/app/workspace/resource/resource-instance-form/select-project/select-project.component.spec.ts
  100. +3 −7 src/app/workspace/resource/resource-link-form/resource-link-form.component.spec.ts
  101. +2 −1 src/app/workspace/resource/resource-link-form/resource-link-form.component.ts
  102. +2 −7 src/app/workspace/resource/resource.component.spec.ts
  103. +4 −8 src/app/workspace/resource/resource.component.ts
  104. +2 −2 src/app/workspace/results/results.component.html
  105. +2 −7 src/app/workspace/results/results.component.spec.ts
  106. +1 −1 test.config.ts
@@ -6,16 +6,11 @@ import { MatMenuModule } from '@angular/material/menu';
import { MatToolbarModule } from '@angular/material/toolbar';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import {
AppInitService,
DspActionModule,
DspApiConfigToken,
DspApiConnectionToken,
DspSearchModule
} from '@dasch-swiss/dsp-ui';
import { AppInitService, DspActionModule, DspSearchModule } from '@dasch-swiss/dsp-ui';
import { TranslateModule } from '@ngx-translate/core';
import { TestConfig } from 'test.config';
import { AppComponent } from './app.component';
import { DspApiConfigToken, DspApiConnectionToken } from './main/declarations/dsp-api-tokens';
import { HeaderComponent } from './main/header/header.component';
import { SelectLanguageComponent } from './main/select-language/select-language.component';
import { UserMenuComponent } from './user/user-menu/user-menu.component';
@@ -7,14 +7,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import {
DspActionModule,
DspApiConfigToken,
DspApiConnectionToken,
DspCoreModule,
DspSearchModule,
DspViewerModule
} from '@dasch-swiss/dsp-ui';
import { DspActionModule, DspCoreModule, DspSearchModule, DspViewerModule } from '@dasch-swiss/dsp-ui';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { AngularSplitModule } from 'angular-split';
@@ -166,6 +159,7 @@ import { ResourceAndPropertySelectionComponent } from './workspace/search/advanc
import { SearchSelectPropertyComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/search-select-property.component';
import { SearchSelectResourceClassComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-resource-class/search-select-resource-class.component';
import { SearchSelectOntologyComponent } from './workspace/search/advanced-search/search-select-ontology/search-select-ontology.component';
import { DspApiConfigToken, DspApiConnectionToken } from './main/declarations/dsp-api-tokens';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
@@ -2,7 +2,8 @@ import { TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DspActionModule, DspApiConnectionToken, DspCoreModule } from '@dasch-swiss/dsp-ui';
import { DspActionModule, DspCoreModule } from '@dasch-swiss/dsp-ui';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { CacheService } from './cache.service';

describe('CacheService', () => {
@@ -2,7 +2,8 @@ import { TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { DspActionModule, DspApiConnectionToken, DspCoreModule } from '@dasch-swiss/dsp-ui';
import { DspActionModule, DspCoreModule } from '@dasch-swiss/dsp-ui';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { ErrorHandlerService } from './error-handler.service';

describe('ErrorHandlerService', () => {
@@ -1,8 +1,10 @@
import { Inject, Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { ApiResponseData, ApiResponseError, KnoraApiConnection, LogoutResponse } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, NotificationService, SessionService } from '@dasch-swiss/dsp-ui';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { DialogComponent } from '../dialog/dialog.component';
import { NotificationService } from '../services/notification.service';
import { SessionService } from '../services/session.service';

@Injectable({
providedIn: 'root'
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { SessionService } from '@dasch-swiss/dsp-ui';
import { SessionService } from '../services/session.service';

@Injectable({
providedIn: 'root'
@@ -13,12 +13,12 @@ <h1 class="mat-headline phone-tablet-only">DSP</h1>
<!-- search-panel (in desktop and tablet version) -->
<span class="action">
<!-- button to reactivate when dsp-app will be used as a research platform again: -->
<dsp-search-panel
<app-search-panel
[projectfilter]="true"
[advanced]="true"
[expert]="true"
(search)="doSearch($event)">
</dsp-search-panel>
</app-search-panel>

</span>

@@ -1,4 +1,5 @@
import { HttpClientModule } from '@angular/common/http';
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
@@ -8,38 +9,62 @@ import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import {
AppInitService,
DspActionModule,
DspApiConfigToken,
DspApiConnectionToken,
DspCoreModule,
DspSearchModule
} from '@dasch-swiss/dsp-ui';
import { DspActionModule, DspSearchModule } from '@dasch-swiss/dsp-ui';
import { TranslateModule } from '@ngx-translate/core';
import { AppInitService } from 'src/app/app-init.service';
import { ComponentCommunicationEventService, EmitEvent, Events } from 'src/app/main/services/component-communication-event.service';
import { UserMenuComponent } from 'src/app/user/user-menu/user-menu.component';
import { TestConfig } from 'test.config';
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { SelectLanguageComponent } from '../select-language/select-language.component';
import { HeaderComponent } from './header.component';

/**
* test host component to simulate parent component.
*/
@Component({
template: '<app-header #header></app-header>'
})
class TestHostHeaderComponent {
@ViewChild('header') headerComp: HeaderComponent;
}

/**
* test component to simulate search panel component.
*/
@Component({
selector: 'app-search-panel',
template: ''
})
class TestSearchPanelComponent {
@Input() projectfilter?: boolean = false;
@Input() filterbyproject?: string;
@Input() limitToProject?: string;
@Input() advanced?: boolean = false;
@Input() expert?: boolean = false;
}

describe('HeaderComponent', () => {
let component: HeaderComponent;
let fixture: ComponentFixture<HeaderComponent>;
let testHostComponent: TestHostHeaderComponent;
let testHostFixture: ComponentFixture<TestHostHeaderComponent>;
let hostCompDe;
let headerCompDe;

let componentCommsService: ComponentCommunicationEventService;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
HeaderComponent,
TestHostHeaderComponent,
TestSearchPanelComponent,
SelectLanguageComponent,
UserMenuComponent
],
imports: [
BrowserAnimationsModule,
HttpClientModule,
DspActionModule,
DspCoreModule,
DspSearchModule,
MatIconModule,
MatListModule,
@@ -66,55 +91,59 @@ describe('HeaderComponent', () => {
}));

beforeEach(() => {
fixture = TestBed.createComponent(HeaderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
testHostFixture = TestBed.createComponent(TestHostHeaderComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();

hostCompDe = testHostFixture.debugElement;
headerCompDe = hostCompDe.query(By.directive(HeaderComponent));
});

it('should create', () => {
expect(component).toBeTruthy();
expect(testHostComponent).toBeTruthy();
});

it('should display the lamp icon button', () => {
const lampIconBtn = fixture.debugElement.query(By.css('button.home-button'));
expect(lampIconBtn).toBeDefined();
const lampIconBtn = testHostFixture.debugElement.query(By.css('button.home-button'));
expect(lampIconBtn).toBeTruthy();
});

it('should display the link to the help page', () => {
const helpBtn = fixture.debugElement.query(By.css('button.help'));
expect(helpBtn).toBeDefined();
const helpBtn = testHostFixture.debugElement.query(By.css('button.help'));
expect(helpBtn).toBeTruthy();

const helpBtnLabel = helpBtn.nativeElement.innerHTML;
expect(helpBtnLabel).toEqual('Help');
});

it('should display the login button', () => {
const loginBtn = fixture.debugElement.query(By.css('button.login-button'));
expect(loginBtn).toBeDefined();
const loginBtn = testHostFixture.debugElement.query(By.css('button.login-button'));
expect(loginBtn).toBeTruthy();

const loginBtnLabel = loginBtn.nativeElement.innerHTML;
expect(loginBtnLabel).toEqual('LOGIN');
});

it('should display fulltext-search', () => {
const searchPanel = fixture.debugElement.query(By.css('dsp-fulltext-search-panel'));
expect(searchPanel).toBeDefined();
it('should display search panel', () => {
const searchPanel = testHostFixture.debugElement.query(By.css('app-search-panel'));
expect(searchPanel).toBeTruthy();
});

it('should subscribe to component communication when the loginSuccess event is emitted', () => {
componentCommsService.emit(new EmitEvent(Events.loginSuccess));
fixture.detectChanges();
expect(component.componentCommsSubscription.closed).toBe(false);
testHostFixture.detectChanges();
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(false);
});

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

expect(component.componentCommsSubscription.closed).toBe(false);
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(false);

fixture.destroy();
testHostFixture.destroy();

expect(component.componentCommsSubscription.closed).toBe(true);
expect(testHostComponent.headerComp.componentCommsSubscription.closed).toBe(true);

});

});

@@ -3,10 +3,12 @@ import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { NavigationStart, Router } from '@angular/router';
import { NotificationService, SearchParams, SessionService } from '@dasch-swiss/dsp-ui';
import { SearchParams } from '@dasch-swiss/dsp-ui';
import { Subscription } from 'rxjs';
import { DialogComponent } from 'src/app/main/dialog/dialog.component';
import { ComponentCommunicationEventService, Events } from 'src/app/main/services/component-communication-event.service';
import { NotificationService } from '../services/notification.service';
import { SessionService } from '../services/session.service';

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

@@ -6,8 +6,9 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { AppInitService, DspApiConfigToken, DspApiConnectionToken } from '@dasch-swiss/dsp-ui';
import { AppInitService } from '@dasch-swiss/dsp-ui';
import { TestConfig } from 'test.config';
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { DialogComponent } from '../dialog/dialog.component';
import { ErrorComponent } from '../error/error.component';
import { FooterComponent } from '../footer/footer.component';
@@ -1,6 +1,6 @@
import { Component, Inject, OnInit } from '@angular/core';
import { ApiResponseData, ApiResponseError, HealthResponse, KnoraApiConnection } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from '@dasch-swiss/dsp-ui';
import { DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { ErrorHandlerService } from '../error/error-handler.service';
import { GridItem } from '../grid/grid.component';

@@ -1,3 +1,3 @@
<div class="login-page">
<dsp-login-form (loginSuccess)="login($event)" (logoutSuccess)="logout($event)"></dsp-login-form>
<app-login-form (loginSuccess)="login($event)" (logoutSuccess)="logout($event)"></app-login-form>
</div>
@@ -1,27 +1,46 @@
import { Component } from '@angular/core';
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing';
import { KnoraApiConnection } from '@dasch-swiss/dsp-js';
import {
AppInitService,
DspActionModule,
DspApiConfigToken,
DspApiConnectionToken,
DspCoreModule
} from '@dasch-swiss/dsp-ui';
import { DspActionModule } from '@dasch-swiss/dsp-ui';
import { AppInitService } from 'src/app/app-init.service';
import { TestConfig } from 'test.config';
import { DspApiConfigToken, DspApiConnectionToken } from '../declarations/dsp-api-tokens';
import { LoginComponent } from './login.component';

/**
* test host component to simulate parent component.
*/
@Component({
template: '<app-login></app-login>'
})
class TestHostLoginComponent { }

/**
* test component to simulate child component.
*/
@Component({
selector: 'app-login-form',
template: ''
})
class TestLoginFormComponent { }

describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
let testHostComponent: TestHostLoginComponent;
let testHostFixture: ComponentFixture<TestHostLoginComponent>;
let hostCompDe;
let loginComponentDe;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [LoginComponent],
declarations: [
LoginComponent,
TestHostLoginComponent,
TestLoginFormComponent
],
imports: [
DspActionModule,
DspCoreModule,
RouterTestingModule
],
providers: [
@@ -39,18 +58,23 @@ describe('LoginComponent', () => {
}));

beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
testHostFixture = TestBed.createComponent(TestHostLoginComponent);
testHostComponent = testHostFixture.componentInstance;
testHostFixture.detectChanges();

hostCompDe = testHostFixture.debugElement;
loginComponentDe = hostCompDe.query(By.directive(LoginComponent));

expect(testHostComponent).toBeTruthy();
});

it('should create', () => {
expect(component).toBeTruthy();
expect(testHostComponent).toBeTruthy();
});

it('should define the login form', () => {
const loginForm = fixture.debugElement.query(By.css('app-login dsp-login-form'));
expect(loginForm).toBeDefined();
const loginForm = testHostFixture.debugElement.query(By.css('app-login app-login-form'));
expect(loginForm).toBeTruthy();
});

});
Loading

0 comments on commit e7a2c4f

Please sign in to comment.