From d962200b79a3ed8dfd6799f8104fe115d12cb59d Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Sat, 1 Aug 2026 10:52:17 +0200 Subject: [PATCH] test: cover assignment failure recovery --- .../src/app/features/users/users.spec.ts | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/myteamwallet_frontend_modern/src/app/features/users/users.spec.ts b/myteamwallet_frontend_modern/src/app/features/users/users.spec.ts index 867217d..8b955c4 100644 --- a/myteamwallet_frontend_modern/src/app/features/users/users.spec.ts +++ b/myteamwallet_frontend_modern/src/app/features/users/users.spec.ts @@ -548,6 +548,71 @@ describe('Users directory', () => { expect(mutationStayedActive).toBe(true); }); + it('keeps directory controls blocked until a failed assignment mutation clears', () => { + isAdmin.set(true); + create(); + http.expectOne(`${api}?page=1&limit=20`).flush(directoryPage([ada], 1, 60, true)); + fixture.detectChanges(); + button('Weiter').click(); + http.expectOne(`${api}?page=2&limit=20`).flush(directoryPage([ada], 2, 60, true)); + fixture.detectChanges(); + button('Zuordnungen verwalten').click(); + fixture.detectChanges(); + http.expectOne(`${adminApi}/players?assignment=all&page=1&limit=20`).flush( + playersPage({ + data: [ + { + id: 101, + firstName: 'Ada', + lastName: 'Lovelace', + active: true, + team: { id: 5, name: 'First Team', alias: 'first' }, + currentUser: { id: 7, firstName: 'Ada', lastName: 'Lovelace', status: { id: 1, name: 'Active' } }, + }, + ], + }), + ); + fixture.detectChanges(); + + const panel = (fixture.nativeElement as HTMLElement).querySelector('app-player-assignments')!; + panel.querySelector('.player-row button')!.click(); + closeDialog.next(true); + fixture.detectChanges(); + const unlink = http.expectOne(`${adminApi}/7/players/101`); + + const directoryForm = (fixture.nativeElement as HTMLElement).querySelector('.directory-search')!; + const directorySearch = directoryForm.querySelector('input[type="search"]')!; + const directorySearchButton = directoryForm.querySelector('button[type="submit"]')!; + const [previous, next] = [ + ...(fixture.nativeElement as HTMLElement).querySelectorAll('nav.pagination button'), + ]; + expect(directorySearch.disabled).toBe(true); + expect(directorySearchButton.disabled).toBe(true); + expect(previous.disabled).toBe(true); + expect(next.disabled).toBe(true); + + directorySearch.value = 'Other'; + directorySearch.dispatchEvent(new Event('input')); + directoryForm.dispatchEvent(new Event('submit')); + previous.click(); + next.click(); + fixture.detectChanges(); + expect(http.match((request) => request.url.startsWith(api))).toHaveLength(0); + expect(unlink.cancelled).toBe(false); + + unlink.flush({ message: 'Assignment failed' }, { status: 500, statusText: 'Server Error' }); + fixture.detectChanges(); + expect(text()).toContain('Zuordnung konnte nicht geƤndert werden. Assignment failed'); + expect(directorySearch.disabled).toBe(false); + expect(directorySearchButton.disabled).toBe(false); + expect(previous.disabled).toBe(false); + expect(next.disabled).toBe(false); + expect(http.match((request) => request.url.startsWith(api))).toHaveLength(0); + + directoryForm.dispatchEvent(new Event('submit')); + http.expectOne(`${api}?page=1&limit=20&search=Other`).flush(directoryPage([])); + }); + it('shows a persistent explanation for disabled self-deactivation', () => { isAdmin.set(true); currentUser.set({ id: 1, firstName: 'Grace', lastName: 'Admin', role: { id: 1 } });