Skip to content
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
31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"progressbar.js": "1.1.1",
"rxjs": "7.8.2",
"sass": "^1.93.2",
"shallow-render": "^20.0.0",
"time-ago-pipe": "^1.3.2",
"ts-key-enum": "^3.0.13",
"vis-data": "^8.0.3",
Expand Down Expand Up @@ -131,6 +130,7 @@
"karma-junit-reporter": "^2.0.1",
"karma-spec-reporter": "^0.0.36",
"karma-verbose-reporter": "^0.0.8",
"ng-mocks": "^14.15.0",
"patch-package": "^8.0.1",
"prettier": "^3.6.2",
"storybook": "10.1.11",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Shallow } from 'shallow-render';
import { ComponentFixture } from '@angular/core/testing';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';

import { AnnouncementModule } from '@announcement/announcement.module';
import {
Expand Down Expand Up @@ -26,68 +27,70 @@ class DummyInstallPromptEvent
let prompted: boolean;

describe('AndroidAppNotifyComponent', () => {
let shallow: Shallow<AndroidAppNotifyComponent>;
const waitForPromptEvent = async (fixture) => {
const event = new DummyInstallPromptEvent();
window.dispatchEvent(event);
fixture.detectChanges();
await fixture.whenStable();
};
beforeEach(() => {
beforeEach(async () => {
prompted = false;
shallow = new Shallow(AndroidAppNotifyComponent, AnnouncementModule);
await MockBuilder(AndroidAppNotifyComponent, AnnouncementModule);
});

afterEach(() => {
localStorage.clear();
});

it('should exist', async () => {
const { element } = await shallow.render();
const waitForPromptEvent = async (
fixture: ComponentFixture<AndroidAppNotifyComponent>,
) => {
const event = new DummyInstallPromptEvent();
window.dispatchEvent(event);
fixture.detectChanges();
await fixture.whenStable();
};

it('should exist', () => {
const fixture = MockRender(AndroidAppNotifyComponent);

expect(element).not.toBeNull();
expect(fixture.debugElement).not.toBeNull();
});

it('should be invisible before `beforeinstallprompt` event', async () => {
const { find } = await shallow.render();
it('should be invisible before `beforeinstallprompt` event', () => {
MockRender(AndroidAppNotifyComponent);

expect(find('div').length).toBe(0);
expect(ngMocks.findAll('div').length).toBe(0);
});

it('should appear when the `beforeinstallprompt` fires', async () => {
const { find, fixture } = await shallow.render();
const fixture = MockRender(AndroidAppNotifyComponent);
await waitForPromptEvent(fixture);

expect(find('div').length).toBeGreaterThan(0);
expect(ngMocks.findAll('div').length).toBeGreaterThan(0);
});

it('has a clickable button that shows the prompt', async () => {
const { find, fixture } = await shallow.render();
const fixture = MockRender(AndroidAppNotifyComponent);
await waitForPromptEvent(fixture);
find('.prompt-button')[0].triggerEventHandler('click', {});
ngMocks.findAll('.prompt-button')[0].triggerEventHandler('click', {});

expect(prompted).toBeTruthy();
});

it('should dismiss itself after the App Install Banner appears', async () => {
const { find, fixture } = await shallow.render();
const fixture = MockRender(AndroidAppNotifyComponent);
await waitForPromptEvent(fixture);
find('.prompt-button')[0].triggerEventHandler('click', {});
ngMocks.findAll('.prompt-button')[0].triggerEventHandler('click', {});
await fixture.whenStable();
fixture.detectChanges();
await fixture.whenStable();

expect(find('div').length).toBe(0);
expect(ngMocks.findAll('div').length).toBe(0);
});

it('should be dismissable from a close button', async () => {
const { find, fixture } = await shallow.render();
const fixture = MockRender(AndroidAppNotifyComponent);
await waitForPromptEvent(fixture);
find('.dismiss-button')[0].triggerEventHandler('click', {});
ngMocks.findAll('.dismiss-button')[0].triggerEventHandler('click', {});
fixture.detectChanges();
await fixture.whenStable();

expect(find('div').length).toBe(0);
expect(ngMocks.findAll('div').length).toBe(0);
const dismissed = localStorage.getItem(
AndroidAppNotifyComponent.storageKey,
);
Expand All @@ -97,9 +100,9 @@ describe('AndroidAppNotifyComponent', () => {

it('should not show up if previously dismissed', async () => {
localStorage.setItem(AndroidAppNotifyComponent.storageKey, 'true');
const { find, fixture } = await shallow.render();
const fixture = MockRender(AndroidAppNotifyComponent);
await waitForPromptEvent(fixture);

expect(find('div').length).toBe(0);
expect(ngMocks.findAll('div').length).toBe(0);
});
});
Loading