clean unit test (#4890)

* promote use setupTestbed

* fix comment using right spy and remove deprecated moment method usage

* restore md icon file

* remove error translation log

* restore extension test
This commit is contained in:
Eugenio Romano
2019-07-02 16:00:58 +01:00
committed by GitHub
parent 87b80235a7
commit 0d6140be77
17 changed files with 208 additions and 226 deletions

View File

@@ -15,18 +15,20 @@
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { JwtHelperService } from './jwt-helper.service';
import { mockToken } from './../mock/jwt-helper.service.spec';
import { setupTestBed } from '../testing/setupTestBed';
import { TestBed } from '@angular/core/testing';
describe('JwtHelperService', () => {
let jwtHelperService: JwtHelperService;
setupTestBed({
providers: [JwtHelperService]
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [JwtHelperService]
});
jwtHelperService = TestBed.get(JwtHelperService);
});

View File

@@ -60,8 +60,10 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{ 'cm:lockType': 'READ_ONLY_LOCK',
'cm:lockLifetime': 'PERSISTENT' }
{
'cm:lockType': 'READ_ONLY_LOCK',
'cm:lockLifetime': 'PERSISTENT'
}
};
const nodeReadOnlyWithExpiredDate: Node = <Node> {
@@ -69,12 +71,12 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract('days', '4')
}
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
}
};
const nodeReadOnlyWithActiveExpiration: Node = <Node> {
@@ -82,12 +84,12 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add('days', '4')
}
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
}
};
it('should return true when readonly lock is active', () => {
@@ -109,11 +111,11 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' }
}
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' }
}
};
const nodeOwnerAllowedLockWithExpiredDate: Node = <Node> {
@@ -121,12 +123,12 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract('days', '4')
}
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().subtract(4, 'days')
}
};
const nodeOwnerAllowedLockWithActiveExpiration: Node = <Node> {
@@ -134,12 +136,12 @@ describe('PeopleProcessService', () => {
isLocked: true,
isFile: true,
properties:
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add('days', '4')
}
{
'cm:lockType': 'WRITE_LOCK',
'cm:lockLifetime': 'PERSISTENT',
'cm:lockOwner': { id: 'lock-owner-user' },
'cm:expiryDate': moment().add(4, 'days')
}
};
it('should return false when the user is the lock owner', () => {

View File

@@ -17,9 +17,10 @@
import { HttpClientModule } from '@angular/common/http';
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { LogService } from './log.service';
import { setupTestBed } from '../testing/setupTestBed';
@Component({
template: '',
@@ -61,20 +62,16 @@ describe('Log Service', () => {
let providesLogComponent: ComponentFixture<ProvidesLogComponent>;
let appConfigService: AppConfigService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule
],
declarations: [ProvidesLogComponent],
providers: [
LogService,
AppConfigService
]
});
TestBed.compileComponents();
}));
setupTestBed({
imports: [
HttpClientModule
],
declarations: [ProvidesLogComponent],
providers: [
LogService,
AppConfigService
]
});
beforeEach(() => {
appConfigService = TestBed.get(AppConfigService);

View File

@@ -18,7 +18,7 @@
import { LiveAnnouncer } from '@angular/cdk/a11y';
import { OVERLAY_PROVIDERS, OverlayModule } from '@angular/cdk/overlay';
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatSnackBar, MatSnackBarModule, MatSnackBarConfig } from '@angular/material';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -26,6 +26,7 @@ import { NotificationService } from './notification.service';
import { TranslationMock } from '../mock/translation.service.mock';
import { TranslationService } from './translation.service';
import { HttpClientModule } from '@angular/common/http';
import { setupTestBed } from '../testing/setupTestBed';
@Component({
template: '',
@@ -37,33 +38,33 @@ class ProvidesNotificationServiceComponent {
}
sendMessageWithoutConfig() {
const promise = this.notificationService.openSnackMessage('Test notification', 1000);
return promise;
return this.notificationService.openSnackMessage('Test notification', 1000);
}
sendMessage() {
const promise = this.notificationService.openSnackMessage('Test notification', 1000);
return promise;
return this.notificationService.openSnackMessage('Test notification', 1000);
}
sendCustomMessage() {
const promise = this.notificationService.openSnackMessage('Test notification', new MatSnackBarConfig());
return promise;
const matSnackBarConfig = new MatSnackBarConfig();
matSnackBarConfig.duration = 1000;
return this.notificationService.openSnackMessage('Test notification', matSnackBarConfig);
}
sendMessageActionWithoutConfig() {
const promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 1000);
return promise;
return this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 1000);
}
sendMessageAction() {
const promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 1000);
return promise;
return this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', 1000);
}
sendCustomMessageAction() {
const promise = this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', new MatSnackBarConfig());
return promise;
const matSnackBarConfig = new MatSnackBarConfig();
matSnackBarConfig.duration = 1000;
return this.notificationService.openSnackMessageAction('Test notification', 'TestWarn', matSnackBarConfig);
}
}
@@ -72,28 +73,25 @@ describe('NotificationService', () => {
let fixture: ComponentFixture<ProvidesNotificationServiceComponent>;
let translationService: TranslationService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
OverlayModule,
MatSnackBarModule,
HttpClientModule
],
declarations: [ProvidesNotificationServiceComponent],
providers: [
NotificationService,
MatSnackBar,
OVERLAY_PROVIDERS,
LiveAnnouncer,
{ provide: TranslationService, useClass: TranslationMock }
]
});
translationService = TestBed.get(TranslationService);
}));
setupTestBed({
imports: [
NoopAnimationsModule,
OverlayModule,
MatSnackBarModule,
HttpClientModule
],
declarations: [ProvidesNotificationServiceComponent],
providers: [
NotificationService,
MatSnackBar,
OVERLAY_PROVIDERS,
LiveAnnouncer,
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(() => {
translationService = TestBed.get(TranslationService);
fixture = TestBed.createComponent(ProvidesNotificationServiceComponent);
fixture.detectChanges();
});
@@ -132,7 +130,7 @@ describe('NotificationService', () => {
expect(document.querySelector('snack-bar-container')).not.toBeNull();
});
it('should open a message notification bar with custom configuration', async((done) => {
it('should open a message notification bar with custom configuration', (done) => {
const promise = fixture.componentInstance.sendCustomMessage();
promise.afterDismissed().subscribe(() => {
done();
@@ -141,7 +139,7 @@ describe('NotificationService', () => {
fixture.detectChanges();
expect(document.querySelector('snack-bar-container')).not.toBeNull();
}));
});
it('should open a message notification bar with action', (done) => {
const promise = fixture.componentInstance.sendMessageAction();
@@ -154,7 +152,7 @@ describe('NotificationService', () => {
expect(document.querySelector('snack-bar-container')).not.toBeNull();
});
it('should open a message notification bar with action and custom configuration', async((done) => {
it('should open a message notification bar with action and custom configuration', (done) => {
const promise = fixture.componentInstance.sendCustomMessageAction();
promise.afterDismissed().subscribe(() => {
done();
@@ -163,7 +161,7 @@ describe('NotificationService', () => {
fixture.detectChanges();
expect(document.querySelector('snack-bar-container')).not.toBeNull();
}));
});
it('should open a message notification bar with action and no custom configuration', (done) => {
const promise = fixture.componentInstance.sendMessageActionWithoutConfig();