reset selection state on navigation (#793)

This commit is contained in:
Cilibiu Bogdan
2018-11-12 14:56:02 +02:00
committed by Denys Vuika
parent c9f2895ead
commit aa6995e7b2
2 changed files with 51 additions and 1 deletions

View File

@@ -28,16 +28,43 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
import { AppConfigService, UserPreferencesService } from '@alfresco/adf-core';
import { AppLayoutComponent } from './app-layout.component';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { Store } from '@ngrx/store';
import { AppStore } from '../../../store/states';
import { SetSelectedNodesAction } from '../../../store/actions';
import { Router, NavigationStart } from '@angular/router';
import { appSelection } from '../../../store/selectors/app.selectors';
import { Subject } from 'rxjs';
class MockRouter {
private url = 'some-url';
private subject = new Subject();
events = this.subject.asObservable();
routerState = { snapshot: { url: this.url } };
navigate(url: string) {
const navigationStart = new NavigationStart(0, url);
this.subject.next(navigationStart);
}
}
describe('AppLayoutComponent', () => {
let fixture: ComponentFixture<AppLayoutComponent>;
let component: AppLayoutComponent;
let appConfig: AppConfigService;
let userPreference: UserPreferencesService;
let store: Store<AppStore>;
let router: Router;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
providers: [
Store,
{
provide: Router,
useClass: MockRouter
}
],
declarations: [AppLayoutComponent],
schemas: [NO_ERRORS_SCHEMA]
});
@@ -45,6 +72,8 @@ describe('AppLayoutComponent', () => {
fixture = TestBed.createComponent(AppLayoutComponent);
component = fixture.componentInstance;
appConfig = TestBed.get(AppConfigService);
store = TestBed.get(Store);
router = TestBed.get(Router);
userPreference = TestBed.get(UserPreferencesService);
});
@@ -108,4 +137,17 @@ describe('AppLayoutComponent', () => {
expect(component.expandedSidenav).toBe(false);
});
});
it('should reset selection before navigation', done => {
fixture.detectChanges();
const selection = [{ entry: { id: 'nodeId', name: 'name' } }];
store.dispatch(new SetSelectedNodesAction(selection));
router.navigate(['somewhere/over/the/rainbow']);
fixture.detectChanges();
store.select(appSelection).subscribe(state => {
expect(state.isEmpty).toBe(true);
done();
});
});
});