Merge branch 'DEVELOP_FE' of ssh://git.eclipse.org:29418/elogbook/elogbookFE into DEVELOP_FE
diff --git a/src/app/pages/search/search.component.spec.ts b/src/app/pages/search/search.component.spec.ts
index adf3842..e51ee01 100644
--- a/src/app/pages/search/search.component.spec.ts
+++ b/src/app/pages/search/search.component.spec.ts
@@ -17,12 +17,11 @@
import { AbstractListComponent } from '../../lists/abstract-list/abstract-list.component';
import { SessionContext } from '../../common/session-context';
import { Router } from '@angular/router';
-import { User } from '../../model/user';
import { EntryComponent } from '../../dialogs/entry/entry.component';
import { MainNavigationComponent } from '../../common-components/main-navigation/main-navigation.component';
import { SearchComponent } from './search.component';
import { SearchResultListComponent } from '../../lists/search-result-list/search-result-list.component';
-import {GlobalSearchFilter } from '../../model/global-search-filter';
+import { GlobalSearchFilter } from '../../model/global-search-filter';
import { Notification } from '../../model/notification';
import { NotificationService } from '../../services/notification.service';
import { SearchResultService } from '../../services/search-result.service';
@@ -36,6 +35,7 @@
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MessageService } from '../../services/message.service';
+
class FakeRouter {
navigate(commands: any[]) {
return commands[0];
@@ -48,7 +48,6 @@
EntryComponent
]
})
-
class TestModule { }
describe('SearchComponent', () => {
@@ -60,15 +59,7 @@
let mockNotificationSearchSortService: MockNotificationSearchSortService;
let mockSearchResultService: MockSearchResultService;
-
- const correctUser: User = {
- id: 44, username: 'carlo', password: 'serverPwd'
- , name: 'Carlo Cottura', specialUser: true, itemName: this.userName
- };
-
- class MockNotificationSearchSortService extends AbstractMockObservableService {
- itemChanged$ = new EventEmitter();
- itemAdded$ = new EventEmitter();
+ class MockNotificationSearchSortService extends AbstractMockObservableService {
loadCalled = false;
searchResultNotifications = SEARCH_RESULT_NOTIFICATIONS;
@@ -88,16 +79,18 @@
}
}
-
class MockSearchResultService extends AbstractMockObservableService {
- //TODO
+ loadCalled = false;
+ public getSearchResults(globalSearchFilter: GlobalSearchFilter) {
+ this.loadCalled = true;
+ return this;
+ };
}
- class MockDialogRef extends AbstractMockObservableService {
- close() { }
- }
+
beforeEach(async(() => {
mockNotificationSearchSortService = new MockNotificationSearchSortService();
+ mockSearchResultService = new MockSearchResultService();
router = new FakeRouter() as any as Router;
TestBed.overrideModule(BrowserDynamicTestingModule, {
@@ -112,27 +105,26 @@
MdDialogModule,
MaterialModule.forRoot()],
declarations: [
- SearchComponent,
+ SearchComponent,
EntryComponent,
MainNavigationComponent,
SearchResultListComponent,
FormattedTimestampPipe,
StringToDatePipe,
MockComponent({ selector: 'app-entry' }),
- MockComponent({ selector: 'app-sorting', inputs: ['columnName','initColumnName','isDesc', 'defaultState']}),
+ MockComponent({ selector: 'app-sorting', inputs: ['columnName', 'initColumnName', 'isDesc', 'defaultState'] }),
MockComponent({ selector: 'input', inputs: ['options'] }),
- MockComponent({ selector: 'app-search'}),
+ MockComponent({ selector: 'app-search' }),
MockComponent({ selector: 'app-autocomplete', inputs: ['responsibilityForwarding'], outputs: ['responsibilityForwarding'] }),
MockComponent({ selector: 'loading-spinner' }),
],
providers: [
{ provide: Router, useValue: router },
- { provide: MdDialogRef, useClass: MockDialogRef },
{ provide: Overlay, useClass: Overlay },
{ provide: OVERLAY_PROVIDERS, useClass: OVERLAY_PROVIDERS },
{ provide: DaterangepickerConfig, useClass: DaterangepickerConfig },
{ provide: NotificationService, useClass: NotificationService },
- { provide: NotificationSearchSortService, useValue: mockNotificationSearchSortService },
+ { provide: NotificationSearchSortService, useValue: mockNotificationSearchSortService },
{ provide: SearchResultService, useValue: mockNotificationSearchSortService },
{ provide: SessionContext, useClass: SessionContext },
{ provide: ReminderService, useClass: ReminderService },
@@ -148,38 +140,13 @@
//fixture.detectChanges();
});
- it('should init correctly with correct user', async(() => {
- sessionContext.setCurrUser(correctUser);
-
- mockNotificationSearchSortService.searchResultNotifications = [];
- fixture.detectChanges();
- expect(component.user.id).toBe(correctUser.id);
- }));
-
- it('should should navigate to Overview after click at homebbutton', (() => {
- //spy = spyOn(router, 'navigate');
- //TODO spyOn(component, 'goToOverview').and.callThrough();
-
- fixture.detectChanges();
-
- fixture.whenStable().then(() => {
- const button = fixture.debugElement.nativeElement.querySelector('button#homebutton');
- button.click();
- fixture.detectChanges();
- expect(component.goToOverview).toHaveBeenCalled();
- expect(router.navigate).toHaveBeenCalledWith(['/overview']);
- });
- }));
-
-
+
it('should open a dialog to view a notification on button click', async(() => {
let entryOpend = false;
let dialog;
const testNotification = SEARCH_RESULT_NOTIFICATIONS[0];
- sessionContext.setCurrUser(correctUser);
-
fixture.detectChanges();
component.dialog.afterOpen.subscribe((value) => {
@@ -218,7 +185,7 @@
fixture.whenStable().then(() => {
const button = fixture.debugElement.nativeElement.querySelector('button#deletesearch');
- button.click();
+ button.click();
fixture.detectChanges();
expect(component.globalSearchFilter.searchString).toBe('');
@@ -231,6 +198,30 @@
expect(component.globalSearchFilter.fkRefBranch).toBe(-1);
expect(component.globalSearchFilter.fkRefGridTerritory).toBe(-1);
expect(component.globalSearchFilter.fastSearchSelected).toBe(true);
+ expect(sessionContext.getGlobalSearchFilter().fastSearchSelected).toBe(true);
});
}));
+
+
+it('should execute fast search and store it in the session context', (() => {
+ let dialog;
+ const globalSearchFilter: GlobalSearchFilter = new GlobalSearchFilter();
+ globalSearchFilter.searchString = 'a';
+ globalSearchFilter.statusOpenSelection = true;
+ globalSearchFilter.fastSearchSelected = true;
+
+ component.dialog.afterOpen.subscribe((value) => {
+ dialog = value.componentInstance;
+ spyOn(dialog, 'search');
+
+ });
+
+ fixture.whenStable().then(() => {
+ const button = fixture.debugElement.nativeElement.querySelector('button#search');
+ button.click();
+ fixture.detectChanges();
+ expect(component.currentSearchFilter).toBe(true);
+ expect(sessionContext.getGlobalSearchFilter().fastSearchSelected).toBe(true);
+ });
+}));
});