feat: add comprehensive loading feedback (#18)
This commit is contained in:
1 parent
45de0cebcc
commit
ec3319494b
47 files changed
+1753
-406
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { of, Subject, throwError } from 'rxjs';
|
||||
import { vi } from 'vitest';
|
||||
import { SessionService } from './session.service';
|
||||
|
||||
@@ -9,12 +9,29 @@ describe('SessionService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
TestBed.configureTestingModule({ providers: [SessionService, { provide: HttpClient, useValue: http }] });
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SessionService, { provide: HttpClient, useValue: http }],
|
||||
});
|
||||
});
|
||||
|
||||
it('distinguishes a pending session check from its final outcome', () => {
|
||||
const response = new Subject<{ authenticated: boolean }>();
|
||||
http.get.mockReturnValueOnce(response);
|
||||
const service = TestBed.inject(SessionService);
|
||||
|
||||
service.refresh();
|
||||
expect(service.status()).toBe('checking');
|
||||
|
||||
response.next({ authenticated: false });
|
||||
response.complete();
|
||||
expect(service.status()).toBe('anonymous');
|
||||
});
|
||||
|
||||
it('stores an authenticated user and applies its defaults', () => {
|
||||
const service = TestBed.inject(SessionService);
|
||||
http.get.mockReturnValueOnce(of({ authenticated: true, username: 'Camille', email: 'camille@example.com' }));
|
||||
http.get.mockReturnValueOnce(
|
||||
of({ authenticated: true, username: 'Camille', email: 'camille@example.com' }),
|
||||
);
|
||||
service.refresh();
|
||||
expect(service.username()).toBe('Camille');
|
||||
expect(service.email()).toBe('camille@example.com');
|
||||
|
||||
Reference in new issue
Block a user