From 2d0171132019306a50e0475cfd1f8c06d2f32ac6 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Mon, 3 Nov 2025 19:04:52 -0500 Subject: [PATCH] update --- tests/ui/profileModalController.test.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/ui/profileModalController.test.js diff --git a/tests/ui/profileModalController.test.js b/tests/ui/profileModalController.test.js new file mode 100644 index 00000000..ba571976 --- /dev/null +++ b/tests/ui/profileModalController.test.js @@ -0,0 +1 @@ +import { ProfileModalController } from '../../js/ui/profileModalController.js'; import { userLogger } from '../../js/utils/logger.js'; describe('ProfileModalController - Direct Messages Error Handling', () => { let controller; let mockUserLoggerWarn; beforeEach(() => { jest.spyOn(userLogger, 'warn').mockImplementation(() => {}); mockUserLoggerWarn = jest.spyOn(userLogger, 'warn'); controller = new ProfileModalController({ /* minimal mocks for services/state */ }); jest.spyOn(controller, 'setMessagesLoadingState'); jest.spyOn(controller, 'setMessagesAnnouncement'); jest.spyOn(controller, 'updateMessagesReloadState'); controller.directMessagesCache = []; // Empty for error state }); afterEach(() => { jest.restoreAllMocks(); }); it('handles "no-decryptors" with specific message, no warn log, and enables reload', () => { const detail = { context: { reason: 'no-decryptors' }, error: new Error('Mock signer unlock error') }; controller.handleDirectMessagesError(detail); expect(controller.setMessagesLoadingState).toHaveBeenCalledWith('error', { message: 'Unlock your signer to read direct messages.' }); expect(mockUserLoggerWarn).not.toHaveBeenCalled(); // No log for this reason expect(controller.updateMessagesReloadState).toHaveBeenCalled(); // Reload affordance }); it('handles other reasons with generic message, warn log, and enables reload', () => { const detail = { context: { reason: 'relay-failed' }, // Mock real transport error error: new Error('Mock relay error') }; controller.handleDirectMessagesError(detail); expect(controller.setMessagesLoadingState).toHaveBeenCalledWith('error', { message: 'Unable to sync direct messages right now.' }); expect(mockUserLoggerWarn).toHaveBeenCalledWith( '[profileModal] Direct message sync issue detected:', detail.error ); // Warn for transport errors expect(controller.updateMessagesReloadState).toHaveBeenCalled(); // Reload affordance }); it('handles non-empty cache for "no-decryptors" (announcement only, no error state)', () => { controller.directMessagesCache = ['mock-message']; // Non-empty const detail = { context: { reason: 'no-decryptors' } }; controller.handleDirectMessagesError(detail); // Uses announcement, not error state expect(controller.setMessagesAnnouncement).toHaveBeenCalledWith('Unable to sync direct messages right now.'); expect(mockUserLoggerWarn).not.toHaveBeenCalled(); }); it('maintains behavior for active requests (ignores detail, no state change)', () => { controller.activeMessagesRequest = Symbol('active'); const detail = { context: { reason: 'no-decryptors' } }; controller.handleDirectMessagesError(detail); expect(controller.setMessagesLoadingState).not.toHaveBeenCalled(); expect(controller.setMessagesAnnouncement).not.toHaveBeenCalled(); expect(mockUserLoggerWarn).toHaveBeenCalled(); // Still logs for diagnostics }); }); // Adjust existing tests to cover "no-decryptors" in DM flows (e.g., error simulation in populateProfileMessages)