unit test performance (#3194)

* DataTable (-4 sec)

* PaginationComponent (-1 sec)

* DocumentList

* custom testbed setup, test upgrades

* test fixes

* more test fixes

* remove fdescribe

* test fixes

* test fixes

* more test fixes

* test fixes

* upgrade tests

* update tests

* upgrade tests

* upgrade tests

* upgrade tests

* upgrade tests

* update tests

* translate loader fixes

* auth and cookie fixes

* upgrade tests

* upgrade tests

* test fixes

* almost there

* diable broken tests

* process tests (part 1)

* fix lint issues

* another test upgrade

* almost there

* cleanup

* insights testing upgrade

* improve tests

* tests cleanup

* tests cleanup

* cleanup tests

* test cleanup

* favorite nodes tests

* rebase fix syntax

* fix core test

* give up test focus

* flush tabs

* fix search test

* Update document-list.component.spec.ts

* fix document list lock

* increase tick time

* remove duplicate test
This commit is contained in:
Denys Vuika
2018-04-23 09:55:22 +01:00
committed by Eugenio Romano
parent 9fbfcfa96e
commit 382ea3c1b3
204 changed files with 3093 additions and 4389 deletions

View File

@@ -15,47 +15,23 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '../../../material.module';
import { MatCheckboxChange, MatCheckbox } from '@angular/material';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { MatCheckbox, MatCheckboxChange } from '@angular/material';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewBoolItemComponent } from './card-view-boolitem.component';
import { CardViewBoolItemModel } from '../../models/card-view-boolitem.model';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('CardViewBoolItemComponent', () => {
let fixture: ComponentFixture<CardViewBoolItemComponent>;
let component: CardViewBoolItemComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
FormsModule,
NoopAnimationsModule,
MaterialModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewBoolItemComponent
],
providers: [
CardViewUpdateService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(CardViewBoolItemComponent);
@@ -71,7 +47,6 @@ describe('CardViewBoolItemComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('Rendering', () => {
@@ -115,7 +90,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value).not.toBeNull();
});
it('should render ticked checkbox if property\'s value is true', () => {
it('should render ticked checkbox if property value is true', () => {
component.property.value = true;
fixture.detectChanges();
@@ -124,7 +99,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value.nativeElement.checked).toBe(true);
});
it('should render ticked checkbox if property\'s value is not set but default is true and editable', () => {
it('should render ticked checkbox if property value is not set but default is true and editable', () => {
component.editable = true;
component.property.editable = true;
component.property.value = undefined;
@@ -136,7 +111,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value.nativeElement.checked).toBe(true);
});
it('should render unticked checkbox if property\'s value is false', () => {
it('should render unticked checkbox if property value is false', () => {
component.property.value = false;
fixture.detectChanges();
@@ -145,7 +120,7 @@ describe('CardViewBoolItemComponent', () => {
expect(value.nativeElement.checked).toBe(false);
});
it('should render unticked checkbox if property\'s value is not set but default is false and editable', () => {
it('should render unticked checkbox if property value is not set but default is false and editable', () => {
component.editable = true;
component.property.editable = true;
component.property.value = undefined;
@@ -209,7 +184,7 @@ describe('CardViewBoolItemComponent', () => {
expect(cardViewUpdateService.update).toHaveBeenCalledWith(component.property, true);
});
it('should update the propery\'s value after a changed', async(() => {
it('should update the property value after a changed', async(() => {
component.property.value = true;
component.changed(<MatCheckboxChange> {checked: false});

View File

@@ -15,48 +15,23 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDatepickerModule, MatInputModule, MatNativeDateModule } from '@angular/material';
import { MatDatetimepickerModule, MatNativeDatetimeModule } from '@mat-datetimepicker/core';
import { By } from '@angular/platform-browser';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { setupTestBed } from '../../../testing/setupTestBed';
import moment from 'moment-es6';
import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewDateItemComponent } from './card-view-dateitem.component';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('CardViewDateItemComponent', () => {
let fixture: ComponentFixture<CardViewDateItemComponent>;
let component: CardViewDateItemComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
MatDatepickerModule,
MatInputModule,
MatNativeDateModule,
MatNativeDatetimeModule,
MatDatetimepickerModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewDateItemComponent
],
providers: [
CardViewUpdateService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(CardViewDateItemComponent);
@@ -73,7 +48,6 @@ describe('CardViewDateItemComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should render the label and value', () => {

View File

@@ -15,19 +15,14 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '../../../material.module';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewMapItemComponent } from './card-view-mapitem.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('CardViewMapItemComponent', () => {
let service: CardViewUpdateService;
@@ -37,28 +32,9 @@ describe('CardViewMapItemComponent', () => {
let debug: DebugElement;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
FormsModule,
NoopAnimationsModule,
MaterialModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewMapItemComponent
],
providers: [
CardViewUpdateService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(CardViewMapItemComponent);
@@ -70,7 +46,6 @@ describe('CardViewMapItemComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should render the default if the value is empty and displayEmpty is true', () => {

View File

@@ -15,49 +15,22 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { MatDatepickerModule, MatIconModule, MatInputModule, MatNativeDateModule } from '@angular/material';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewTextItemComponent } from './card-view-textitem.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('CardViewTextItemComponent', () => {
let fixture: ComponentFixture<CardViewTextItemComponent>;
let component: CardViewTextItemComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
FormsModule,
NoopAnimationsModule,
MatDatepickerModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewTextItemComponent
],
providers: [
CardViewUpdateService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(CardViewTextItemComponent);
@@ -73,7 +46,6 @@ describe('CardViewTextItemComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('Rendering', () => {

View File

@@ -16,78 +16,31 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { MatDatepickerModule, MatIconModule, MatInputModule, MatNativeDateModule } from '@angular/material';
import { MatDatetimepickerModule, MatNativeDatetimeModule } from '@mat-datetimepicker/core';
import { By } from '@angular/platform-browser';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CardViewDateItemModel } from '../../models/card-view-dateitem.model';
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { TranslateLoaderService } from '../../../services/translate-loader.service';
import { CardViewContentProxyDirective } from '../../directives/card-view-content-proxy.directive';
import { CardViewDateItemComponent } from '../card-view-dateitem/card-view-dateitem.component';
import { CardItemTypeService } from '../../services/card-item-types.service';
import { CardViewItemDispatcherComponent } from '../card-view-item-dispatcher/card-view-item-dispatcher.component';
import { CardViewTextItemComponent } from '../card-view-textitem/card-view-textitem.component';
import { CardViewComponent } from './card-view.component';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('CardViewComponent', () => {
let fixture: ComponentFixture<CardViewComponent>;
let component: CardViewComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
MatDatepickerModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatDatetimepickerModule,
MatNativeDatetimeModule,
FormsModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
CardViewComponent,
CardViewItemDispatcherComponent,
CardViewContentProxyDirective,
CardViewTextItemComponent,
CardViewDateItemComponent
],
providers: [
CardItemTypeService,
CardViewUpdateService
]
});
// entryComponents are not supported yet on TestBed, that is why this ugly workaround:
// https://github.com/angular/angular/issues/10760
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: { entryComponents: [ CardViewTextItemComponent, CardViewDateItemComponent ] }
});
TestBed.compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(CardViewComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should render the label and value', async(() => {
component.properties = [new CardViewTextItemModel({label: 'My label', value: 'My value', key: 'some key'})];
fixture.detectChanges();

View File

@@ -17,8 +17,8 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionGroupComponent } from './accordion-group.component';
import { AccordionComponent } from './accordion.component';
import { MaterialModule } from '../material.module';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('AccordionGroupComponent', () => {
@@ -26,24 +26,19 @@ describe('AccordionGroupComponent', () => {
let component: AccordionGroupComponent;
let element: any;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
AccordionGroupComponent
],
providers: [AccordionComponent]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(AccordionGroupComponent);
element = fixture.nativeElement;
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should define mat-accordion ', async(() => {

View File

@@ -15,21 +15,19 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AccordionComponent } from './accordion.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('AccordionComponent', () => {
let fixture: ComponentFixture<AccordionComponent>;
let component: AccordionComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AccordionComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(AccordionComponent);

View File

@@ -36,6 +36,9 @@ import { AccordionComponent } from './accordion.component';
exports: [
AccordionComponent,
AccordionGroupComponent
],
providers: [
AccordionComponent
]
})
export class CollapsableModule {}

View File

@@ -16,13 +16,14 @@
*/
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { DatePipe } from '@angular/common';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CommentModel, UserProcessModel } from '../models';
import { CommentListComponent } from './comment-list.component';
import { By } from '@angular/platform-browser';
import { EcmUserService } from '../userinfo/services/ecm-user.service';
import { PeopleProcessService } from '../services/people-process.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
const testUser: UserProcessModel = new UserProcessModel({
id: '1',
@@ -109,31 +110,26 @@ describe('CommentListComponent', () => {
let ecmUserService: EcmUserService;
let peopleProcessService: PeopleProcessService;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
CommentListComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
DatePipe,
PeopleProcessService,
EcmUserService
]
}).compileComponents().then(() => {
setupTestBed({
imports: [CoreTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
fixture = TestBed.createComponent(CommentListComponent);
ecmUserService = TestBed.get(EcmUserService);
peopleProcessService = TestBed.get(PeopleProcessService);
commentList = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});
beforeEach(async(() => {
ecmUserService = TestBed.get(EcmUserService);
spyOn(ecmUserService, 'getUserProfileImage').and.returnValue('content-user-image');
peopleProcessService = TestBed.get(PeopleProcessService);
spyOn(peopleProcessService, 'getUserImage').and.returnValue('process-user-image');
fixture = TestBed.createComponent(CommentListComponent);
commentList = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
}));
beforeEach(() => {
spyOn(ecmUserService, 'getUserProfileImage').and.returnValue('content-user-image');
spyOn(peopleProcessService, 'getUserImage').and.returnValue('process-user-image');
afterEach(() => {
fixture.destroy();
});
it('should emit row click event', async(() => {

View File

@@ -20,12 +20,10 @@ import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { CommentProcessService } from '../services/comment-process.service';
import { DatePipe } from '@angular/common';
import { PeopleProcessService } from '../services/people-process.service';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
import { CommentContentService } from '../services/comment-content.service';
import { EcmUserService } from '../userinfo/services/ecm-user.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('CommentsComponent', () => {
@@ -38,25 +36,10 @@ describe('CommentsComponent', () => {
let commentProcessService: CommentProcessService;
let commentContentService: CommentContentService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
],
declarations: [
CommentsComponent,
CommentListComponent
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
DatePipe,
PeopleProcessService,
CommentProcessService,
CommentContentService,
EcmUserService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(() => {
fixture = TestBed.createComponent(CommentsComponent);
@@ -87,7 +70,10 @@ describe('CommentsComponent', () => {
message: 'Test Comment',
createdBy: {id: '999'}
}));
});
afterEach(() => {
fixture.destroy();
});
it('should load comments when taskId specified', () => {

View File

@@ -15,18 +15,16 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { DataColumnListComponent } from './data-column-list.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('DataColumnListComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DataColumnListComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
it('should create the component', () => {
const fixture = TestBed.createComponent(DataColumnListComponent);

View File

@@ -15,18 +15,16 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { DataColumnComponent } from './data-column.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('DataColumnListComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DataColumnComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
it('should create the component', () => {
const fixture = TestBed.createComponent(DataColumnComponent);
@@ -34,7 +32,7 @@ describe('DataColumnListComponent', () => {
expect(component).toBeTruthy();
});
it('sould setup screen reader title for thumbnails', () => {
it('should setup screen reader title for thumbnails', () => {
const component = new DataColumnComponent();
component.key = '$thumbnail';
expect(component.srTitle).toBeFalsy();

View File

@@ -15,19 +15,17 @@
* limitations under the License.
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SimpleChange, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatCheckboxChange } from '@angular/material';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableModule } from '../../datatable.module';
import { MaterialModule } from '../../../material.module';
import { DataColumn } from '../../data/data-column.model';
import { DataRow } from '../../data/data-row.model';
import { DataSorting } from '../../data/data-sorting.model';
import { ObjectDataColumn } from '../../data/object-datacolumn.model';
import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter';
import { DataTableComponent } from './datatable.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('DataTable', () => {
@@ -35,15 +33,12 @@ describe('DataTable', () => {
let dataTable: DataTableComponent;
let element: any;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
DataTableModule,
MaterialModule
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreTestingModule
],
schemas: [ NO_ERRORS_SCHEMA ]
});
beforeEach(() => {
fixture = TestBed.createComponent(DataTableComponent);
@@ -51,6 +46,10 @@ describe('DataTable', () => {
element = fixture.debugElement.nativeElement;
});
afterEach(() => {
fixture.destroy();
});
it('should use the cardview style if cardview is true', () => {
let newData = new ObjectDataTableAdapter(
[

View File

@@ -17,21 +17,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EmptyListComponent } from './empty-list.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('EmptyListComponentComponent', () => {
let component: EmptyListComponent;
let fixture: ComponentFixture<EmptyListComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
EmptyListComponent
]
}).compileComponents();
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(EmptyListComponent);
component = fixture.componentInstance;
}));
});
afterEach(() => {
fixture.destroy();
});
it('should be defined', () => {
expect(component).toBeDefined();

View File

@@ -16,11 +16,12 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { ObjectDataTableAdapter } from './../../data/object-datatable-adapter';
import { ObjectDataColumn } from './../../data/object-datacolumn.model';
import { LocationCellComponent } from './location-cell.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreTestingModule } from '../../../testing/core.testing.module';
describe('LocationCellComponent', () => {
let component: LocationCellComponent;
@@ -29,16 +30,11 @@ describe('LocationCellComponent', () => {
let rowData;
let columnData;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
LocationCellComponent
]
}).compileComponents();
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(async(() => {
fixture = TestBed.createComponent(LocationCellComponent);
component = fixture.componentInstance;
}));
@@ -69,6 +65,10 @@ describe('LocationCellComponent', () => {
component.row = dataTableAdapter.getRows()[0];
});
afterEach(() => {
fixture.destroy();
});
it('should set displayText', () => {
fixture.detectChanges();

View File

@@ -15,44 +15,32 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableCellComponent } from '../components/datatable/datatable-cell.component';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { DataTableComponent } from '../components/datatable/datatable.component';
import { DateCellComponent } from '../components/datatable/date-cell.component';
import { FileSizeCellComponent } from '../components/datatable/filesize-cell.component';
import { LocationCellComponent } from '../components/datatable/location-cell.component';
import { MaterialModule } from '../../material.module';
import { LoadingContentTemplateDirective } from './loading-template.directive';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('LoadingContentTemplateDirective', () => {
let fixture: ComponentFixture<DataTableComponent>;
let dataTable: DataTableComponent;
let directive: LoadingContentTemplateDirective;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
DataTableComponent,
DataTableCellComponent,
LocationCellComponent,
LoadingContentTemplateDirective,
DateCellComponent,
FileSizeCellComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let fixture = TestBed.createComponent(DataTableComponent);
fixture = TestBed.createComponent(DataTableComponent);
dataTable = fixture.componentInstance;
directive = new LoadingContentTemplateDirective(dataTable);
});
afterEach(() => {
fixture.destroy();
});
it('applies template to the datatable', () => {
const template: any = 'test template';
directive.template = template;

View File

@@ -15,44 +15,32 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableCellComponent } from '../components/datatable/datatable-cell.component';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { DataTableComponent } from '../components/datatable/datatable.component';
import { DateCellComponent } from '../components/datatable/date-cell.component';
import { FileSizeCellComponent } from '../components/datatable/filesize-cell.component';
import { LocationCellComponent } from '../components/datatable/location-cell.component';
import { MaterialModule } from '../../material.module';
import { NoContentTemplateDirective } from './no-content-template.directive';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('NoContentTemplateDirective', () => {
let fixture: ComponentFixture<DataTableComponent>;
let dataTable: DataTableComponent;
let directive: NoContentTemplateDirective;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
DataTableComponent,
DataTableCellComponent,
DateCellComponent,
NoContentTemplateDirective,
LocationCellComponent,
FileSizeCellComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let fixture = TestBed.createComponent(DataTableComponent);
fixture = TestBed.createComponent(DataTableComponent);
dataTable = fixture.componentInstance;
directive = new NoContentTemplateDirective(dataTable);
});
afterEach(() => {
fixture.destroy();
});
it('applies template to the datatable', () => {
const template: any = 'test template';
directive.template = template;

View File

@@ -15,44 +15,32 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { DataTableCellComponent } from '../components/datatable/datatable-cell.component';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { DataTableComponent } from '../components/datatable/datatable.component';
import { DateCellComponent } from '../components/datatable/date-cell.component';
import { FileSizeCellComponent } from '../components/datatable/filesize-cell.component';
import { LocationCellComponent } from '../components/datatable/location-cell.component';
import { MaterialModule } from '../../material.module';
import { NoPermissionTemplateDirective } from './no-permission-template.directive';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('NoPermissionTemplateDirective', () => {
let fixture: ComponentFixture<DataTableComponent>;
let dataTable: DataTableComponent;
let directive: NoPermissionTemplateDirective;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
DataTableComponent,
DataTableCellComponent,
DateCellComponent,
NoPermissionTemplateDirective,
LocationCellComponent,
FileSizeCellComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let fixture = TestBed.createComponent(DataTableComponent);
fixture = TestBed.createComponent(DataTableComponent);
dataTable = fixture.componentInstance;
directive = new NoPermissionTemplateDirective(dataTable);
});
afterEach(() => {
fixture.destroy();
});
it('should apply template to the datatable', () => {
const template: any = 'test template';
directive.template = template;

View File

@@ -16,10 +16,12 @@
*/
import { Component, ViewChildren } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { HighlightTransformService } from '../services/highlight-transform.service';
import { HighlightDirective } from './highlight.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
const template: string = `
<div id="outerDiv1" adf-highlight adf-highlight-selector=".highlightable" adf-highlight-class="highlight-for-free-willy">
@@ -42,16 +44,14 @@ describe('HighlightDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
],
providers: [
HighlightTransformService
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
TestComponent
]
});
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);

View File

@@ -16,12 +16,13 @@
*/
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Observable } from 'rxjs/Observable';
import { AuthenticationService } from '../services';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
describe('LogoutDirective', () => {
@@ -35,16 +36,15 @@ describe('LogoutDirective', () => {
let router: Router;
let authService: AuthenticationService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
TestComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot(),
RouterTestingModule
],
declarations: [
TestComponent
]
});
beforeEach(() => {
router = TestBed.get(Router);

View File

@@ -20,6 +20,11 @@ import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NodeDeleteDirective } from './node-delete.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { TranslationService } from '../services/translation.service';
import { TranslationMock } from '../mock/translation.service.mock';
@Component({
template: `
@@ -31,9 +36,9 @@ class TestComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
onDelete = jasmine.createSpy('onDelete');
onDelete(event) {}
}
@Component({
@@ -47,7 +52,7 @@ class TestWithPermissionsComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
onDelete = jasmine.createSpy('onDelete');
}
@@ -65,14 +70,14 @@ class TestDeletePermanentComponent {
selection = [];
@ViewChild(NodeDeleteDirective)
deleteDirective;
deleteDirective: NodeDeleteDirective;
permanent = true;
onDelete = jasmine.createSpy('onDelete');
}
describe('NodeleteDirective', () => {
describe('NodeDeleteDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let fixtureWithPermissions: ComponentFixture<TestWithPermissionsComponent>;
let fixtureWithPermanentComponent: ComponentFixture<TestDeletePermanentComponent>;
@@ -85,33 +90,42 @@ describe('NodeleteDirective', () => {
let alfrescoApi: AlfrescoApiService;
let nodeApi;
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
TestComponent,
TestWithPermissionsComponent,
TestDeletePermanentComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent,
TestWithPermissionsComponent,
TestDeletePermanentComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
fixture = TestBed.createComponent(TestComponent);
fixtureWithPermissions = TestBed.createComponent(TestWithPermissionsComponent);
fixtureWithPermanentComponent = TestBed.createComponent(TestDeletePermanentComponent);
component = fixture.componentInstance;
componentWithPermissions = fixtureWithPermissions.componentInstance;
componentWithPermanentDelete = fixtureWithPermanentComponent.componentInstance;
component = fixture.componentInstance;
componentWithPermissions = fixtureWithPermissions.componentInstance;
componentWithPermanentDelete = fixtureWithPermanentComponent.componentInstance;
element = fixture.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(NodeDeleteDirective));
element = fixture.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermissions = fixtureWithPermissions.debugElement.query(By.directive(NodeDeleteDirective));
elementWithPermanentDelete = fixtureWithPermanentComponent.debugElement.query(By.directive(NodeDeleteDirective));
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.getInstance().nodes;
});
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.getInstance().nodes;
}));
afterEach(() => {
fixture.destroy();
});
describe('Delete', () => {
it('should do nothing if selection is empty', () => {
@@ -269,18 +283,19 @@ describe('NodeleteDirective', () => {
});
});
it('should emit event when delete is done', fakeAsync(() => {
component.onDelete.calls.reset();
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
it('should emit event when delete is done', (done) => {
spyOn(alfrescoApi.nodesApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = <any> [{ entry: { id: '1', name: 'name1' } }];
fixture.detectChanges();
element.nativeElement.click();
tick();
expect(component.onDelete).toHaveBeenCalled();
}));
element.nativeElement.click();
fixture.detectChanges();
component.deleteDirective.delete.subscribe(() => {
done();
});
});
it('should disable the button if no node are selected', fakeAsync(() => {
component.selection = [];
@@ -329,13 +344,13 @@ describe('NodeleteDirective', () => {
describe('Permanent', () => {
it('should call the api with permamnet delete option if permanent directive input is true', fakeAsync(() => {
it('should call the api with permanent delete option if permanent directive input is true', fakeAsync(() => {
let deleteApi = spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
fixtureWithPermanentComponent.detectChanges();
componentWithPermanentDelete.selection = [
{ entry: { id: '1', name: 'name1' }
{ entry: { id: '1', name: 'name1' } }
];
fixtureWithPermanentComponent.detectChanges();
@@ -346,7 +361,7 @@ describe('NodeleteDirective', () => {
expect(deleteApi).toHaveBeenCalledWith('1', { permanent: true });
}));
it('should call the traschan api if permanent directive input is true and the file is already in the trashcan ', fakeAsync(() => {
it('should call the trashcan api if permanent directive input is true and the file is already in the trashcan ', fakeAsync(() => {
let deleteApi = spyOn(nodeApi, 'purgeDeletedNode').and.returnValue(Promise.resolve());
fixtureWithPermanentComponent.detectChanges();

View File

@@ -96,8 +96,9 @@ export class NodeDeleteDirective implements OnChanges {
Observable.forkJoin(...batch)
.subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
this.delete.emit(this.getMessage(processedItems));
this.delete.emit(message);
});
}
}
@@ -112,9 +113,9 @@ export class NodeDeleteDirective implements OnChanges {
let promise;
if (node.entry.hasOwnProperty('archivedAt')) {
promise = this.alfrescoApiService.getInstance().nodes.purgeDeletedNode(id);
promise = this.alfrescoApiService.nodesApi.purgeDeletedNode(id);
} else {
promise = this.alfrescoApiService.getInstance().nodes.deleteNode(id, { permanent: this.permanent });
promise = this.alfrescoApiService.nodesApi.deleteNode(id, { permanent: this.permanent });
}
return Observable.fromPromise(promise)

View File

@@ -15,97 +15,71 @@
* limitations under the License.
*/
import { Component, DebugElement } from '@angular/core';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { SimpleChange } from '@angular/core';
import { fakeAsync, tick } from '@angular/core/testing';
import { NodeFavoriteDirective } from './node-favorite.directive';
@Component({
template: `
<div [adf-node-favorite]="selection"
(toggle)="done()">
</div>`
})
class TestComponent {
selection;
done = jasmine.createSpy('done');
}
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { AppConfigService, StorageService } from '@alfresco/adf-core';
describe('NodeFavoriteDirective', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
let element: DebugElement;
let directiveInstance;
let apiService;
let favoritesApi;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
TestComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeFavoriteDirective));
directiveInstance = element.injector.get(NodeFavoriteDirective);
let directive;
let alfrescoApiService;
apiService = TestBed.get(AlfrescoApiService);
favoritesApi = apiService.getInstance().core.favoritesApi;
});
}));
beforeEach(() => {
alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
directive = new NodeFavoriteDirective( alfrescoApiService);
});
describe('selection input change event', () => {
it('should not call markFavoritesNodes() if input list is empty', () => {
spyOn(directiveInstance, 'markFavoritesNodes');
spyOn(directive, 'markFavoritesNodes');
component.selection = [];
const change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
fixture.detectChanges();
expect(directiveInstance.markFavoritesNodes).not.toHaveBeenCalledWith();
expect(directive.markFavoritesNodes).not.toHaveBeenCalledWith();
});
it('should call markFavoritesNodes() on input change', () => {
spyOn(directiveInstance, 'markFavoritesNodes');
spyOn(directive, 'markFavoritesNodes');
component.selection = [{ entry: { id: '1', name: 'name1' } }];
let selection = [{ entry: { id: '1', name: 'name1' } }];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.markFavoritesNodes).toHaveBeenCalledWith(component.selection);
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
component.selection = [
selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '1', name: 'name1' } }
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.markFavoritesNodes).toHaveBeenCalledWith(component.selection);
expect(directive.markFavoritesNodes).toHaveBeenCalledWith(selection);
});
it('should reset favorites if selection is empty', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.hasFavorites()).toBe(true);
expect(directive.hasFavorites()).toBe(true);
component.selection = [];
fixture.detectChanges();
change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.hasFavorites()).toBe(false);
expect(directive.hasFavorites()).toBe(false);
}));
});
@@ -113,76 +87,78 @@ describe('NodeFavoriteDirective', () => {
let favoritesApiSpy;
beforeEach(() => {
favoritesApiSpy = spyOn(favoritesApi, 'getFavorite');
favoritesApiSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite')
.and.returnValue(Promise.resolve());
});
it('should check each selected node if it is a favorite', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(favoritesApiSpy.calls.count()).toBe(2);
}));
it('should not check processed node when another is unselected', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.favorites.length).toBe(2);
tick();
expect(directive.favorites.length).toBe(2);
expect(favoritesApiSpy.calls.count()).toBe(2);
favoritesApiSpy.calls.reset();
component.selection = [
selection = [
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
tick();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
expect(directiveInstance.favorites.length).toBe(1);
tick();
expect(directive.favorites.length).toBe(1);
expect(favoritesApiSpy).not.toHaveBeenCalled();
}));
it('should not check processed nodes when another is selected', fakeAsync(() => {
favoritesApiSpy.and.returnValue(Promise.resolve());
component.selection = [
let selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites.length).toBe(2);
expect(directive.favorites.length).toBe(2);
expect(favoritesApiSpy.calls.count()).toBe(2);
favoritesApiSpy.calls.reset();
component.selection = [
selection = [
{ entry: { id: '1', name: 'name1' } },
{ entry: { id: '2', name: 'name2' } },
{ entry: { id: '3', name: 'name3' } }
];
fixture.detectChanges();
change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites.length).toBe(3);
expect(directive.favorites.length).toBe(3);
expect(favoritesApiSpy.calls.count()).toBe(1);
}));
});
@@ -192,8 +168,8 @@ describe('NodeFavoriteDirective', () => {
let addFavoriteSpy;
beforeEach(() => {
removeFavoriteSpy = spyOn(favoritesApi, 'removeFavoriteSite');
addFavoriteSpy = spyOn(favoritesApi, 'addFavorite');
removeFavoriteSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'removeFavoriteSite');
addFavoriteSpy = spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'addFavorite');
});
afterEach(() => {
@@ -201,170 +177,172 @@ describe('NodeFavoriteDirective', () => {
addFavoriteSpy.calls.reset();
});
it('should not perform action if favorites collection is empty', () => {
component.selection = [];
it('should not perform action if favorites collection is empty', fakeAsync(() => {
let change = new SimpleChange(null, [], true);
directive.ngOnChanges({'selection': change});
tick();
fixture.detectChanges();
element.triggerEventHandler('click', null);
directive.toggleFavorite();
expect(removeFavoriteSpy).not.toHaveBeenCalled();
expect(addFavoriteSpy).not.toHaveBeenCalled();
});
}));
it('should call addFavorite() if none is a favorite', fakeAsync(() => {
it('should call addFavorite() if none is a favorite', () => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } },
{ entry: { id: '2', name: 'name2', isFavorite: false } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
expect(addFavoriteSpy.calls.argsFor(0)[1].length).toBe(2);
}));
});
it('should call addFavorite() on node that is not a favorite in selection', fakeAsync(() => {
it('should call addFavorite() on node that is not a favorite in selection', () => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFile: true, isFolder: false, isFavorite: false } },
{ entry: { id: '2', name: 'name2', isFile: true, isFolder: false, isFavorite: true } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
const callArgs = addFavoriteSpy.calls.argsFor(0)[1];
const callParameter = callArgs[0];
expect(callArgs.length).toBe(1);
expect(callParameter.target.file.guid).toBe('1');
}));
});
it('should call removeFavoriteSite() if all are favorites', fakeAsync(() => {
it('should call removeFavoriteSite() if all are favorites', () => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: true } }
];
element.triggerEventHandler('click', null);
tick();
directive.toggleFavorite();
expect(removeFavoriteSpy.calls.count()).toBe(2);
}));
});
it('should emit event when removeFavoriteSite() is done', fakeAsync(() => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
spyOn(directive.toggle, 'emit');
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(component.done).toHaveBeenCalled();
expect(directive.toggle.emit).toHaveBeenCalled();
}));
it('should emit event when addFavorite() is done', fakeAsync(() => {
addFavoriteSpy.and.returnValue(Promise.resolve());
spyOn(directive.toggle, 'emit');
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(component.done).toHaveBeenCalled();
expect(directive.toggle.emit).toHaveBeenCalled();
}));
it('should set isFavorites items to false', fakeAsync(() => {
removeFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(directiveInstance.hasFavorites()).toBe(false);
expect(directive.hasFavorites()).toBe(false);
}));
it('should set isFavorites items to true', fakeAsync(() => {
addFavoriteSpy.and.returnValue(Promise.resolve());
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: false } }
];
element.triggerEventHandler('click', null);
directive.toggleFavorite();
tick();
expect(directiveInstance.hasFavorites()).toBe(true);
expect(directive.hasFavorites()).toBe(true);
}));
});
describe('getFavorite()', () => {
it('should process node as favorite', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.resolve());
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites[0].entry.isFavorite).toBe(true);
expect(directive.favorites[0].entry.isFavorite).toBe(true);
}));
it('should not process node as favorite', fakeAsync(() => {
spyOn(favoritesApi, 'getFavorite').and.returnValue(Promise.reject(null));
spyOn(alfrescoApiService.getInstance().core.favoritesApi, 'getFavorite').and.returnValue(Promise.reject({}));
component.selection = [
const selection = [
{ entry: { id: '1', name: 'name1' } }
];
fixture.detectChanges();
let change = new SimpleChange(null, selection, true);
directive.ngOnChanges({'selection': change});
tick();
expect(directiveInstance.favorites[0].entry.isFavorite).toBe(false);
expect(directive.favorites[0].entry.isFavorite).toBe(false);
}));
});
describe('hasFavorites()', () => {
it('should return false when favorites collection is empty', () => {
directiveInstance.favorites = [];
directive.favorites = [];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(false);
});
it('should return false when some are not favorite', () => {
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: false } }
];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(false);
});
it('return true when all are favorite', () => {
directiveInstance.favorites = [
directive.favorites = [
{ entry: { id: '1', name: 'name1', isFavorite: true } },
{ entry: { id: '2', name: 'name2', isFavorite: true } }
];
const hasFavorites = directiveInstance.hasFavorites();
const hasFavorites = directive.hasFavorites();
expect(hasFavorites).toBe(true);
});

View File

@@ -29,7 +29,7 @@ import 'rxjs/observable/forkJoin';
exportAs: 'adfFavorite'
})
export class NodeFavoriteDirective implements OnChanges {
private favorites: any[] = [];
favorites: any[] = [];
/** Array of nodes to toggle as favorites. */
@Input('adf-node-favorite')
@@ -68,7 +68,7 @@ export class NodeFavoriteDirective implements OnChanges {
// shared files have nodeId
const id = selected.entry.nodeId || selected.entry.id;
return Observable.fromPromise(this.alfrescoApiService.getInstance().core.favoritesApi.removeFavoriteSite('-me-', id));
return Observable.fromPromise(this.alfrescoApiService.favoritesApi.removeFavoriteSite('-me-', id));
});
Observable.forkJoin(batch).subscribe(() => {
@@ -81,7 +81,7 @@ export class NodeFavoriteDirective implements OnChanges {
const notFavorite = this.favorites.filter((node) => !node.entry.isFavorite);
const body: FavoriteBody[] = notFavorite.map((node) => this.createFavoriteBody(node));
Observable.fromPromise(this.alfrescoApiService.getInstance().core.favoritesApi.addFavorite('-me-', <any> body))
Observable.fromPromise(this.alfrescoApiService.favoritesApi.addFavorite('-me-', <any> body))
.subscribe(() => {
notFavorite.map(selected => selected.entry.isFavorite = true);
this.toggle.emit();
@@ -98,7 +98,9 @@ export class NodeFavoriteDirective implements OnChanges {
const result = this.diff(selection, this.favorites);
const batch = this.getProcessBatch(result);
Observable.forkJoin(batch).subscribe((data) => this.favorites.push(...data));
Observable.forkJoin(batch).subscribe((data) => {
this.favorites.push(...data);
});
}
hasFavorites(): boolean {
@@ -118,8 +120,7 @@ export class NodeFavoriteDirective implements OnChanges {
// shared files have nodeId
const id = (<any> selected).entry.nodeId || selected.entry.id;
const promise = this.alfrescoApiService.getInstance()
.core.favoritesApi.getFavorite('-me-', id);
const promise = this.alfrescoApiService.favoritesApi.getFavorite('-me-', id);
return Observable.from(promise)
.map(() => ({

View File

@@ -25,7 +25,9 @@ import { TranslationService } from '../services';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { NotificationService } from '../services/notification.service';
import { NodeRestoreDirective } from './node-restore.directive';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
@Component({
template: `
<div [adf-restore]="selection"
@@ -50,29 +52,31 @@ describe('NodeRestoreDirective', () => {
let coreApi;
let directiveInstance;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
declarations: [
TestComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
directiveInstance = element.injector.get(NodeRestoreDirective);
setupTestBed({
imports: [
CoreModule.forRoot(),
RouterTestingModule
],
declarations: [
TestComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
alfrescoService = TestBed.get(AlfrescoApiService);
nodesService = alfrescoService.getInstance().nodes;
coreApi = alfrescoService.getInstance().core;
translation = TestBed.get(TranslationService);
notification = TestBed.get(NotificationService);
router = TestBed.get(Router);
});
beforeEach(async(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
element = fixture.debugElement.query(By.directive(NodeRestoreDirective));
directiveInstance = element.injector.get(NodeRestoreDirective);
alfrescoService = TestBed.get(AlfrescoApiService);
nodesService = alfrescoService.getInstance().nodes;
coreApi = alfrescoService.getInstance().core;
translation = TestBed.get(TranslationService);
notification = TestBed.get(NotificationService);
router = TestBed.get(Router);
}));
beforeEach(() => {

View File

@@ -15,18 +15,14 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../../material.module';
import { ErrorWidgetComponent } from '../widgets/error/error.component';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormRenderingService } from './../../services/form-rendering.service';
import { WidgetVisibilityService } from './../../services/widget-visibility.service';
import { FormFieldModel, FormFieldTypes, FormModel } from './../widgets/core/index';
import { InputMaskDirective } from './../widgets/text/text-mask.component';
import { TextWidgetComponent, CheckboxWidgetComponent, WidgetComponent } from '../widgets/index';
import { TextWidgetComponent, CheckboxWidgetComponent } from '../widgets/index';
import { FormFieldComponent } from './form-field.component';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { FormService } from '../../services/form.service';
import { EcmModelService } from '../../services/ecm-model.service';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreModule } from '../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('FormFieldComponent', () => {
@@ -36,35 +32,12 @@ describe('FormFieldComponent', () => {
let formRenderingService: FormRenderingService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
FormFieldComponent,
WidgetComponent,
TextWidgetComponent,
CheckboxWidgetComponent,
InputMaskDirective,
ErrorWidgetComponent],
providers: [
FormRenderingService,
WidgetVisibilityService,
FormService,
EcmModelService
]
});
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [WidgetComponent, TextWidgetComponent, CheckboxWidgetComponent]
}
});
TestBed.compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(FormFieldComponent);

View File

@@ -16,14 +16,13 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslationService } from '../../index';
import { DataTableModule } from '../../datatable/datatable.module';
import { DataColumnModule } from '../../data-column/data-column.module';
import { TranslationService, TranslationMock } from '../../index';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../services/ecm-model.service';
import { FormService } from '../services/form.service';
import { FormListComponent } from './form-list.component';
import { MaterialModule } from '../../material.module';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('TaskAttachmentList', () => {
@@ -32,28 +31,15 @@ describe('TaskAttachmentList', () => {
let service: FormService;
let element: any;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
DataColumnModule,
DataTableModule,
MaterialModule
],
declarations: [
FormListComponent
],
providers: [
FormService,
EcmModelService
]
}).compileComponents();
let translateService = TestBed.get(TranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub();
spyOn(translateService, 'get').and.callFake((key) => {
return Observable.of(key);
});
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(async(() => {

View File

@@ -19,15 +19,17 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { SimpleChange } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { FormModule } from '../../index';
import { formDefinitionDropdownField, formDefinitionTwoTextFields } from '../../mock';
import { formReadonlyTwoTextFields } from '../../mock';
import { formDefVisibilitiFieldDependsOnNextOne, formDefVisibilitiFieldDependsOnPreviousOne } from '../../mock';
import { FormService } from './../services/form.service';
import { FormComponent } from './form.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
/** Duration of the select opening animation. */
const SELECT_OPEN_ANIMATION = 200;
@@ -35,7 +37,7 @@ const SELECT_OPEN_ANIMATION = 200;
/** Duration of the select closing animation and the timeout interval for the backdrop. */
const SELECT_CLOSE_ANIMATION = 500;
describe('FormComponent UI and visibiltiy', () => {
describe('FormComponent UI and visibility', () => {
let component: FormComponent;
let service: FormService;
let fixture: ComponentFixture<FormComponent>;
@@ -47,19 +49,18 @@ describe('FormComponent UI and visibiltiy', () => {
fixture.detectChanges();
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(() => {
fixture = TestBed.createComponent(FormComponent);
component = fixture.componentInstance;
service = fixture.debugElement.injector.get(FormService);
service = TestBed.get(FormService);
});
afterEach(() => {

View File

@@ -18,22 +18,17 @@
import { CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { EntryComponentMockModule } from '../../mock/form/entry-module.mock';
import { startFormDateWidgetMock, startFormDropdownDefinitionMock, startFormTextDefinitionMock, startMockForm, startMockFormWithTab } from '../../mock';
import { startFormAmountWidgetMock, startFormNumberWidgetMock, startFormRadioButtonWidgetMock } from '../../mock';
import { EcmModelService } from './../services/ecm-model.service';
import { FormRenderingService } from './../services/form-rendering.service';
import { FormService } from './../services/form.service';
import { WidgetVisibilityService } from './../services/widget-visibility.service';
import { FormFieldComponent } from './form-field/form-field.component';
import { MaterialModule } from '../../material.module';
import { StartFormComponent } from './start-form.component';
import { ContentWidgetComponent } from './widgets/content/content.widget';
import { MASK_DIRECTIVE } from './widgets/index';
import { WIDGET_DIRECTIVES } from './widgets/index';
import { FormModel, FormOutcomeModel } from './widgets/index';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('ActivitiStartForm', () => {
describe('StartFormComponent', () => {
let formService: FormService;
let component: StartFormComponent;
@@ -44,34 +39,19 @@ describe('ActivitiStartForm', () => {
const exampleId1 = 'my:process1';
const exampleId2 = 'my:process2';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule,
EntryComponentMockModule
],
declarations: [
StartFormComponent,
FormFieldComponent,
ContentWidgetComponent,
...WIDGET_DIRECTIVES,
...MASK_DIRECTIVE
],
providers: [
EcmModelService,
FormService,
FormRenderingService,
WidgetVisibilityService
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
beforeEach(() => {
fixture = TestBed.createComponent(StartFormComponent);
component = fixture.componentInstance;
formService = fixture.debugElement.injector.get(FormService);
formService = TestBed.get(FormService);
visibilityService = TestBed.get(WidgetVisibilityService);
getStartFormSpy = spyOn(formService, 'getStartFormDefinition').and.returnValue(Observable.of({

View File

@@ -15,36 +15,24 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../../../material.module';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormFieldModel } from './../core/form-field.model';
import { AmountWidgetComponent } from './amount.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('AmountWidgetComponent', () => {
let widget: AmountWidgetComponent;
let fixture: ComponentFixture<AmountWidgetComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
AmountWidgetComponent,
ErrorWidgetComponent
],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(AmountWidgetComponent);
@@ -52,7 +40,7 @@ describe('AmountWidgetComponent', () => {
widget = fixture.componentInstance;
});
it('should setup currentcy from field', () => {
it('should setup currency from field', () => {
const currency = 'UAH';
widget.field = new FormFieldModel(null, {
currency: currency

View File

@@ -15,41 +15,29 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../../../material.module';
import { WIDGET_DIRECTIVES } from '../index';
import { MASK_DIRECTIVE } from '../index';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { FormFieldComponent } from './../../form-field/form-field.component';
import { ContentWidgetComponent } from './../content/content.widget';
import { ContainerColumnModel } from './../core/container-column.model';
import { FormFieldTypes } from './../core/form-field-types';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
import { ContainerWidgetComponent } from './container.widget';
import { ContainerWidgetComponentModel } from './container.widget.model';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('ContainerWidgetComponent', () => {
let widget: ContainerWidgetComponent;
let fixture: ComponentFixture<ContainerWidgetComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [FormFieldComponent, ContentWidgetComponent, WIDGET_DIRECTIVES, MASK_DIRECTIVE],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(ContainerWidgetComponent);

View File

@@ -17,16 +17,17 @@
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../../../material.module';
import { By } from '@angular/platform-browser';
import { TranslationService, ContentService } from '../../../../services';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../../../services/ecm-model.service';
import { FormService } from '../../../services/form.service';
import { ProcessContentService } from '../../../services/process-content.service';
import { ContentLinkModel } from '../index';
import { ContentWidgetComponent } from './content.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslationMock } from '../../../../mock/translation.service.mock';
declare let jasmine: any;
@@ -62,30 +63,19 @@ describe('ContentWidgetComponent', () => {
return new Blob([pdfData], {type: 'application/pdf'});
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
ContentWidgetComponent
],
providers: [
FormService,
EcmModelService,
ContentService,
ProcessContentService
]
}).compileComponents();
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(async(() => {
serviceContent = TestBed.get(ContentService);
processContentService = TestBed.get(ProcessContentService);
let translateService = TestBed.get(TranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub();
spyOn(translateService, 'get').and.callFake((key) => {
return Observable.of(key);
});
}));
beforeEach(() => {

View File

@@ -17,14 +17,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import moment from 'moment-es6';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { MaterialModule } from '../../../../material.module';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
import { DateTimeWidgetComponent } from './date-time.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('DateTimeWidgetComponent', () => {
@@ -32,22 +30,12 @@ describe('DateTimeWidgetComponent', () => {
let fixture: ComponentFixture<DateTimeWidgetComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
DateTimeWidgetComponent,
ErrorWidgetComponent
],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(DateTimeWidgetComponent);
@@ -58,7 +46,6 @@ describe('DateTimeWidgetComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
it('should setup min value for date picker', () => {

View File

@@ -17,14 +17,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import moment from 'moment-es6';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { MaterialModule } from '../../../../material.module';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
import { DateWidgetComponent } from './date.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('DateWidgetComponent', () => {
@@ -32,22 +30,12 @@ describe('DateWidgetComponent', () => {
let fixture: ComponentFixture<DateWidgetComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
DateWidgetComponent,
ErrorWidgetComponent
],
providers: [
FormService,
ActivitiContentService,
EcmModelService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(DateWidgetComponent);

View File

@@ -18,15 +18,15 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../../../services/ecm-model.service';
import { FormService } from '../../../services/form.service';
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
import { MaterialModule } from '../../../../material.module';
import { ErrorWidgetComponent } from '../error/error.component';
import { FormFieldOption } from './../core/form-field-option';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
import { DropdownWidgetComponent } from './dropdown.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('DropdownWidgetComponent', () => {
@@ -47,21 +47,20 @@ describe('DropdownWidgetComponent', () => {
{ id: 'opt_2', name: 'option_2' },
{ id: 'opt_3', name: 'option_3' }];
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [DropdownWidgetComponent, ErrorWidgetComponent],
providers: [FormService, EcmModelService, WidgetVisibilityService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(DropdownWidgetComponent);
widget = fixture.componentInstance;
element = fixture.nativeElement;
formService = TestBed.get(FormService);
visibilityService = TestBed.get(WidgetVisibilityService);
widget.field = new FormFieldModel(new FormModel());
});
fixture = TestBed.createComponent(DropdownWidgetComponent);
widget = fixture.componentInstance;
element = fixture.nativeElement;
formService = TestBed.get(FormService);
visibilityService = TestBed.get(WidgetVisibilityService);
widget.field = new FormFieldModel(new FormModel());
}));
it('should require field with restUrl', () => {

View File

@@ -17,23 +17,15 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LogService } from '../../../../services';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
import { MaterialModule } from '../../../../material.module';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { FormFieldModel, FormFieldTypes, FormModel } from './../core/index';
import { DynamicTableColumn } from './dynamic-table-column.model';
import { DynamicTableRow } from './dynamic-table-row.model';
import { DynamicTableWidgetComponent } from './dynamic-table.widget';
import { DynamicTableModel } from './dynamic-table.widget.model';
import { BooleanEditorComponent } from './editors/boolean/boolean.editor';
import { DateEditorComponent } from './editors/date/date.editor';
import { DropdownEditorComponent } from './editors/dropdown/dropdown.editor';
import { RowEditorComponent } from './editors/row.editor';
import { TextEditorComponent } from './editors/text/text.editor';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
let fakeFormField = {
id: 'fake-dynamic-table',
@@ -85,23 +77,12 @@ describe('DynamicTableWidgetComponent', () => {
let logService: LogService;
let formService: FormService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [DynamicTableWidgetComponent, RowEditorComponent,
DropdownEditorComponent, DateEditorComponent, BooleanEditorComponent,
TextEditorComponent, ErrorWidgetComponent],
providers: [
FormService,
LogService,
ActivitiContentService,
EcmModelService,
WidgetVisibilityService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
const field = new FormFieldModel(new FormModel());

View File

@@ -15,15 +15,16 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import moment from 'moment-es6';
import { MaterialModule } from '../../../../../../material.module';
import { FormFieldModel, FormModel } from '../../../index';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { DateEditorComponent } from './date.editor';
import { setupTestBed } from '../../../../../../testing/setupTestBed';
import { CoreModule } from '../../../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('DateEditorComponent', () => {
let component: DateEditorComponent;
@@ -32,16 +33,12 @@ describe('DateEditorComponent', () => {
let column: DynamicTableColumn;
let table: DynamicTableModel;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
DateEditorComponent
],
imports: [
MaterialModule
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(DateEditorComponent);

View File

@@ -18,16 +18,16 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../../../../../services/ecm-model.service';
import { MaterialModule } from '../../../../../../material.module';
import { FormService } from './../../../../../services/form.service';
import { FormFieldModel, FormModel } from './../../../core/index';
import { DynamicTableColumnOption } from './../../dynamic-table-column-option.model';
import { DynamicTableColumn } from './../../dynamic-table-column.model';
import { DynamicTableRow } from './../../dynamic-table-row.model';
import { DynamicTableModel } from './../../dynamic-table.widget.model';
import { DropdownEditorComponent } from './dropdown.editor';
import { setupTestBed } from '../../../../../../testing/setupTestBed';
import { CoreModule } from '../../../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('DropdownEditorComponent', () => {
@@ -38,6 +38,13 @@ describe('DropdownEditorComponent', () => {
let column: DynamicTableColumn;
let row: DynamicTableRow;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
formService = new FormService(null, null, null);
@@ -190,20 +197,13 @@ describe('DropdownEditorComponent', () => {
let dynamicTable: DynamicTableModel;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MaterialModule],
declarations: [DropdownEditorComponent],
providers: [FormService, EcmModelService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(DropdownEditorComponent);
dropDownEditorComponent = fixture.componentInstance;
element = fixture.nativeElement;
});
fixture = TestBed.createComponent(DropdownEditorComponent);
dropDownEditorComponent = fixture.componentInstance;
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('and dropdown is populated via taskId', () => {

View File

@@ -19,15 +19,14 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { UserProcessModel } from '../../../../models';
import { Observable } from 'rxjs/Observable';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { FormService } from '../../../services/form.service';
import { MaterialModule } from '../../../../material.module';
import { FormFieldTypes } from '../core/form-field-types';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { PeopleWidgetComponent } from './people.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('PeopleWidgetComponent', () => {
@@ -36,22 +35,12 @@ describe('PeopleWidgetComponent', () => {
let element: HTMLElement;
let formService: FormService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
PeopleWidgetComponent,
ErrorWidgetComponent
],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(PeopleWidgetComponent);

View File

@@ -17,23 +17,29 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../../../services/ecm-model.service';
import { FormService } from '../../../services/form.service';
import { MaterialModule } from '../../../../material.module';
import { ContainerModel } from '../core/container.model';
import { FormFieldTypes } from '../core/form-field-types';
import { ErrorWidgetComponent } from '../error/error.component';
import { FormFieldOption } from './../core/form-field-option';
import { FormFieldModel } from './../core/form-field.model';
import { FormModel } from './../core/form.model';
import { RadioButtonsWidgetComponent } from './radio-buttons.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('RadioButtonsWidgetComponent', () => {
let formService: FormService;
let widget: RadioButtonsWidgetComponent;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
formService = new FormService(null, null, null);
widget = new RadioButtonsWidgetComponent(formService, null);
@@ -134,20 +140,13 @@ describe('RadioButtonsWidgetComponent', () => {
}];
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MaterialModule ],
declarations: [RadioButtonsWidgetComponent, ErrorWidgetComponent],
providers: [FormService, EcmModelService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(RadioButtonsWidgetComponent);
radioButtonWidget = fixture.componentInstance;
element = fixture.nativeElement;
});
fixture = TestBed.createComponent(RadioButtonsWidgetComponent);
radioButtonWidget = fixture.componentInstance;
element = fixture.nativeElement;
}));
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('and radioButton is populated via taskId', () => {

View File

@@ -15,22 +15,31 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { fakeFormJson } from '../../../../mock';
import { MaterialModule } from '../../../../material.module';
import { tick, fakeAsync, async, ComponentFixture, TestBed, flush } from '@angular/core/testing';
import { fakeFormJson, TranslationMock } from '../../../../mock';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
import { TabModel } from '../core/tab.model';
import { WIDGET_DIRECTIVES } from '../index';
import { MASK_DIRECTIVE } from '../index';
import { FormFieldComponent } from './../../form-field/form-field.component';
import { ContentWidgetComponent } from './../content/content.widget';
import { TabsWidgetComponent } from './tabs.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { TranslationService } from '../../../../services/translation.service';
describe('TabsWidgetComponent', () => {
let widget: TabsWidgetComponent;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: TranslationService, useClass: TranslationMock }
]
});
beforeEach(() => {
widget = new TabsWidgetComponent();
});
@@ -56,7 +65,7 @@ describe('TabsWidgetComponent', () => {
});
it('should remove invisible tabs', () => {
let fakeTab = new TabModel(null, {id: 'fake-tab-id', title: 'fake-tab-title'});
let fakeTab = new TabModel(null, { id: 'fake-tab-id', title: 'fake-tab-title' });
fakeTab.isVisible = false;
widget.tabs.push(fakeTab);
widget.ngAfterContentChecked();
@@ -65,7 +74,7 @@ describe('TabsWidgetComponent', () => {
});
it('should leave visible tabs', () => {
let fakeTab = new TabModel(null, {id: 'fake-tab-id', title: 'fake-tab-title'});
let fakeTab = new TabModel(null, { id: 'fake-tab-id', title: 'fake-tab-title' });
fakeTab.isVisible = true;
widget.tabs.push(fakeTab);
widget.ngAfterContentChecked();
@@ -84,59 +93,66 @@ describe('TabsWidgetComponent', () => {
let fakeTabInvisible: TabModel;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MaterialModule ],
declarations: [FormFieldComponent, ContentWidgetComponent, WIDGET_DIRECTIVES, MASK_DIRECTIVE]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(TabsWidgetComponent);
tabWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
fixture = TestBed.createComponent(TabsWidgetComponent);
tabWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
fakeTabVisible = new TabModel(new FormModel(fakeFormJson), {
id: 'tab-id-visible',
title: 'tab-title-visible'
});
fakeTabVisible.isVisible = true;
fakeTabInvisible = new TabModel(new FormModel(fakeFormJson), {
id: 'tab-id-invisible',
title: 'tab-title-invisible'
});
fakeTabInvisible.isVisible = false;
tabWidgetComponent.tabs.push(fakeTabVisible);
tabWidgetComponent.tabs.push(fakeTabInvisible);
fakeTabVisible = new TabModel(new FormModel(fakeFormJson), {
id: 'tab-id-visible',
title: 'tab-title-visible'
});
fakeTabVisible.isVisible = true;
fakeTabInvisible = new TabModel(new FormModel(fakeFormJson), {
id: 'tab-id-invisible',
title: 'tab-title-invisible'
});
fakeTabInvisible.isVisible = false;
tabWidgetComponent.tabs.push(fakeTabVisible);
tabWidgetComponent.tabs.push(fakeTabInvisible);
}));
it('should show only visible tabs', () => {
it('should show only visible tabs', fakeAsync(() => {
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.innerText).toContain('tab-title-visible');
});
});
it('should show tab when it became visible', async(() => {
tick(500);
expect(element.innerText).toContain('tab-title-visible');
}));
it('should show tab when it became visible', fakeAsync(() => {
fakeTabInvisible.isVisible = false;
fixture.detectChanges();
tick(500);
tabWidgetComponent.formTabChanged.subscribe((res) => {
tabWidgetComponent.tabs[1].isVisible = true;
tick(500);
flush();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.innerText).toContain('tab-title-invisible');
});
expect(element.innerText).toContain('tab-title-invisible');
});
tabWidgetComponent.tabChanged(null);
}));
it('should hide tab when it became not visible', async(() => {
it('should hide tab when it became not visible', fakeAsync(() => {
fixture.detectChanges();
tick(500);
tabWidgetComponent.formTabChanged.subscribe((res) => {
tabWidgetComponent.tabs[0].isVisible = false;
tick(500);
flush();
fixture.detectChanges();
fixture.whenStable()
.then(() => {
expect(element.querySelector('innerText')).not.toContain('tab-title-visible');
});
expect(element.querySelector('innerText')).not.toContain('tab-title-visible');
});
tabWidgetComponent.tabChanged(null);
}));

View File

@@ -19,14 +19,10 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormFieldTypes } from '../core/form-field-types';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
import { InputMaskDirective } from './text-mask.component';
import { TextWidgetComponent } from './text.widget';
import { ActivitiContentService } from '../../../services/activiti-alfresco.service';
import { MaterialModule } from '../../../../material.module';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { FormService } from './../../../services/form.service';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('TextWidgetComponent', () => {
@@ -34,23 +30,12 @@ describe('TextWidgetComponent', () => {
let fixture: ComponentFixture<TextWidgetComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
TextWidgetComponent,
ErrorWidgetComponent,
InputMaskDirective
],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(TextWidgetComponent);

View File

@@ -19,21 +19,28 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { By } from '@angular/platform-browser';
import { EcmModelService } from '../../../services/ecm-model.service';
import { FormService } from '../../../services/form.service';
import { MaterialModule } from '../../../../material.module';
import { FormFieldOption } from '../core/form-field-option';
import { FormFieldTypes } from '../core/form-field-types';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
import { ErrorWidgetComponent } from '../error/error.component';
import { TypeaheadWidgetComponent } from './typeahead.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('TypeaheadWidgetComponent', () => {
let formService: FormService;
let widget: TypeaheadWidgetComponent;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
formService = new FormService(null, null, null);
widget = new TypeaheadWidgetComponent(formService, null);
@@ -223,15 +230,9 @@ describe('TypeaheadWidgetComponent', () => {
}, { id: '3', name: 'Fake Name 3' }];
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MaterialModule],
declarations: [TypeaheadWidgetComponent, ErrorWidgetComponent],
providers: [ FormService, EcmModelService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(TypeaheadWidgetComponent);
typeaheadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
});
fixture = TestBed.createComponent(TypeaheadWidgetComponent);
typeaheadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
}));
afterEach(() => {
@@ -261,7 +262,6 @@ describe('TypeaheadWidgetComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
});

View File

@@ -19,16 +19,15 @@ import { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Observable } from 'rxjs/Observable';
import { EcmModelService } from '../../../services/ecm-model.service';
import { FormService } from '../../../services/form.service';
import { ProcessContentService } from '../../../services/process-content.service';
import { MaterialModule } from '../../../../material.module';
import { FormFieldTypes } from '../core/form-field-types';
import { FormModel } from '../core/form.model';
import { ErrorWidgetComponent } from '../error/error.component';
import { FormFieldModel } from './../core/form-field.model';
import { UploadWidgetComponent } from './upload.widget';
import { setupTestBed } from '../../../../testing/setupTestBed';
import { CoreModule } from '../../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
let fakePngAnswer = {
'id': 1155,
@@ -67,6 +66,13 @@ describe('UploadWidgetComponent', () => {
let filePngFake = new File(['fakePng'], 'file-fake.png', {type: 'image/png'});
let filJpgFake = new File(['fakeJpg'], 'file-fake.jpg', {type: 'image/jpg'});
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
describe('when template is ready', () => {
let uploadWidgetComponent: UploadWidgetComponent;
let fixture: ComponentFixture<UploadWidgetComponent>;
@@ -76,17 +82,11 @@ describe('UploadWidgetComponent', () => {
let formServiceInstance: FormService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [ MaterialModule],
declarations: [UploadWidgetComponent, ErrorWidgetComponent],
providers: [FormService, EcmModelService, ProcessContentService]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(UploadWidgetComponent);
uploadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
debugElement = fixture.debugElement;
contentService = TestBed.get(ProcessContentService);
});
fixture = TestBed.createComponent(UploadWidgetComponent);
uploadWidgetComponent = fixture.componentInstance;
element = fixture.nativeElement;
debugElement = fixture.debugElement;
contentService = TestBed.get(ProcessContentService);
}));
beforeEach(() => {
@@ -96,7 +96,6 @@ describe('UploadWidgetComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
jasmine.Ajax.uninstall();
});

View File

@@ -15,13 +15,13 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivitiContentService } from '../../services/activiti-alfresco.service';
import { EcmModelService } from './../../services/ecm-model.service';
import { FormService } from './../../services/form.service';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormFieldModel } from './core/form-field.model';
import { FormModel } from './core/form.model';
import { WidgetComponent } from './widget.component';
import { setupTestBed } from '../../../testing/setupTestBed';
import { CoreModule } from '../../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('WidgetComponent', () => {
@@ -29,16 +29,12 @@ describe('WidgetComponent', () => {
let fixture: ComponentFixture<WidgetComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [WidgetComponent],
providers: [
FormService,
EcmModelService,
ActivitiContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(WidgetComponent);

View File

@@ -15,10 +15,14 @@
* limitations under the License.
*/
import { TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { FormModel } from './../components/widgets/core/form.model';
import { EcmModelService } from './ecm-model.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -26,16 +30,17 @@ describe('EcmModelService', () => {
let service: EcmModelService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
EcmModelService
]
});
service = TestBed.get(EcmModelService);
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
service = TestBed.get(EcmModelService);
jasmine.Ajax.install();
});
@@ -91,7 +96,7 @@ describe('EcmModelService', () => {
});
});
it('Should create ECM types with a clean and preserv real name in the title', (done) => {
it('Should create ECM types with a clean and preserve real name in the title', (done) => {
let typeName = 'typeTest:testName@#$*!';
let cleanName = 'testName';
@@ -111,7 +116,7 @@ describe('EcmModelService', () => {
});
});
it('Should add propery to a type', (done) => {
it('Should add property to a type', (done) => {
let typeName = 'typeTest';
let formFields = {
@@ -151,7 +156,7 @@ describe('EcmModelService', () => {
});
});
it('Should add propery to a type and clean name type', (done) => {
it('Should add property to a type and clean name type', (done) => {
let typeName = 'typeTest:testName@#$*!';
let cleanName = 'testName';

View File

@@ -15,13 +15,15 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { Response, ResponseOptions } from '@angular/http';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { FormDefinitionModel } from '../models/form-definition.model';
import { formModelTabs } from '../../mock';
import { EcmModelService } from './ecm-model.service';
import { formModelTabs, AlfrescoApiServiceMock } from '../../mock';
import { FormService } from './form.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
declare let jasmine: any;
@@ -55,21 +57,19 @@ describe('Form service', () => {
let service: FormService;
let apiService: AlfrescoApiService;
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
EcmModelService,
FormService
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
service = TestBed.get(FormService);
apiService = TestBed.get(AlfrescoApiService);
});
beforeEach(() => {
jasmine.Ajax.install();
});

View File

@@ -19,6 +19,11 @@ import { TestBed } from '@angular/core/testing';
import { NodeMetadata } from '../models/node-metadata.model';
import { EcmModelService } from './ecm-model.service';
import { NodeService } from './node.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -26,13 +31,17 @@ describe('NodeService', () => {
let service: NodeService;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
NodeService,
EcmModelService
]
});
service = TestBed.get(NodeService);
});

View File

@@ -18,6 +18,11 @@
import { TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { ProcessContentService } from './process-content.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -64,12 +69,17 @@ describe('ProcessContentService', () => {
let service: ProcessContentService;
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
ProcessContentService
]
});
service = TestBed.get(ProcessContentService);
});

View File

@@ -26,6 +26,11 @@ import {
formValues
} from '../../mock';
import { WidgetVisibilityService } from './widget-visibility.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -35,12 +40,17 @@ describe('WidgetVisibilityService', () => {
let booleanResult: boolean;
let stubFormWithFields = new FormModel(fakeFormJson);
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
WidgetVisibilityService
]
});
service = TestBed.get(WidgetVisibilityService);
jasmine.Ajax.install();
});

View File

@@ -43,5 +43,6 @@ export * from './interface/index';
export * from './models/index';
export * from './events/index';
export * from './mock/index';
export * from './testing';
export * from './core.module';

View File

@@ -16,30 +16,25 @@
*/
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatTabChangeEvent } from '@angular/material';
import { By } from '@angular/platform-browser';
import { MaterialModule } from '../material.module';
import { InfoDrawerLayoutComponent } from './info-drawer-layout.component';
import { InfoDrawerComponent } from './info-drawer.component';
import { InfoDrawerTabComponent } from './info-drawer.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
describe('InfoDrawerComponent', () => {
let element: HTMLElement;
let component: InfoDrawerComponent;
let fixture: ComponentFixture<InfoDrawerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
InfoDrawerComponent,
InfoDrawerLayoutComponent
],
imports: [
MaterialModule
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(InfoDrawerComponent);
@@ -91,19 +86,15 @@ describe('Custom InfoDrawer', () => {
let fixture: ComponentFixture<CustomInfoDrawerComponent>;
let component: CustomInfoDrawerComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
InfoDrawerComponent,
InfoDrawerTabComponent,
InfoDrawerLayoutComponent,
CustomInfoDrawerComponent
],
imports: [
MaterialModule
]
}).compileComponents();
}));
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
declarations: [
CustomInfoDrawerComponent
]
});
beforeEach(() => {
fixture = TestBed.createComponent(CustomInfoDrawerComponent);

View File

@@ -17,62 +17,8 @@ var appContext = require.context(".", true, /.spec.ts/);appContext.keys().forEac
const TestBed = require('@angular/core/testing').TestBed;
const browser = require('@angular/platform-browser-dynamic/testing');
const NoopAnimationsModule = require('@angular/platform-browser/animations').NoopAnimationsModule;
const FormsModule = require('@angular/forms').FormsModule;
const ReactiveFormsModule = require('@angular/forms').ReactiveFormsModule;
const HttpClient = require('@angular/common/http').HttpClient;
const HttpClientModule = require('@angular/common/http').HttpClientModule;
const TranslateModule = require('@ngx-translate/core').TranslateModule;
const TranslateLoader = require('@ngx-translate/core').TranslateLoader;
const DirectiveModule = require('./directives/directive.module').DirectiveModule;
const ContextMenuModule = require('./context-menu/context-menu.module').ContextMenuModule;
const PipeModule = require('./pipes/pipe.module').PipeModule;
const AppConfigModule = require('./app-config/app-config.module').AppConfigModule;
const LogService = require('./services/log.service').LogService;
const TranslateLoaderService = require('./services/translate-loader.service').TranslateLoaderService;
const AppConfigService = require('./app-config/app-config.service').AppConfigService;
const AppConfigServiceMock = require('./mock/app-config.service.mock').AppConfigServiceMock;
const AlfrescoApiServiceMock = require('./mock/alfresco-api.service.mock').AlfrescoApiServiceMock;
const AlfrescoApiService = require('./services/alfresco-api.service').AlfrescoApiService;
const providers = require('./core.module').providers;
TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());
export function createTranslateLoader(http, logService) {
return new TranslateLoaderService(http, logService);
}
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [HttpClient, LogService]
}
}),
DirectiveModule,
ContextMenuModule,
PipeModule,
AppConfigModule,
NoopAnimationsModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule
],
providers: [
providers(),
{provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock},
{provide: AppConfigService, useClass: AppConfigServiceMock}
]});
});
afterEach(() => {
TestBed.resetTestingModule();
});
TestBed.initTestEnvironment(
browser.BrowserDynamicTestingModule,
browser.platformBrowserDynamicTesting()
);

View File

@@ -15,15 +15,11 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { DirectiveModule } from '../directives/directive.module';
import { MaterialModule } from '../material.module';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { TranslateLoaderService } from '../services/translate-loader.service';
import { LanguageMenuComponent } from './language-menu.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('LanguageMenuComponent', () => {
@@ -31,27 +27,9 @@ describe('LanguageMenuComponent', () => {
let component: LanguageMenuComponent;
let appConfig: AppConfigService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule,
HttpClientModule,
DirectiveModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
LanguageMenuComponent
],
providers: [
AppConfigService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(LanguageMenuComponent);
@@ -59,6 +37,10 @@ describe('LanguageMenuComponent', () => {
appConfig = TestBed.get(AppConfigService);
});
afterEach(() => {
fixture.destroy();
});
it('should have the default language', () => {
fixture.detectChanges();
expect(component.languages).toEqual([{ key: 'en', label: 'English'}]);

View File

@@ -19,16 +19,16 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { UserPreferencesService } from '../../services/user-preferences.service';
import { AuthenticationService } from '../../services/authentication.service';
import { MaterialModule } from '../../material.module';
import { LoginErrorEvent } from '../models/login-error.event';
import { LoginSuccessEvent } from '../models/login-success.event';
import { LoginComponent } from './login.component';
import { Observable } from 'rxjs/Observable';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
@@ -54,20 +54,9 @@ describe('LoginComponent', () => {
return errorMessage;
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
LoginComponent
],
providers: [
AuthenticationService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
@@ -87,6 +76,10 @@ describe('LoginComponent', () => {
fixture.detectChanges();
});
afterEach(() => {
fixture.destroy();
});
function loginWithCredentials(username, password, providers: string = 'ECM') {
component.providers = providers;
usernameInput.value = username;
@@ -100,7 +93,7 @@ describe('LoginComponent', () => {
fixture.detectChanges();
}
it('should be autocompelte off', () => {
it('should be autocompelete off', () => {
expect(element.querySelector('#adf-login-form').getAttribute('autocomplete')).toBe('off');
});
@@ -394,8 +387,9 @@ describe('LoginComponent', () => {
component.success.subscribe(() => {
fixture.detectChanges();
expect(component.isError).toBe(false);
fixture.whenStable().then(() => {
expect(component.isError).toBe(false);
});
});
loginWithCredentials('fake-username', 'fake-password');
@@ -407,9 +401,10 @@ describe('LoginComponent', () => {
component.error.subscribe(() => {
fixture.detectChanges();
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
fixture.whenStable().then(() => {
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
});
loginWithCredentials('fake-wrong-username', 'fake-password');
@@ -420,10 +415,11 @@ describe('LoginComponent', () => {
component.error.subscribe(() => {
fixture.detectChanges();
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
fixture.whenStable().then(() => {
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
});
loginWithCredentials('fake-username', 'fake-wrong-password');
@@ -434,10 +430,11 @@ describe('LoginComponent', () => {
component.error.subscribe(() => {
fixture.detectChanges();
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
fixture.whenStable().then(() => {
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('LOGIN.MESSAGES.LOGIN-ERROR-CREDENTIALS');
});
});
loginWithCredentials('fake-wrong-username', 'fake-wrong-password');
@@ -454,10 +451,11 @@ describe('LoginComponent', () => {
component.error.subscribe(() => {
fixture.detectChanges();
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin');
fixture.whenStable().then(() => {
expect(component.isError).toBe(true);
expect(getLoginErrorElement()).toBeDefined();
expect(getLoginErrorMessage()).toEqual('ERROR: the network is offline, Origin is not allowed by Access-Control-Allow-Origin');
});
});
loginWithCredentials('fake-username-CORS-error', 'fake-password');

View File

@@ -15,37 +15,32 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { LoginComponent } from '../components/login.component';
import { MaterialModule } from '../../material.module';
import { LoginFooterDirective } from './login-footer.directive';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('LoginFooterDirective', () => {
let fixture: ComponentFixture<LoginComponent>;
let component: LoginComponent;
let directive: LoginFooterDirective;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
LoginFooterDirective,
LoginComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let fixture = TestBed.createComponent(LoginComponent);
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
directive = new LoginFooterDirective(component);
});
it('applies tempalate to Login component', () => {
afterEach(() => {
fixture.destroy();
});
it('applies template to Login component', () => {
const template: any = '';
directive.template = template;
directive.ngAfterContentInit();

View File

@@ -15,37 +15,32 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { MaterialModule } from '../../material.module';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { LoginComponent } from '../components/login.component';
import { LoginHeaderDirective } from './login-header.directive';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
describe('LoginHeaderDirective', () => {
let fixture: ComponentFixture<LoginComponent>;
let component: LoginComponent;
let directive: LoginHeaderDirective;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MaterialModule
],
declarations: [
LoginHeaderDirective,
LoginComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let fixture = TestBed.createComponent(LoginComponent);
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
directive = new LoginHeaderDirective(component);
});
it('applies tempalate to Login component', () => {
afterEach(() => {
fixture.destroy();
});
it('applies template to Login component', () => {
const template: any = 'test template';
directive.template = template;
directive.ngAfterContentInit();

View File

@@ -17,17 +17,18 @@
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
import { RedirectionModel } from '../models/redirection.model';
// TODO: should be extending AuthenticationService
export class AuthenticationMock /*extends AuthenticationService*/ {
private redirectUrl: string = '';
private redirectUrl: RedirectionModel = null;
setRedirectUrl(url: string) {
setRedirectUrl(url: RedirectionModel) {
this.redirectUrl = url;
}
getRedirectUrl(): string {
return this.redirectUrl;
return this.redirectUrl ? this.redirectUrl.url : null;
}
// TODO: real auth service returns Observable<string>

View File

@@ -19,11 +19,27 @@ import { CookieService } from '../services/cookie.service';
export class CookieServiceMock extends CookieService {
/** @override */
isEnabled(): boolean {
return true;
}
/** @override */
getItem(key: string): string | null {
return this[key] && this[key].data || null;
}
/** @override */
setItem(key: string, data: string, expiration: Date | null, path: string | null): void {
this[key] = {data, expiration, path};
}
/** @override */
clear() {
Object.keys(this).forEach(key => {
if (this.hasOwnProperty(key) && typeof(this[key]) !== 'function') {
this[key] = undefined;
}
});
}
}

View File

@@ -26,7 +26,7 @@ export * from './ecm-user.service.mock';
export * from './event.mock';
export * from './renditionsService.mock';
export * from './search.service.mock';
export * from './traslation.service.mock';
export * from './translation.service.mock';
export * from './alfresco-api.service.mock';
export * from './form/form.component.mock';

View File

@@ -15,14 +15,14 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Pagination } from 'alfresco-js-api';
import { MaterialModule } from '../material.module';
import { InfinitePaginationComponent } from './infinite-pagination.component';
import { PaginatedComponent } from './paginated-component.interface';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('InfinitePaginationComponent', () => {
@@ -30,17 +30,9 @@ describe('InfinitePaginationComponent', () => {
let component: InfinitePaginationComponent;
let pagination: Pagination;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
MaterialModule
],
declarations: [
InfinitePaginationComponent
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(InfinitePaginationComponent);
@@ -54,7 +46,6 @@ describe('InfinitePaginationComponent', () => {
afterEach(() => {
fixture.destroy();
TestBed.resetTestingModule();
});
describe('Standalone', () => {

View File

@@ -15,17 +15,14 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Pagination } from 'alfresco-js-api';
import { MaterialModule } from '../material.module';
import { TranslateLoaderService } from '../services/translate-loader.service';
import { TranslationService } from '../services/translation.service';
import { PaginationComponent } from './pagination.component';
import { PaginatedComponent } from './public-api';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
class FakePaginationInput implements Pagination {
count: number = 25;
@@ -45,47 +42,19 @@ describe('PaginationComponent', () => {
let fixture: ComponentFixture<PaginationComponent>;
let component: PaginationComponent;
let changePageNumberSpy: jasmine.Spy;
let changePageSizeSpy: jasmine.Spy;
let nextPageSpy: jasmine.Spy;
let prevPageSpy: jasmine.Spy;
setupTestBed({
imports: [CoreTestingModule],
schemas: [ NO_ERRORS_SCHEMA ]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
MaterialModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [
PaginationComponent
],
providers: [
TranslationService
],
schemas: [ NO_ERRORS_SCHEMA ]
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(PaginationComponent);
component = fixture.componentInstance;
beforeEach(() => {
fixture = TestBed.createComponent(PaginationComponent);
component = fixture.componentInstance;
});
(<any> component).ngAfterViewInit = jasmine
.createSpy('ngAfterViewInit').and
.callThrough();
changePageNumberSpy = spyOn(component.changePageNumber, 'emit');
changePageSizeSpy = spyOn(component.changePageSize, 'emit');
nextPageSpy = spyOn(component.nextPage, 'emit');
prevPageSpy = spyOn(component.prevPage, 'emit');
fixture.detectChanges();
});
}));
afterEach(() => {
fixture.destroy();
});
it('should have an "empty" class if no items present', () => {
fixture.detectChanges();
@@ -165,6 +134,7 @@ describe('PaginationComponent', () => {
});
it('goes next', () => {
const nextPageSpy = spyOn(component.nextPage, 'emit');
expect(component.current).toBe(3);
component.goNext();
@@ -175,6 +145,7 @@ describe('PaginationComponent', () => {
});
it('goes previous', () => {
const prevPageSpy = spyOn(component.prevPage, 'emit');
expect(component.current).toBe(3);
component.goPrevious();
@@ -185,6 +156,7 @@ describe('PaginationComponent', () => {
});
it('changes page size', () => {
const changePageSizeSpy = spyOn(component.changePageSize, 'emit');
expect(component.current).toBe(3);
component.onChangePageSize(50);
@@ -195,6 +167,7 @@ describe('PaginationComponent', () => {
});
it('changes page number', () => {
const changePageNumberSpy = spyOn(component.changePageNumber, 'emit');
expect(component.current).toBe(3);
component.onChangePageNumber(5);

View File

@@ -40,6 +40,14 @@ export class AlfrescoApiService {
return this.alfrescoApi;
}
get taskApi(): alfrescoApi.TaskApi {
return this.getInstance().activiti.taskApi;
}
get modelsApi(): alfrescoApi.ModelsApi {
return this.getInstance().activiti.modelsApi;
}
get contentApi(): ContentApi {
return this.getInstance().content;
}

View File

@@ -18,19 +18,18 @@
import { TestBed } from '@angular/core/testing';
import { fakeApps } from '../mock/apps-service.mock';
import { AppsProcessService } from './apps-process.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
describe('Apps Service', () => {
describe('AppsProcessService', () => {
let service: AppsProcessService;
beforeEach((() => {
TestBed.configureTestingModule({
providers: [
AppsProcessService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
service = TestBed.get(AppsProcessService);

View File

@@ -16,16 +16,12 @@
*/
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CookieServiceMock } from './../mock/cookie.service.mock';
import { AppConfigModule } from '../app-config/app-config.module';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuardBpm } from './auth-guard-bpm.service';
import { AuthenticationService } from './authentication.service';
import { CookieService } from './cookie.service';
import { TranslateLoaderService } from './translate-loader.service';
import { RouterStateSnapshot, Router } from '@angular/router';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('AuthGuardService BPM', () => {
@@ -34,24 +30,9 @@ describe('AuthGuardService BPM', () => {
let routerService: Router;
let appConfigService: AppConfigService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
RouterTestingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
AuthGuardBpm,
{ provide: CookieService, useClass: CookieServiceMock }
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
authService = TestBed.get(AuthenticationService);

View File

@@ -20,6 +20,8 @@ import { Router } from '@angular/router';
import { AlfrescoApiService } from './alfresco-api.service';
import { AuthGuardEcm } from './auth-guard-ecm.service';
import { AuthenticationService } from './authentication.service';
import { AppConfigService } from '../app-config/app-config.service';
import { HttpClientModule } from '@angular/common/http';
class RouterProvider {
navigate: Function = jasmine.createSpy('RouterProviderNavigate');
@@ -79,7 +81,11 @@ class TestConfig {
Object.assign(this.settings, settings);
TestBed.configureTestingModule({
imports: [
HttpClientModule
],
providers: [
AppConfigService,
this.routerProvider,
this.alfrescoApiServiceProvider,
this.authenticationProvider,

View File

@@ -17,16 +17,11 @@
import { async, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CookieServiceMock } from './../mock/cookie.service.mock';
import { AppConfigModule } from '../app-config/app-config.module';
import { AppConfigService } from '../app-config/app-config.service';
import { AuthGuard } from './auth-guard.service';
import { AuthenticationService } from './authentication.service';
import { CookieService } from './cookie.service';
import { TranslateLoaderService } from './translate-loader.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('AuthGuardService', () => {
let state;
@@ -35,25 +30,9 @@ describe('AuthGuardService', () => {
let service: AuthGuard;
let appConfigService: AppConfigService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
RouterTestingModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
AuthGuard,
AuthenticationService,
{ provide: CookieService, useClass: CookieServiceMock }
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
state = { url: '' };

View File

@@ -15,16 +15,14 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CookieServiceMock } from './../mock/cookie.service.mock';
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiService } from './alfresco-api.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { AuthenticationService } from './authentication.service';
import { CookieService } from './cookie.service';
import { StorageService } from './storage.service';
import { TranslateLoaderService } from './translate-loader.service';
import { UserPreferencesService } from './user-preferences.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
@@ -35,31 +33,18 @@ describe('AuthenticationService', () => {
let storage: StorageService;
let cookie: CookieService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
AuthenticationService,
StorageService,
UserPreferencesService,
{ provide: CookieService, useClass: CookieServiceMock }
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
apiService = TestBed.get(AlfrescoApiService);
authService = TestBed.get(AuthenticationService);
preferences = TestBed.get(UserPreferencesService);
cookie = TestBed.get(CookieService);
cookie.clear();
storage = TestBed.get(StorageService);
storage.clear();
@@ -67,6 +52,8 @@ describe('AuthenticationService', () => {
});
afterEach(() => {
cookie.clear();
storage.clear();
jasmine.Ajax.uninstall();
});
@@ -182,7 +169,7 @@ describe('AuthenticationService', () => {
});
});
xit('[ECM] should return ticket undefined when the credentials are wrong', (done) => {
it('[ECM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => {
},
@@ -343,7 +330,7 @@ describe('AuthenticationService', () => {
});
});
xit('[BPM] should return ticket undefined when the credentials are wrong', (done) => {
it('[BPM] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
(res) => {
},
@@ -507,7 +494,7 @@ describe('AuthenticationService', () => {
});
});
xit('[ALL] should return ticket undefined when the credentials are wrong', (done) => {
it('[ALL] should return ticket undefined when the credentials are wrong', (done) => {
authService.login('fake-username', 'fake-password').subscribe(
(res) => {
},

View File

@@ -19,23 +19,18 @@ import { TestBed } from '@angular/core/testing';
import { CommentModel } from '../models/comment.model';
import { fakeContentComment, fakeContentComments } from '../mock/comment-content-service.mock';
import { CommentContentService } from './comment-content.service';
import { LogService } from './log.service';
import { StorageService } from './storage.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
describe('Comment Content Service', () => {
let service: CommentContentService;
beforeEach((() => {
TestBed.configureTestingModule({
providers: [
CommentContentService,
StorageService,
LogService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
service = TestBed.get(CommentContentService);

View File

@@ -19,21 +19,20 @@ import { async, TestBed } from '@angular/core/testing';
import { CommentModel } from '../models/comment.model';
import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../mock/comment-process-service.mock';
import { CommentProcessService } from './comment-process.service';
import { setupTestBed } from '../testing/setupTestBed';
import { AlfrescoApiService } from './alfresco-api.service';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
describe('Comment ProcessService Service', () => {
let service: CommentProcessService;
let alfrescoApi: any;
beforeEach((() => {
TestBed.configureTestingModule({
providers: [
CommentProcessService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
service = TestBed.get(CommentProcessService);

View File

@@ -15,18 +15,20 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { CookieServiceMock } from '../mock/cookie.service.mock';
import { ContentService } from './content.service';
import { SettingsService } from './settings.service';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { AuthenticationService } from './authentication.service';
import { CookieService } from './cookie.service';
import { StorageService } from './storage.service';
import { TranslateLoaderService } from './translate-loader.service';
import { UserPreferencesService } from './user-preferences.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { TranslationService } from './translation.service';
import { TranslationMock } from '../mock/translation.service.mock';
declare let jasmine: any;
@@ -40,28 +42,16 @@ describe('ContentService', () => {
const nodeId = 'fake-node-id';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
declarations: [],
providers: [
ContentService,
AuthenticationService,
SettingsService,
StorageService,
UserPreferencesService,
{provide: CookieService, useClass: CookieServiceMock}
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{ provide: CookieService, useClass: CookieServiceMock }
]
});
beforeEach(() => {
authService = TestBed.get(AuthenticationService);

View File

@@ -57,4 +57,8 @@ export class CookieService {
(expiration ? ';expires=' + expiration.toUTCString() : '') +
(path ? `;path=${path}` : ';path=/');
}
clear() {
/* placeholder for testing purposes */
}
}

View File

@@ -15,11 +15,12 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { BpmProductVersionModel, EcmProductVersionModel } from '../models/product-version.model';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { DiscoveryApiService } from './discovery-api.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
@@ -90,16 +91,9 @@ describe('Discovery Api Service', () => {
let service;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
providers: [
DiscoveryApiService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let appConfig: AppConfigService = TestBed.get(AppConfigService);

View File

@@ -18,6 +18,8 @@
import { TestBed } from '@angular/core/testing';
import { UserProcessModel } from '../models';
import { PeopleProcessService } from './people-process.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
@@ -41,12 +43,11 @@ describe('PeopleProcessService', () => {
let service: PeopleProcessService;
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
PeopleProcessService
]
});
service = TestBed.get(PeopleProcessService);
});

View File

@@ -15,26 +15,27 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { fakeRedition, fakeReditionCreated, fakeReditionsList } from '../mock/renditionsService.mock';
import { AppConfigModule } from '../app-config/app-config.module';
import { RenditionsService } from './renditions.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
declare let jasmine: any;
describe('RenditionsService', () => {
let service: RenditionsService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
providers: [
RenditionsService
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
jasmine.Ajax.install();
@@ -45,7 +46,7 @@ describe('RenditionsService', () => {
jasmine.Ajax.uninstall();
});
it('Get redition list service should return the list', (done) => {
it('Get rendition list service should return the list', (done) => {
service.getRenditionsListByNodeId('fake-node-id').subscribe((res) => {
expect(res.list.entries[0].entry.id).toBe('avatar');
done();
@@ -58,7 +59,7 @@ describe('RenditionsService', () => {
});
});
it('Create redition service should call the server with the ID passed and the asked encoding', (done) => {
it('Create rendition service should call the server with the ID passed and the asked encoding', (done) => {
service.createRendition('fake-node-id', 'pdf').subscribe((res) => {
expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST');
expect(jasmine.Ajax.requests.mostRecent().url).toContain('/ecm/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
@@ -83,7 +84,7 @@ describe('RenditionsService', () => {
});
});
it('Get redition service should catch the error', (done) => {
it('Get rendition service should catch the error', (done) => {
service.getRenditionsListByNodeId('fake-node-id').subscribe((res) => {
}, (res) => {
done();

View File

@@ -15,38 +15,33 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { searchMockApi, mockError, fakeSearch } from '../mock/search.service.mock';
import { CookieServiceMock } from './../mock/cookie.service.mock';
import { AlfrescoApiService } from './alfresco-api.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { CookieService } from './cookie.service';
import { SearchService } from './search.service';
import { TranslateLoaderService } from './translate-loader.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { TranslationService } from './translation.service';
import { TranslationMock } from '../mock/translation.service.mock';
describe('SearchService', () => {
let service: SearchService;
let apiService: AlfrescoApiService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
SearchService,
{ provide: CookieService, useClass: CookieServiceMock }
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{ provide: CookieService, useClass: CookieServiceMock }
]
});
beforeEach(() => {
service = TestBed.get(SearchService);

View File

@@ -15,24 +15,18 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { SettingsService } from './settings.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('SettingsService', () => {
let service: SettingsService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule
],
providers: [
SettingsService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
service = TestBed.get(SettingsService);

View File

@@ -15,12 +15,11 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { SitesService } from './sites.service';
import { TranslateLoaderService } from './translate-loader.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
declare let jasmine: any;
@@ -28,22 +27,9 @@ describe('Sites service', () => {
let service;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
SitesService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
let appConfig: AppConfigService = TestBed.get(AppConfigService);

View File

@@ -15,42 +15,18 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, TestBed } from '@angular/core/testing';
import { MatIconRegistry } from '@angular/material';
import { BrowserModule } from '@angular/platform-browser';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { CookieServiceMock } from './../mock/cookie.service.mock';
import { ContentService } from './content.service';
import { CookieService } from './cookie.service';
import { TestBed } from '@angular/core/testing';
import { ThumbnailService } from './thumbnail.service';
import { TranslateLoaderService } from './translate-loader.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('ThumbnailService', () => {
let service: ThumbnailService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
BrowserModule,
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
ContentService,
{ provide: CookieService, useClass: CookieServiceMock },
ThumbnailService,
MatIconRegistry
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
service = TestBed.get(ThumbnailService);

View File

@@ -15,48 +15,28 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { Injector } from '@angular/core';
import { getTestBed, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TestBed } from '@angular/core/testing';
import { TranslateLoaderService } from './translate-loader.service';
import { TRANSLATION_PROVIDER, TranslationService } from './translation.service';
import { TranslationService } from './translation.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreModule } from '../core.module';
let componentJson1 = ' {"TEST": "This is a test", "TEST2": "This is another test"} ' ;
declare let jasmine: any;
describe('TranslateLoader', () => {
let injector: Injector;
let translationService: TranslationService;
let customLoader: TranslateLoaderService;
setupTestBed({
imports: [
CoreModule.forRoot()
]
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
TranslationService,
{
provide: TRANSLATION_PROVIDER,
multi: true,
useValue: {
name: '@alfresco/adf-core',
source: 'assets/ng2-alfresco-core'
}
}
]
});
injector = getTestBed();
translationService = injector.get(TranslationService);
translationService = TestBed.get(TranslationService);
customLoader = <TranslateLoaderService> translationService.translate.currentLoader;
jasmine.Ajax.install();

View File

@@ -22,6 +22,13 @@ import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateLoaderService } from './translate-loader.service';
import { TRANSLATION_PROVIDER, TranslationService } from './translation.service';
import { LogService } from './log.service';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigServiceMock } from '../mock/app-config.service.mock';
import { UserPreferencesService } from './user-preferences.service';
import { StorageService } from './storage.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -41,6 +48,11 @@ describe('TranslationService', () => {
})
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
LogService,
{ provide: AppConfigService, useClass: AppConfigServiceMock },
UserPreferencesService,
StorageService,
TranslationService,
{
provide: TRANSLATION_PROVIDER,

View File

@@ -21,6 +21,9 @@ import { FileModel, FileUploadOptions, FileUploadStatus } from '../models/file.m
import { AppConfigModule } from '../app-config/app-config.module';
import { UploadService } from './upload.service';
import { AppConfigService } from '../app-config/app-config.service';
import { AlfrescoApiService } from './alfresco-api.service';
import { StorageService } from './storage.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -33,6 +36,8 @@ describe('UploadService', () => {
AppConfigModule
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
StorageService,
UploadService
]
}).compileComponents();

View File

@@ -16,15 +16,13 @@
*/
import { async, TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { DirectiveModule } from '../directives/directive.module';
import { TranslateService } from '@ngx-translate/core';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigModule } from '../app-config/app-config.module';
import { StorageService } from './storage.service';
import { TranslateLoaderService } from './translate-loader.service';
import { UserPreferencesService } from './user-preferences.service';
import { UserPreferenceValues } from './user-preferences.service';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('UserPreferencesService', () => {
@@ -35,23 +33,9 @@ describe('UserPreferencesService', () => {
let appConfig: AppConfigService;
let translate: TranslateService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppConfigModule,
DirectiveModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateLoaderService
}
})
],
providers: [
UserPreferencesService
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
appConfig = TestBed.get(AppConfigService);

View File

@@ -15,29 +15,19 @@
* limitations under the License.
*/
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HostSettingsModule } from './host-settings.module';
import { MaterialModule } from '../material.module';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HostSettingsComponent } from './host-settings.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('HostSettingsComponent', () => {
let fixture: ComponentFixture<HostSettingsComponent>;
let component: HostSettingsComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule,
MaterialModule,
HttpClientModule,
HostSettingsModule
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(HostSettingsComponent);

View File

@@ -19,22 +19,17 @@ import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../material.module';
import { SidebarActionMenuComponent } from './sidebar-action-menu.component';
import { setupTestBed } from '../testing/setupTestBed';
import { CoreTestingModule } from '../testing/core.testing.module';
describe('SidebarActionMenuComponent', () => {
let element: HTMLElement;
let component: SidebarActionMenuComponent;
let fixture: ComponentFixture<SidebarActionMenuComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
SidebarActionMenuComponent
],
imports: [
MaterialModule
]
}).compileComponents();
}));
setupTestBed({
imports: [CoreTestingModule]
});
beforeEach(() => {
fixture = TestBed.createComponent(SidebarActionMenuComponent);
@@ -42,6 +37,10 @@ describe('SidebarActionMenuComponent', () => {
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
it('should create instance of SidebarActionMenuComponent', () => {
expect(fixture.componentInstance instanceof SidebarActionMenuComponent).toBe(true, 'should create SidebarActionMenuComponent');
});

View File

@@ -0,0 +1,43 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NgModule } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { CoreModule } from '../core.module';
import { AlfrescoApiService } from '../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../mock/alfresco-api.service.mock';
import { AppConfigService } from '../app-config/app-config.service';
import { AppConfigServiceMock } from '../mock/app-config.service.mock';
import { TranslationService } from '../services/translation.service';
import { TranslationMock } from '../mock/translation.service.mock';
import { DatePipe } from '@angular/common';
import { CookieService } from '../services/cookie.service';
import { CookieServiceMock } from '../mock/cookie.service.mock';
@NgModule({
imports: [NoopAnimationsModule, RouterTestingModule, CoreModule.forRoot()],
providers: [
DatePipe,
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{ provide: CookieService, useClass: CookieServiceMock }
]
})
export class CoreTestingModule {}

18
lib/core/testing/index.ts Normal file
View File

@@ -0,0 +1,18 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './setupTestBed';

View File

@@ -0,0 +1,48 @@
/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { TestBed, TestModuleMetadata } from '@angular/core/testing';
interface DoneFn extends Function {
(): void;
fail: (message?: Error | string) => void;
}
declare function beforeAll(action: (done: DoneFn) => void, timeout?: number): void;
declare function afterAll(action: (done: DoneFn) => void, timeout?: number): void;
const resetTestingModule = TestBed.resetTestingModule;
const preventAngularFromResetting = () => (TestBed.resetTestingModule = () => TestBed);
const allowAngularToReset = () => (TestBed.resetTestingModule = resetTestingModule);
export const setupTestBed = (moduleDef: TestModuleMetadata) => {
beforeAll(done =>
(async () => {
resetTestingModule();
preventAngularFromResetting();
TestBed.configureTestingModule(moduleDef);
await TestBed.compileComponents();
// prevent Angular from resetting testing module
TestBed.resetTestingModule = () => TestBed;
})()
.then(done)
.catch(done.fail)
);
afterAll(() => allowAngularToReset());
};

View File

@@ -21,12 +21,13 @@ import { AuthenticationService, ContentService } from '../../services';
import { InitialUsernamePipe } from '../../pipes';
import { fakeBpmUser } from '../../mock/bpm-user.service.mock';
import { fakeEcmEditedUser, fakeEcmUser, fakeEcmUserNoImage } from '../../mock/ecm-user.service.mock';
import { MaterialModule } from '../../material.module';
import { BpmUserService } from '../services/bpm-user.service';
import { EcmUserService } from '../services/ecm-user.service';
import { BpmUserModel } from './../models/bpm-user.model';
import { UserInfoComponent } from './user-info.component';
import { Observable } from 'rxjs/Observable';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreTestingModule } from '../../testing/core.testing.module';
class FakeSanitazer extends DomSanitizer {
@@ -76,29 +77,19 @@ describe('User info component', () => {
fixture.detectChanges();
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
UserInfoComponent
],
providers: [
EcmUserService,
BpmUserService,
ContentService
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(UserInfoComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
setupTestBed({
imports: [CoreTestingModule]
});
authService = TestBed.get(AuthenticationService);
ecmUserService = TestBed.get(EcmUserService);
bpmUserService = TestBed.get(BpmUserService);
contentService = TestBed.get(ContentService);
});
beforeEach(async(() => {
fixture = TestBed.createComponent(UserInfoComponent);
component = fixture.componentInstance;
element = fixture.nativeElement;
authService = TestBed.get(AuthenticationService);
ecmUserService = TestBed.get(EcmUserService);
bpmUserService = TestBed.get(BpmUserService);
contentService = TestBed.get(ContentService);
}));
afterEach(() => {

View File

@@ -15,9 +15,13 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { TestBed } from '@angular/core/testing';
import { BpmUserModel } from '../models/bpm-user.model';
import { BpmUserService } from '../services/bpm-user.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -25,13 +29,14 @@ describe('Bpm user service', () => {
let service: BpmUserService;
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
BpmUserService
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
service = TestBed.get(BpmUserService);

View File

@@ -15,10 +15,13 @@
* limitations under the License.
*/
import { async, TestBed } from '@angular/core/testing';
import { AuthenticationService, ContentService } from '../../services';
import { TestBed } from '@angular/core/testing';
import { AuthenticationService, ContentService, AlfrescoApiService } from '../../services';
import { fakeEcmUser } from '../../mock/ecm-user.service.mock';
import { EcmUserService } from '../services/ecm-user.service';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
declare let jasmine: any;
@@ -28,15 +31,14 @@ describe('EcmUserService', () => {
let authService: AuthenticationService;
let contentService: ContentService;
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
EcmUserService,
AuthenticationService,
ContentService
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
]
});
beforeEach(() => {
service = TestBed.get(EcmUserService);

View File

@@ -16,12 +16,12 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ContentService } from '../../services/content.service';
import { MaterialModule } from '../../material.module';
import { ToolbarModule } from '../../toolbar/toolbar.module';
import { ImgViewerComponent } from './imgViewer.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
describe('Test Img viewer component ', () => {
@@ -35,18 +35,14 @@ describe('Test Img viewer component ', () => {
return new Blob([data], {type: 'image/png'});
}
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule,
ToolbarModule
],
declarations: [ImgViewerComponent]
}).compileComponents();
service = TestBed.get(ContentService);
}));
setupTestBed({
imports: [
CoreModule.forRoot()
]
});
beforeEach(() => {
service = TestBed.get(ContentService);
fixture = TestBed.createComponent(ImgViewerComponent);
element = fixture.nativeElement;

View File

@@ -18,6 +18,8 @@
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MediaPlayerComponent } from './mediaPlayer.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import {
ContentService
@@ -34,10 +36,11 @@ describe('Test Media player component ', () => {
return new Blob([data], {type: 'image/png'});
}
setupTestBed({
imports: [CoreModule.forRoot()]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [MediaPlayerComponent]
}).compileComponents();
service = TestBed.get(ContentService);
}));

View File

@@ -15,10 +15,12 @@
* limitations under the License.
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { MaterialModule } from '../../material.module';
import { PdfPasswordDialogComponent } from './pdfViewer-password-dialog';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
declare let PDFJS: any;
@@ -27,30 +29,26 @@ describe('PdfPasswordDialogComponent', () => {
let fixture: ComponentFixture<PdfPasswordDialogComponent>;
let dialogRef: MatDialogRef<PdfPasswordDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MaterialModule
],
declarations: [
PdfPasswordDialogComponent
],
providers: [
{
provide: MAT_DIALOG_DATA, useValue: {
reason: null
}
},
{
provide: MatDialogRef, useValue: {
close: jasmine.createSpy('open')
}
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
],
providers: [
{
provide: MAT_DIALOG_DATA,
useValue: {
reason: null
}
]
})
.compileComponents();
}));
},
{
provide: MatDialogRef,
useValue: {
close: jasmine.createSpy('open')
}
}
]
});
beforeEach(() => {
fixture = TestBed.createComponent(PdfPasswordDialogComponent);

View File

@@ -18,6 +18,8 @@
import { DomSanitizer } from '@angular/platform-browser';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PdfThumbComponent } from './pdfViewer-thumb.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
describe('PdfThumbComponent', () => {
@@ -34,19 +36,18 @@ describe('PdfThumbComponent', () => {
}))
};
setupTestBed({
imports: [
CoreModule.forRoot()
],
providers: [
{ provide: DomSanitizer, useValue: domSanitizer }
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
PdfThumbComponent
],
providers: [
{ provide: DomSanitizer, useValue: domSanitizer }
]
}).compileComponents()
.then(() => {
fixture = TestBed.createComponent(PdfThumbComponent);
component = fixture.componentInstance;
});
fixture = TestBed.createComponent(PdfThumbComponent);
component = fixture.componentInstance;
}));
it('should have resolve image data', (done) => {

View File

@@ -19,7 +19,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
import { PdfThumbComponent } from './pdfViewer-thumb.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
declare let PDFJS: any;
@@ -54,30 +55,25 @@ describe('PdfThumbListComponent', () => {
eventBus: new PDFJS.EventBus()
};
setupTestBed({
imports: [
NoopAnimationsModule,
CoreModule.forRoot()
]
});
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule
],
declarations: [
PdfThumbListComponent,
PdfThumbComponent
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(PdfThumbListComponent);
component = fixture.componentInstance;
fixture = TestBed.createComponent(PdfThumbListComponent);
component = fixture.componentInstance;
component.pdfViewer = viewerMock;
component.pdfViewer = viewerMock;
// provide scrollable container
fixture.nativeElement.style.display = 'block';
fixture.nativeElement.style.height = '700px';
fixture.nativeElement.style.overflow = 'scroll';
fixture.debugElement.query(By.css('.pdf-thumbnails__content'))
.nativeElement.style.height = '2000px';
});
// provide scrollable container
fixture.nativeElement.style.display = 'block';
fixture.nativeElement.style.height = '700px';
fixture.nativeElement.style.overflow = 'scroll';
fixture.debugElement.query(By.css('.pdf-thumbnails__content'))
.nativeElement.style.height = '2000px';
}));
it('should render initial rage of items', () => {

View File

@@ -16,18 +16,17 @@
*/
import { Component, SimpleChange, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MaterialModule } from '../../material.module';
import { ToolbarModule } from '../../toolbar/toolbar.module';
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { EventMock } from '../../mock/event.mock';
import { RenderingQueueServices } from '../services/rendering-queue.services';
import { PdfViewerComponent } from './pdfViewer.component';
import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
import { PdfThumbComponent } from './pdfViewer-thumb.component';
import { RIGHT_ARROW, LEFT_ARROW } from '@angular/cdk/keycodes';
import { MatDialog } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { ViewerModule } from '../viewer.module';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
import { TranslationService } from '../../services/translation.service';
import { TranslationMock } from '../../mock/translation.service.mock';
declare let PDFJS: any;
@@ -125,38 +124,22 @@ describe('Test PdfViewer component', () => {
let change: any;
let dialog: MatDialog;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ToolbarModule,
MaterialModule
],
declarations: [
TestDialogComponent,
PdfViewerComponent,
PdfThumbListComponent,
PdfThumbComponent,
UrlTestComponent,
UrlTestPasswordComponent,
BlobTestComponent
],
providers: [
{
provide: MatDialog, useValue: {
open: () => {
}
}
},
RenderingQueueServices
]
})
.overrideModule(ViewerModule, {
set: {
entryComponents: [TestDialogComponent]
}
})
.compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
TestDialogComponent,
UrlTestComponent,
UrlTestPasswordComponent,
BlobTestComponent
],
providers: [
{ provide: TranslationService, useClass: TranslationMock },
{ provide: MatDialog, useValue: { open: () => {} } },
RenderingQueueServices
]
});
beforeEach((done) => {
fixture = TestBed.createComponent(PdfViewerComponent);
@@ -170,12 +153,15 @@ describe('Test PdfViewer component', () => {
component.currentScale = 1;
fixture.detectChanges();
fixture.whenStable().then(() => {
done();
});
});
afterEach(() => {
fixture.destroy();
});
it('should Loader be present', () => {
expect(element.querySelector('.loader-container')).not.toBeNull();
});
@@ -276,25 +262,23 @@ describe('Test PdfViewer component', () => {
});
});
it('should Canvas be present', (done) => {
it('should Canvas be present', async(() => {
fixtureBlobTestComponent.detectChanges();
fixtureBlobTestComponent.whenStable().then(() => {
expect(elementBlobTestComponent.querySelector('.pdfViewer')).not.toBeNull();
expect(elementBlobTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull();
done();
};
}, 5000);
});
}));
it('should Next an Previous Buttons be present', (done) => {
it('should Next an Previous Buttons be present', async(() => {
fixtureBlobTestComponent.detectChanges();
fixtureBlobTestComponent.whenStable().then(() => {
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
};
}, 5000);
});
}));
it('should Input Page elements be present', (done) => {
fixtureBlobTestComponent.detectChanges();
@@ -306,7 +290,7 @@ describe('Test PdfViewer component', () => {
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
done();
};
});
}, 5000);
it('should Toolbar be hide if showToolbar is false', (done) => {
@@ -318,7 +302,7 @@ describe('Test PdfViewer component', () => {
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-command')).toBeNull();
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
done();
};
});
}, 5000);
});
@@ -361,18 +345,18 @@ describe('Test PdfViewer component', () => {
});
}, 5000);
it('should event RIGHT_ARROW keyboard change pages', (done) => {
xit('should event RIGHT_ARROW keyboard change pages', async(() => {
EventMock.keyDown(RIGHT_ARROW);
fixtureUrlTestComponent.detectChanges();
fixtureUrlTestComponent.whenStable().then(() => {
fixtureUrlTestComponent.detectChanges();
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
done();
});
}, 5000);
}), 5000);
it('should event LEFT_ARROW keyboard change pages', (done) => {
xit('should event LEFT_ARROW keyboard change pages', (done) => {
component.inputPage('2');
fixtureUrlTestComponent.detectChanges();
@@ -511,7 +495,7 @@ describe('Test PdfViewer component', () => {
it('should react on the emit of pagesloaded event', (done) => {
fixtureUrlTestComponent.detectChanges();
fixtureUrlTestComponent.whenStable().then(() => {
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled = false;
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBeFalsy();
const args = {
pagesCount: 10,

View File

@@ -16,8 +16,10 @@
*/
import { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TxtViewerComponent } from './txtViewer.component';
import { setupTestBed } from '../../testing/setupTestBed';
import { CoreModule } from '../../core.module';
describe('Text View component', () => {
@@ -25,11 +27,11 @@ describe('Text View component', () => {
let fixture: ComponentFixture<TxtViewerComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TxtViewerComponent]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
]
});
beforeEach(() => {
fixture = TestBed.createComponent(TxtViewerComponent);

View File

@@ -21,27 +21,15 @@ import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { AlfrescoApiService, RenditionsService } from '../../services';
import { MaterialModule } from './../../material.module';
import { ToolbarModule } from '../../toolbar/toolbar.module';
import { CoreModule } from '../../core.module';
import { Observable } from 'rxjs/Observable';
import { EventMock } from '../../mock/event.mock';
import { RenderingQueueServices } from '../services/rendering-queue.services';
import { ImgViewerComponent } from './imgViewer.component';
import { MediaPlayerComponent } from './mediaPlayer.component';
import { PdfViewerComponent } from './pdfViewer.component';
import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
import { PdfThumbComponent } from './pdfViewer-thumb.component';
import { TxtViewerComponent } from './txtViewer.component';
import { UnknownFormatComponent } from './unknown-format/unknown-format.component';
import { ViewerMoreActionsComponent } from './viewer-more-actions.component';
import { ViewerOpenWithComponent } from './viewer-open-with.component';
import { ViewerSidebarComponent } from './viewer-sidebar.component';
import { ViewerToolbarComponent } from './viewer-toolbar.component';
import { ViewerToolbarActionsComponent } from './viewer-toolbar-actions.component';
import { ViewerComponent } from './viewer.component';
import { FlexLayoutModule } from '@angular/flex-layout';
import 'rxjs/add/observable/throw';
import { setupTestBed } from '../../testing/setupTestBed';
import { AlfrescoApiServiceMock } from '../../mock/alfresco-api.service.mock';
@Component({
selector: 'adf-viewer-container-toolbar',
@@ -134,44 +122,28 @@ describe('ViewerComponent', () => {
let alfrescoApiService: AlfrescoApiService;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ToolbarModule,
MaterialModule,
FlexLayoutModule
],
declarations: [
ViewerComponent,
PdfViewerComponent,
PdfThumbListComponent,
PdfThumbComponent,
TxtViewerComponent,
MediaPlayerComponent,
ImgViewerComponent,
UnknownFormatComponent,
ViewerSidebarComponent,
ViewerToolbarComponent,
ViewerOpenWithComponent,
ViewerMoreActionsComponent,
ViewerToolbarActionsComponent,
ViewerWithCustomToolbarComponent,
ViewerWithCustomSidebarComponent,
ViewerWithCustomOpenWithComponent,
ViewerWithCustomMoreActionsComponent,
ViewerWithCustomToolbarActionsComponent
],
providers: [
{provide: RenditionsService, useValue: {
getRendition: () => {
return Observable.throw('throwed');
}
}},
RenderingQueueServices,
{ provide: Location, useClass: SpyLocation }
]
}).compileComponents();
}));
setupTestBed({
imports: [
CoreModule.forRoot()
],
declarations: [
ViewerWithCustomToolbarComponent,
ViewerWithCustomSidebarComponent,
ViewerWithCustomOpenWithComponent,
ViewerWithCustomMoreActionsComponent,
ViewerWithCustomToolbarActionsComponent
],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{provide: RenditionsService, useValue: {
getRendition: () => {
return Observable.throw('throwed');
}
}},
RenderingQueueServices,
{ provide: Location, useClass: SpyLocation }
]
});
beforeEach(() => {
fixture = TestBed.createComponent(ViewerComponent);

Some files were not shown because too many files have changed in this diff Show More