feat: add notification functionality

This commit is contained in:
2025-12-20 20:37:49 -03:00
parent dc3def94c4
commit d0362e2d7d
3 changed files with 22 additions and 5 deletions

View File

@@ -1 +1,4 @@
@if(this.showNotification()) {
<app-notification></app-notification>
}
<router-outlet></router-outlet>

View File

@@ -2,19 +2,29 @@ import { TestBed } from '@angular/core/testing';
import { App } from './app';
import { strings } from './strings';
import { STRINGS_INJECTOR } from './app.config';
import { Notifier } from './services/notifier';
import { signal } from '@angular/core';
describe('App', () => {
let notifier: jasmine.SpyObj<Notifier>;
beforeEach(async () => {
notifier = jasmine.createSpyObj(Notifier.name, [], {
notification$: signal<Notification | null>(null),
});
await TestBed.configureTestingModule({
imports: [App],
providers: [{ provide: STRINGS_INJECTOR, useValue: strings }],
providers: [
{ provide: STRINGS_INJECTOR, useValue: strings },
{ provide: Notifier, useValue: notifier },
],
}).compileComponents();
});
it('should create the app', () => {
const fixture = TestBed.createComponent(App);
const app = fixture.componentInstance;
TestBed.tick();
expect(app).toBeTruthy();
});
});

View File

@@ -1,11 +1,15 @@
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { Notification } from './components/notification/notification';
import { Notifier } from './services/notifier';
import { computed } from '@angular/core';
@Component({
selector: 'app-root',
imports: [RouterOutlet],
imports: [RouterOutlet, Notification],
templateUrl: './app.html',
styleUrl: './app.scss',
})
export class App {
private readonly notifier = inject(Notifier);
showNotification = computed(() => this.notifier.notification$() !== null);
}