@nestjsvn/swagger-sse
Version:
OpenAPI documentation and interactive Swagger UI for NestJS Server-Sent Events endpoints
62 lines (61 loc) • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const setup_1 = require("./setup");
const test_controllers_1 = require("./test-controllers");
describe('SSE Plugin Diagnostic Tests', () => {
let context;
beforeAll(async () => {
context = await setup_1.E2ETestSetup.createContext('sse-plugin-diagnostic', {
controllers: [test_controllers_1.TestEventsController],
});
});
afterAll(async () => {
await setup_1.E2ETestSetup.cleanup('sse-plugin-diagnostic');
});
it('should show SSE UI elements after clicking Execute', async () => {
await context.page.goto(`${context.baseUrl}/api-docs`);
// Wait for Swagger UI to load
await context.page.waitForSelector('.swagger-ui', { timeout: 10000 });
// Find and expand the basic SSE endpoint
const basicEndpoint = await context.page.$('[data-path="/test-events/basic"]');
expect(basicEndpoint).toBeTruthy();
// Click to expand the endpoint - click on the opblock summary that contains this path
await context.page.evaluate(() => {
const pathElement = document.querySelector('[data-path="/test-events/basic"]');
const opblockSummary = pathElement?.closest('.opblock-summary');
if (opblockSummary) {
opblockSummary.click();
}
});
// Wait for the endpoint to expand
await context.page.waitForSelector('.execute-wrapper', { timeout: 5000 });
// Check that SSE UI elements are NOT present before clicking Execute
const sseElementsBeforeExecute = await context.page.evaluate(() => {
return {
connectBtn: !!document.querySelector('[data-testid="sse-connect-btn"]'),
status: !!document.querySelector('[data-testid="sse-status"]'),
eventLog: !!document.querySelector('[data-testid="sse-event-log"]'),
};
});
console.log('SSE elements before Execute:', sseElementsBeforeExecute);
expect(sseElementsBeforeExecute.connectBtn).toBe(false);
expect(sseElementsBeforeExecute.status).toBe(false);
expect(sseElementsBeforeExecute.eventLog).toBe(false);
// Now click the Execute button
await context.page.click('.execute-wrapper .btn.execute');
// Wait a moment for the SSE plugin to process the click
await context.page.waitForTimeout(1000);
// Check that SSE UI elements are NOW present after clicking Execute
const sseElementsAfterExecute = await context.page.evaluate(() => {
return {
connectBtn: !!document.querySelector('[data-testid="sse-connect-btn"]'),
status: !!document.querySelector('[data-testid="sse-status"]'),
eventLog: !!document.querySelector('[data-testid="sse-event-log"]'),
};
});
console.log('SSE elements after Execute:', sseElementsAfterExecute);
expect(sseElementsAfterExecute.connectBtn).toBe(true);
expect(sseElementsAfterExecute.status).toBe(true);
expect(sseElementsAfterExecute.eventLog).toBe(true);
});
});