Skip to content

Commit

Permalink
Unset logbook id when clicking browser back button (#273)
Browse files Browse the repository at this point in the history
Should close: #213
  • Loading branch information
minottic authored Aug 18, 2023
1 parent 4a76188 commit 129eac8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
25 changes: 19 additions & 6 deletions scilog/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { LogbookInfoService } from './core/logbook-info.service';

describe('AppComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule
],
providers: [
{
provide: LogbookInfoService,
useValue: { logbookInfo: {id: 'id'} }
}
],
declarations: [
AppComponent
],
Expand All @@ -26,10 +33,16 @@ describe('AppComponent', () => {
// expect(app.title).toEqual('SciLog');
// });

// it('should render title', () => {
// const fixture = TestBed.createComponent(AppComponent);
// fixture.detectChanges();
// const compiled = fixture.nativeElement;
// expect(compiled.querySelector('.content span').textContent).toContain('scilog app is running!');
// });
it('should unset the logbook', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
const popStateEvent = new PopStateEvent('popstate');
Object.defineProperty(
popStateEvent,
'target',
{writable: false, value: {location: {pathname: '/overview'}}}
);
window.dispatchEvent(popStateEvent);
expect(app['logbookInfo'].logbookInfo).toBeNull();
});
});
13 changes: 9 additions & 4 deletions scilog/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit} from '@angular/core';
import { Component, HostListener, OnInit } from '@angular/core';
import { LogbookInfoService } from './core/logbook-info.service';


@Component({
Expand All @@ -11,7 +12,7 @@ export class AppComponent implements OnInit {
light_mode = true;
disable_log = false;

constructor() {
constructor(private logbookInfo: LogbookInfoService) {
}

ngOnInit(): void {
Expand All @@ -30,6 +31,10 @@ export class AppComponent implements OnInit {
}
}

}

@HostListener('window:popstate', ['$event'])
onPopState(event: Event & {target: Window}) {
if (event.target.location.pathname === '/overview')
this.logbookInfo.logbookInfo = null;
}

}

0 comments on commit 129eac8

Please sign in to comment.