mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
Use ADF Notification Service instead of NgRx store (#3991)
This commit is contained in:
@@ -27,12 +27,14 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||
import { SearchInputComponent } from './search-input.component';
|
||||
import { AppTestingModule } from '../../../testing/app-testing.module';
|
||||
import { Actions, ofType } from '@ngrx/effects';
|
||||
import { SearchByTermAction, SearchActionTypes, SnackbarErrorAction, SnackbarActionTypes } from '@alfresco/aca-shared/store';
|
||||
import { SearchByTermAction, SearchActionTypes } from '@alfresco/aca-shared/store';
|
||||
import { AppHookService, AppService } from '@alfresco/aca-shared';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
|
||||
import { SearchNavigationService } from '../search-navigation.service';
|
||||
import { BehaviorSubject, Subject } from 'rxjs';
|
||||
import { NotificationService } from '@alfresco/adf-core';
|
||||
import { MatSnackBarModule } from '@angular/material/snack-bar';
|
||||
|
||||
describe('SearchInputComponent', () => {
|
||||
let fixture: ComponentFixture<SearchInputComponent>;
|
||||
@@ -40,6 +42,8 @@ describe('SearchInputComponent', () => {
|
||||
let actions$: Actions;
|
||||
let appHookService: AppHookService;
|
||||
let searchInputService: SearchNavigationService;
|
||||
let showErrorSpy: jasmine.Spy;
|
||||
|
||||
const appServiceMock = {
|
||||
appNavNarMode$: new BehaviorSubject('collapsed'),
|
||||
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode'),
|
||||
@@ -49,7 +53,7 @@ describe('SearchInputComponent', () => {
|
||||
beforeEach(() => {
|
||||
appServiceMock.setAppNavbarMode.calls.reset();
|
||||
TestBed.configureTestingModule({
|
||||
imports: [AppTestingModule, SearchInputComponent],
|
||||
imports: [AppTestingModule, SearchInputComponent, MatSnackBarModule],
|
||||
providers: [
|
||||
{
|
||||
provide: AppService,
|
||||
@@ -65,6 +69,9 @@ describe('SearchInputComponent', () => {
|
||||
appHookService = TestBed.inject(AppHookService);
|
||||
searchInputService = TestBed.inject(SearchNavigationService);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
const notificationService = TestBed.inject(NotificationService);
|
||||
showErrorSpy = spyOn(notificationService, 'showError');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -171,19 +178,9 @@ describe('SearchInputComponent', () => {
|
||||
component.onSearchChange(searchedTerm);
|
||||
});
|
||||
|
||||
it('should show snack for empty search', (done) => {
|
||||
const searchedTerm = '';
|
||||
actions$
|
||||
.pipe(
|
||||
ofType<SnackbarErrorAction>(SnackbarActionTypes.Error),
|
||||
map((action) => {
|
||||
expect(action.payload).toBe('APP.BROWSE.SEARCH.EMPTY_SEARCH');
|
||||
})
|
||||
)
|
||||
.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
component.onSearchSubmit(searchedTerm);
|
||||
it('should show snack for empty search', () => {
|
||||
component.onSearchSubmit('');
|
||||
expect(showErrorSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -23,10 +23,10 @@
|
||||
*/
|
||||
|
||||
import { AppHookService, AppService } from '@alfresco/aca-shared';
|
||||
import { AppStore, SearchByTermAction, SearchOptionIds, SearchOptionModel, SnackbarErrorAction } from '@alfresco/aca-shared/store';
|
||||
import { AppStore, SearchByTermAction, SearchOptionIds, SearchOptionModel } from '@alfresco/aca-shared/store';
|
||||
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
|
||||
import { AppConfigService } from '@alfresco/adf-core';
|
||||
import { Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { AppConfigService, NotificationService } from '@alfresco/adf-core';
|
||||
import { Component, inject, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { MatMenuModule, MatMenuTrigger } from '@angular/material/menu';
|
||||
import { NavigationEnd, PRIMARY_OUTLET, Router, RouterEvent, UrlSegment, UrlSegmentGroup, UrlTree } from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
@@ -67,6 +67,8 @@ import { FormsModule } from '@angular/forms';
|
||||
host: { class: 'aca-search-input' }
|
||||
})
|
||||
export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
private notificationService = inject(NotificationService);
|
||||
|
||||
onDestroy$: Subject<boolean> = new Subject<boolean>();
|
||||
hasOneChange = false;
|
||||
hasNewChange = false;
|
||||
@@ -174,7 +176,7 @@ export class SearchInputComponent implements OnInit, OnDestroy {
|
||||
|
||||
this.searchByOption();
|
||||
} else {
|
||||
this.store.dispatch(new SnackbarErrorAction('APP.BROWSE.SEARCH.EMPTY_SEARCH'));
|
||||
this.notificationService.showError('APP.BROWSE.SEARCH.EMPTY_SEARCH');
|
||||
}
|
||||
|
||||
if (this.trigger) {
|
||||
|
@@ -24,9 +24,9 @@
|
||||
|
||||
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||
import { SearchResultsComponent } from './search-results.component';
|
||||
import { AppConfigService, TranslationService } from '@alfresco/adf-core';
|
||||
import { AppConfigService, NotificationService, TranslationService } from '@alfresco/adf-core';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { NavigateToFolder, SnackbarErrorAction } from '@alfresco/aca-shared/store';
|
||||
import { NavigateToFolder } from '@alfresco/aca-shared/store';
|
||||
import { Pagination, SearchRequest } from '@alfresco/js-api';
|
||||
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
@@ -44,6 +44,7 @@ describe('SearchComponent', () => {
|
||||
let router: Router;
|
||||
const searchRequest = {} as SearchRequest;
|
||||
let params: BehaviorSubject<any>;
|
||||
let showErrorSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
params = new BehaviorSubject({ q: 'TYPE: "cm:folder" AND %28=cm: name: email OR cm: name: budget%29' });
|
||||
@@ -78,6 +79,9 @@ describe('SearchComponent', () => {
|
||||
translate = TestBed.inject(TranslationService);
|
||||
router = TestBed.inject(Router);
|
||||
|
||||
const notificationService = TestBed.inject(NotificationService);
|
||||
showErrorSpy = spyOn(notificationService, 'showError');
|
||||
|
||||
config.config = {
|
||||
search: {}
|
||||
};
|
||||
@@ -103,7 +107,7 @@ describe('SearchComponent', () => {
|
||||
queryBuilder.execute();
|
||||
tick();
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('APP.BROWSE.SEARCH.ERRORS.GENERIC'));
|
||||
expect(showErrorSpy).toHaveBeenCalledWith('APP.BROWSE.SEARCH.ERRORS.GENERIC');
|
||||
}));
|
||||
|
||||
it('should raise a known error if search fails', fakeAsync(() => {
|
||||
@@ -122,7 +126,7 @@ describe('SearchComponent', () => {
|
||||
queryBuilder.execute();
|
||||
tick();
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('Known Error'));
|
||||
expect(showErrorSpy).toHaveBeenCalledWith('Known Error');
|
||||
}));
|
||||
|
||||
it('should raise a generic error if search fails', fakeAsync(() => {
|
||||
@@ -141,7 +145,7 @@ describe('SearchComponent', () => {
|
||||
queryBuilder.execute();
|
||||
tick();
|
||||
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new SnackbarErrorAction('Generic Error'));
|
||||
expect(showErrorSpy).toHaveBeenCalledWith('Generic Error');
|
||||
}));
|
||||
|
||||
it('should decode encoded URI', () => {
|
||||
|
@@ -22,7 +22,7 @@
|
||||
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { Component, inject, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { NodeEntry, Pagination, ResultSetPaging } from '@alfresco/js-api';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { AlfrescoViewerComponent, DocumentListModule, SearchModule, SearchQueryBuilderService, TagService } from '@alfresco/adf-content-services';
|
||||
@@ -31,10 +31,9 @@ import {
|
||||
NavigateToFolder,
|
||||
SetInfoDrawerPreviewStateAction,
|
||||
SetInfoDrawerStateAction,
|
||||
ShowInfoDrawerPreviewAction,
|
||||
SnackbarErrorAction
|
||||
ShowInfoDrawerPreviewAction
|
||||
} from '@alfresco/aca-shared/store';
|
||||
import { DataTableModule, PaginationComponent, TranslationService, ViewerModule } from '@alfresco/adf-core';
|
||||
import { DataTableModule, NotificationService, PaginationComponent, TranslationService, ViewerModule } from '@alfresco/adf-core';
|
||||
import { combineLatest } from 'rxjs';
|
||||
import {
|
||||
ContextActionsDirective,
|
||||
@@ -94,6 +93,8 @@ import { DocumentListPresetRef, DynamicColumnComponent } from '@alfresco/adf-ext
|
||||
styleUrls: ['./search-results.component.scss']
|
||||
})
|
||||
export class SearchResultsComponent extends PageComponent implements OnInit {
|
||||
private notificationService = inject(NotificationService);
|
||||
|
||||
infoDrawerPreview$ = this.store.select(infoDrawerPreview);
|
||||
|
||||
searchedWord: string;
|
||||
@@ -180,13 +181,13 @@ export class SearchResultsComponent extends PageComponent implements OnInit {
|
||||
const { statusCode } = JSON.parse(error.message).error;
|
||||
|
||||
const messageKey = `APP.BROWSE.SEARCH.ERRORS.${statusCode}`;
|
||||
let translated = this.translationService.instant(messageKey);
|
||||
let message = this.translationService.instant(messageKey);
|
||||
|
||||
if (translated === messageKey) {
|
||||
translated = this.translationService.instant(`APP.BROWSE.SEARCH.ERRORS.GENERIC`);
|
||||
if (message === messageKey) {
|
||||
message = this.translationService.instant(`APP.BROWSE.SEARCH.ERRORS.GENERIC`);
|
||||
}
|
||||
|
||||
this.store.dispatch(new SnackbarErrorAction(translated));
|
||||
this.notificationService.showError(message);
|
||||
}
|
||||
|
||||
private isOperator(input: string): boolean {
|
||||
|
Reference in New Issue
Block a user