Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Implemented flyout closure on navigation. #22

Merged
merged 4 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions e2e/flyout.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ describe('Flyout', () => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('lg');
element(by.css('.sky-btn-primary')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-lg'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

it('should match previous screenshot (screen: xs)', (done) => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('xs');
element(by.css('.sky-btn-primary')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-xs'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

Expand All @@ -33,7 +37,9 @@ describe('Flyout', () => {
browser.sleep(250);
element(by.css('.sky-flyout .sky-dropdown-button')).click();
SkyHostBrowser.moveCursorOffScreen();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-absolute-lg'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

Expand All @@ -44,39 +50,49 @@ describe('Flyout', () => {
browser.sleep(250);
element(by.css('.sky-flyout .sky-dropdown-button')).click();
SkyHostBrowser.moveCursorOffScreen();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-absolute-xs'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

it('should match previous screenshot when row iterators are enabled', (done) => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('lg');
element(by.css('#open-flyout-with-iterators')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-iterators-lg'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

it('should match previous screenshot when row iterators are enabled (screen: xs)', (done) => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('xs');
element(by.css('#open-flyout-with-iterators')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-iterators-xs'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

it('should match previous screenshot when row iterators are disabled', (done) => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('lg');
element(by.css('#open-flyout-with-iterators-disabled')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-no-iterators-lg'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});

it('should match previous screenshot when row iterator are disabled (screen: xs)', (done) => {
SkyHostBrowser.get('visual/flyout');
SkyHostBrowser.setWindowBreakpoint('xs');
element(by.css('#open-flyout-with-iterators-disabled')).click();
expect('body').toMatchBaselineScreenshot(done);
expect('body').toMatchBaselineScreenshot(done, {
screenshotName: 'flyout-no-iterators-xs'
});
element(by.css('.sky-flyout .sky-flyout-btn-close')).click();
});
});
Binary file removed screenshots-baseline/body0-chrome-1044x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body1-chrome-480x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body1-chrome-481x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body2-chrome-1044x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body3-chrome-480x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body3-chrome-481x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body4-chrome-1044x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body5-chrome-481x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body6-chrome-1044x788-dpr-1.png
Binary file not shown.
Binary file removed screenshots-baseline/body7-chrome-481x788-dpr-1.png
Binary file not shown.
97 changes: 72 additions & 25 deletions src/app/public/modules/flyout/flyout.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import {

import {
inject,
TestBed
TestBed,
fakeAsync,
tick
} from '@angular/core/testing';

import {
Router
} from '@angular/router';

import {
expect
} from '@skyux-sdk/testing';
Expand Down Expand Up @@ -39,6 +45,7 @@ import {
describe('Flyout service', () => {
let service: SkyFlyoutService;
let applicationRef: ApplicationRef;
let router: Router;

beforeEach(() => {
TestBed.configureTestingModule({
Blackbaud-TrevorBurch marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -57,43 +64,46 @@ describe('Flyout service', () => {
beforeEach(
inject(
[
ApplicationRef
ApplicationRef,
Router
],
(
_applicationRef: ApplicationRef
_applicationRef: ApplicationRef,
_router: Router
) => {
applicationRef = _applicationRef;
router = _router;
}
)
);

it('should only create a single host component', () => {
const spy = spyOn(service as any, 'createHostComponent').and.callThrough();
service.open(SkyFlyoutHostsTestComponent);
service.open(SkyFlyoutHostsTestComponent);
expect(spy.calls.count()).toEqual(1);
}
const spy = spyOn(service as any, 'createHostComponent').and.callThrough();
service.open(SkyFlyoutHostsTestComponent);
service.open(SkyFlyoutHostsTestComponent);
expect(spy.calls.count()).toEqual(1);
}
);

it('should return an instance with a close method', () => {
const flyout = service.open(SkyFlyoutHostsTestComponent);
expect(typeof flyout.close).toEqual('function');
}
const flyout = service.open(SkyFlyoutHostsTestComponent);
expect(typeof flyout.close).toEqual('function');
}
);

it('should expose a method to remove the flyout from the DOM', () => {
spyOn(window, 'setTimeout').and.callFake((fun: Function) => {
fun();
});
service.open(SkyFlyoutHostsTestComponent);
applicationRef.tick();
const spy = spyOn(service['host'].instance.messageStream, 'next').and.callThrough();
service.close();
applicationRef.tick();
expect(spy).toHaveBeenCalledWith({
type: SkyFlyoutMessageType.Close
});
}
spyOn(window, 'setTimeout').and.callFake((fun: Function) => {
fun();
});
service.open(SkyFlyoutHostsTestComponent);
applicationRef.tick();
const spy = spyOn(service['host'].instance.messageStream, 'next').and.callThrough();
service.close();
applicationRef.tick();
expect(spy).toHaveBeenCalledWith({
type: SkyFlyoutMessageType.Close
});
}
);

it('should dispose of any open host if the service is destroyed', () => {
Expand All @@ -109,6 +119,43 @@ describe('Flyout service', () => {
service.ngOnDestroy();
applicationRef.tick();
expect(spy).toHaveBeenCalled();
}
);
});

it('should close when the user navigates through history', fakeAsync(() => {
service.open(SkyFlyoutHostsTestComponent);
const closeSpy = spyOn(service, 'close').and.callThrough();

tick();
applicationRef.tick();

router.navigate(['/']);

tick();
applicationRef.tick();

expect(closeSpy).toHaveBeenCalled();
}));

it('should not close on route change if it is already closed', fakeAsync(() => {
service.open(SkyFlyoutHostsTestComponent);
const closeSpy = spyOn(service, 'close').and.callThrough();

tick();
applicationRef.tick();

service.close();

tick();
applicationRef.tick();

expect(closeSpy).toHaveBeenCalled();
closeSpy.calls.reset();

router.navigate(['/']);
tick();

expect(closeSpy).not.toHaveBeenCalled();

applicationRef.tick();
}));
});
24 changes: 19 additions & 5 deletions src/app/public/modules/flyout/flyout.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {
ComponentRef,
Injectable,
Type,
OnDestroy
OnDestroy,
Type
} from '@angular/core';

import {
NavigationStart,
Router
} from '@angular/router';

import {
Observable,
Subject
Expand All @@ -13,8 +18,8 @@ import {
import 'rxjs/add/operator/take';

import {
SkyWindowRefService,
SkyDynamicComponentService
SkyDynamicComponentService,
SkyWindowRefService
} from '@skyux/core';

import {
Expand Down Expand Up @@ -45,7 +50,8 @@ export class SkyFlyoutService implements OnDestroy {
constructor(
private adapter: SkyFlyoutAdapterService,
private windowRef: SkyWindowRefService,
private dynamicComponentService: SkyDynamicComponentService
private dynamicComponentService: SkyDynamicComponentService,
private router: Router
Blackbaud-TrevorBurch marked this conversation as resolved.
Show resolved Hide resolved
) { }

public ngOnDestroy(): void {
Expand All @@ -64,6 +70,14 @@ export class SkyFlyoutService implements OnDestroy {

if (!this.host) {
this.host = this.createHostComponent();

this.router.events
.takeWhile(() => this.host !== undefined)
.subscribe((event) => {
if (event instanceof NavigationStart) {
this.close();
}
});
}

const flyout = this.host.instance.attach(component, config);
Expand Down
8 changes: 8 additions & 0 deletions src/app/visual/flyout/flyout-demo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@ <h1>
>
Open toast
</button>

<button
class="sky-btn sky-btn-default"
type="button"
(click)="goToPage()"
>
Navigate to new page
</button>
</p>
11 changes: 10 additions & 1 deletion src/app/visual/flyout/flyout-demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
Component
} from '@angular/core';

import {
Router
} from '@angular/router';

import {
SkyModalService
} from '@skyux/modals';
Expand Down Expand Up @@ -33,7 +37,8 @@ export class FlyoutDemoComponent {
constructor(
public context: FlyoutDemoContext,
private modalService: SkyModalService,
private toastService: SkyToastService
private toastService: SkyToastService,
private router: Router
) { }

public openModal(): void {
Expand All @@ -49,4 +54,8 @@ export class FlyoutDemoComponent {
);
}

public goToPage(): void {
this.router.navigate(['/']);
}

}