From ce191a9a23155ec56ae725dd42627870f98d46f3 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 30 Aug 2016 16:16:31 +0100 Subject: [PATCH] Cannot click on a item in search result --- .../components/search/search-bar.component.ts | 36 ++------- .../components/search/search.component.html | 2 +- .../app/components/search/search.component.ts | 7 +- .../activiti-tasklist.service.spec.ts | 10 +-- .../ng2-alfresco-search/demo/package.json | 4 +- .../ng2-alfresco-search/demo/src/main.ts | 2 +- .../ng2-alfresco-search/karma.conf.js | 3 +- .../ng2-alfresco-search/package.json | 1 + .../components/alfresco-search.component.ts | 4 +- .../services/alfresco-search.service.spec.ts | 75 +++++++++++++++++-- .../src/services/alfresco-search.service.ts | 11 +-- .../alfresco-thumbnail.service.spec.ts | 7 +- .../services/alfresco-thumbnail.service.ts | 4 +- 13 files changed, 94 insertions(+), 72 deletions(-) diff --git a/demo-shell-ng2/app/components/search/search-bar.component.ts b/demo-shell-ng2/app/components/search/search-bar.component.ts index a55f630e1c..cb83bf6ce6 100644 --- a/demo-shell-ng2/app/components/search/search-bar.component.ts +++ b/demo-shell-ng2/app/components/search/search-bar.component.ts @@ -16,13 +16,9 @@ */ import { Component, EventEmitter, Output } from '@angular/core'; -import { Router } from '@angular/router'; import { ALFRESCO_SEARCH_DIRECTIVES } from 'ng2-alfresco-search'; import { VIEWERCOMPONENT } from 'ng2-alfresco-viewer'; -import { - AlfrescoAuthenticationService, - AlfrescoContentService -} from 'ng2-alfresco-core'; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; declare let __moduleName: string; @@ -30,48 +26,26 @@ declare let __moduleName: string; moduleId: __moduleName, selector: 'search-bar', templateUrl: './search-bar.component.html', - styles: [` - `], - directives: [ ALFRESCO_SEARCH_DIRECTIVES, VIEWERCOMPONENT ] + directives: [ALFRESCO_SEARCH_DIRECTIVES, VIEWERCOMPONENT] }) export class SearchBarComponent { - urlFile: string; - fileName: string; - mimeType: string; + fileNodeId: string; fileShowed: boolean = false; @Output() expand = new EventEmitter(); - constructor( - public router: Router, - public auth: AlfrescoAuthenticationService, - public contentService: AlfrescoContentService - - ) { + constructor(public auth: AlfrescoAuthenticationService) { } isLoggedIn(): boolean { return this.auth.isLoggedIn(); } - /** - * Called when a new search term is submitted - * - * @param params Parameters relating to the search - */ - searchTermChange(params) { - this.router.navigate(['Search', { - q: params.value - }]); - } - onFileClicked(event) { if (event.value.entry.isFile) { - this.fileName = event.value.entry.name; - this.mimeType = event.value.entry.content.mimeType; - this.urlFile = this.contentService.getContentUrl(event.value); + this.fileNodeId = event.value.entry.id; this.fileShowed = true; } } diff --git a/demo-shell-ng2/app/components/search/search.component.html b/demo-shell-ng2/app/components/search/search.component.html index 93568e6b8d..d67a727047 100644 --- a/demo-shell-ng2/app/components/search/search.component.html +++ b/demo-shell-ng2/app/components/search/search.component.html @@ -3,6 +3,6 @@ - +
diff --git a/demo-shell-ng2/app/components/search/search.component.ts b/demo-shell-ng2/app/components/search/search.component.ts index bf836b7783..2d14f09e4b 100644 --- a/demo-shell-ng2/app/components/search/search.component.ts +++ b/demo-shell-ng2/app/components/search/search.component.ts @@ -52,10 +52,7 @@ declare let __moduleName: string; }) export class SearchComponent { - previewContentUrl: string; - previewName: string; - previewMimeType: string; - previewActive: boolean = false; + fileShowed: boolean = false; fileNodeId: string; constructor(public contentService: AlfrescoContentService) { @@ -64,7 +61,7 @@ export class SearchComponent { onFileClicked(event) { if (event.value.entry.isFile) { this.fileNodeId = event.value.entry.id; - this.previewActive = true; + this.fileShowed = true; } } } diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts index 3c9eafefc8..8684988f3a 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.spec.ts @@ -15,11 +15,11 @@ * limitations under the License. */ -import {it, describe, inject, beforeEach, beforeEachProviders} from '@angular/core/testing'; -import {ActivitiTaskListService} from './activiti-tasklist.service'; -import {AlfrescoSettingsService, AlfrescoAuthenticationService} from 'ng2-alfresco-core'; -import {TaskDetailsModel} from '../models/task-details.model'; -import {Comment} from '../models/comment.model'; +import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; +import { ActivitiTaskListService } from './activiti-tasklist.service'; +import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { TaskDetailsModel } from '../models/task-details.model'; +import { Comment } from '../models/comment.model'; declare let AlfrescoApi: any; declare let jasmine: any; diff --git a/ng2-components/ng2-alfresco-search/demo/package.json b/ng2-components/ng2-alfresco-search/demo/package.json index fb97aa08b5..0046304c90 100644 --- a/ng2-components/ng2-alfresco-search/demo/package.json +++ b/ng2-components/ng2-alfresco-search/demo/package.json @@ -67,8 +67,8 @@ "material-design-lite": "1.1.3", "alfresco-js-api": "^0.3.0", - "ng2-alfresco-core": "^0.1.36", - "ng2-alfresco-search": "^0.1.25" + "ng2-alfresco-core": "^0.3.0", + "ng2-alfresco-search": "^0.3.0" }, "devDependencies": { "concurrently": "2.0.0", diff --git a/ng2-components/ng2-alfresco-search/demo/src/main.ts b/ng2-components/ng2-alfresco-search/demo/src/main.ts index b66a9c17a3..b6b37e5568 100644 --- a/ng2-components/ng2-alfresco-search/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-search/demo/src/main.ts @@ -33,7 +33,7 @@ import { @Component({ selector: 'alfresco-search-demo', template: `
-
+



diff --git a/ng2-components/ng2-alfresco-search/karma.conf.js b/ng2-components/ng2-alfresco-search/karma.conf.js index 879e251aa3..ed94344c13 100644 --- a/ng2-components/ng2-alfresco-search/karma.conf.js +++ b/ng2-components/ng2-alfresco-search/karma.conf.js @@ -4,7 +4,7 @@ module.exports = function (config) { var configuration = { basePath: '.', - frameworks: ['jasmine'], + frameworks: ['jasmine-ajax', 'jasmine'], files: [ // paths loaded by Karma @@ -67,6 +67,7 @@ module.exports = function (config) { plugins: [ 'karma-jasmine', 'karma-coverage', + 'karma-jasmine-ajax', 'karma-chrome-launcher', 'karma-mocha-reporter', 'karma-jasmine-html-reporter' diff --git a/ng2-components/ng2-alfresco-search/package.json b/ng2-components/ng2-alfresco-search/package.json index 530b4f88c9..f54951f627 100644 --- a/ng2-components/ng2-alfresco-search/package.json +++ b/ng2-components/ng2-alfresco-search/package.json @@ -88,6 +88,7 @@ "karma-coverage": "1.0.0", "karma-coveralls": "1.1.2", "karma-jasmine": "1.0.2", + "karma-jasmine-ajax": "^0.1.13", "karma-mocha-reporter": "2.0.3", "karma-jasmine-html-reporter": "0.2.0", "license-check": "1.1.5", diff --git a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts index 0b9112cf39..3fc41ab0b7 100644 --- a/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts +++ b/ng2-components/ng2-alfresco-search/src/components/alfresco-search.component.ts @@ -64,7 +64,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit { route: any[] = []; - constructor(private _alfrescoSearchService: AlfrescoSearchService, + constructor(private alfrescoSearchService: AlfrescoSearchService, private translate: AlfrescoTranslationService, private _alfrescoThumbnailService: AlfrescoThumbnailService, @Optional() params: RouteParams) { @@ -118,7 +118,7 @@ export class AlfrescoSearchComponent implements OnChanges, OnInit { */ public displaySearchResults(searchTerm): void { if (searchTerm !== null) { - this._alfrescoSearchService + this.alfrescoSearchService .getLiveSearchResults(searchTerm) .subscribe( results => { diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts index 3877bf2b86..e72f0c8509 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.spec.ts @@ -15,17 +15,76 @@ * limitations under the License. */ -import { - describe, - beforeEach -} from '@angular/core/testing'; -import {AlfrescoSearchService} from './alfresco-search.service'; +import { it, describe, beforeEach, inject, beforeEachProviders } from '@angular/core/testing'; +import { AlfrescoSearchService } from './alfresco-search.service'; +import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; + +declare let jasmine: any; describe('AlfrescoSearchService', () => { - let service: AlfrescoSearchService; + let service: any; - beforeEach(() => { - service = new AlfrescoSearchService(null); + let fakeSearch = { + list: { + pagination: { + count: 1, + hasMoreItems: false, + totalItems: 1, + skipCount: 0, + maxItems: 100 + }, + entries: [ + { + entry: { + id: '123', + name: 'MyDoc', + content: { + mimetype: 'text/plain' + }, + createdByUser: { + displayName: 'John Doe' + }, + modifiedByUser: { + displayName: 'John Doe' + } + } + } + ] + } + }; + + beforeEachProviders(() => { + return [ + AlfrescoSearchService, + AlfrescoSettingsService, + AlfrescoAuthenticationService + ]; }); + + beforeEach(inject([AlfrescoSearchService], (alfrescoSearchService: AlfrescoSearchService) => { + jasmine.Ajax.install(); + service = alfrescoSearchService; + })); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('should return search list', (done) => { + service.getSearchNodesPromise('MyDoc').then( + (res) => { + expect(res).toBeDefined(); + expect(res.list.entries[0].entry.name).toEqual('MyDoc'); + done(); + } + ); + + jasmine.Ajax.requests.mostRecent().respondWith({ + 'status': 200, + contentType: 'application/json', + responseText: JSON.stringify(fakeSearch) + }); + }); + }); diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.ts index f248e4d553..cbfc12dbf3 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-search.service.ts @@ -17,12 +17,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Rx'; - -import { - AlfrescoAuthenticationService -} from 'ng2-alfresco-core'; - -declare let AlfrescoApi: any; +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; /** * Internal service used by Document List component. @@ -33,14 +28,14 @@ export class AlfrescoSearchService { constructor(private authService: AlfrescoAuthenticationService) { } - private getSearchNodesPromise(term: string) { + public getSearchNodesPromise(term: string) { let nodeId = '-root-'; let opts = { include: ['path'], rootNodeId: nodeId, nodeType: 'cm:content' }; - return this.authService.getAlfrescoApi().search.liveSearchNodes(term, opts); + return this.authService.getAlfrescoApi().core.searchApi.liveSearchNodes(term, opts); } /** diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts index b5ddf4442c..32711fd171 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.spec.ts @@ -15,11 +15,8 @@ * limitations under the License. */ -import { - describe, - beforeEach -} from '@angular/core/testing'; -import {AlfrescoThumbnailService} from './alfresco-thumbnail.service'; +import { describe, beforeEach } from '@angular/core/testing'; +import { AlfrescoThumbnailService } from './alfresco-thumbnail.service'; describe('AlfrescoThumbnailService', () => { diff --git a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts index d05c0d1c3a..593f2c8921 100644 --- a/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts +++ b/ng2-components/ng2-alfresco-search/src/services/alfresco-thumbnail.service.ts @@ -16,9 +16,7 @@ */ import { Injectable } from '@angular/core'; -import { - AlfrescoContentService -} from 'ng2-alfresco-core'; +import { AlfrescoContentService } from 'ng2-alfresco-core'; @Injectable() export class AlfrescoThumbnailService {