|
| 1 | +///////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// pgAdmin 4 - PostgreSQL Tools |
| 4 | +// |
| 5 | +// Copyright (C) 2013 - 2026, The pgAdmin Development Team |
| 6 | +// This software is released under the PostgreSQL Licence |
| 7 | +// |
| 8 | +////////////////////////////////////////////////////////////// |
| 9 | + |
| 10 | +import { render, act } from '@testing-library/react'; |
| 11 | + |
| 12 | +import EventBus from '../../../pgadmin/static/js/helpers/EventBus'; |
| 13 | +import { DebuggerEventsContext } from '../../../pgadmin/tools/debugger/static/js/components/DebuggerComponent'; |
| 14 | +import DebuggerMessages from '../../../pgadmin/tools/debugger/static/js/components/DebuggerMessages'; |
| 15 | +import { DEBUGGER_EVENTS } from '../../../pgadmin/tools/debugger/static/js/DebuggerConstants'; |
| 16 | + |
| 17 | + |
| 18 | +describe('Debugger Messages', () => { |
| 19 | + let eventBus; |
| 20 | + |
| 21 | + const renderMessages = () => { |
| 22 | + eventBus = new EventBus(); |
| 23 | + const ctrl = render( |
| 24 | + <DebuggerEventsContext.Provider value={eventBus}> |
| 25 | + <DebuggerMessages /> |
| 26 | + </DebuggerEventsContext.Provider> |
| 27 | + ); |
| 28 | + return ctrl.container.querySelector('#debugger-msg'); |
| 29 | + }; |
| 30 | + |
| 31 | + it('puts each appended batch of messages on a new line', async () => { |
| 32 | + const msgDiv = renderMessages(); |
| 33 | + await act(async () => { |
| 34 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: first', true); |
| 35 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: second', true); |
| 36 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: third\n', true); |
| 37 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: fourth', true); |
| 38 | + }); |
| 39 | + expect(msgDiv.textContent).toBe( |
| 40 | + 'NOTICE: first\nNOTICE: second\nNOTICE: third\nNOTICE: fourth' |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | + it('replaces the messages when not appending', async () => { |
| 45 | + const msgDiv = renderMessages(); |
| 46 | + await act(async () => { |
| 47 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: old', true); |
| 48 | + eventBus.fireEvent(DEBUGGER_EVENTS.SET_MESSAGES, 'NOTICE: new'); |
| 49 | + }); |
| 50 | + expect(msgDiv.textContent).toBe('NOTICE: new'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments