From 54c295d76e06077ac68eb0b92e043224e47bbc09 Mon Sep 17 00:00:00 2001 From: Ignacio Rivas Date: Thu, 9 Sep 2021 16:36:41 +0200 Subject: [PATCH] [Upgrade Assistant] Tests for updating step state accordingly if API poll receives count followed by error (#111701) * Add test for logs count polling * Test when count api fails --- .../fix_logs_step/fix_logs_step.test.tsx | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx index e19ea5b1dfd99..b9a46ce62e20d 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx @@ -23,8 +23,9 @@ jest.mock('../../../../public/application/lib/logs_checkpoint', () => { import { DeprecationLoggingStatus } from '../../../../common/types'; import { DEPRECATION_LOGS_SOURCE_ID } from '../../../../common/constants'; -import { setupEnvironment } from '../../helpers'; import { OverviewTestBed, setupOverviewPage } from '../overview.helpers'; +import { setupEnvironment, advanceTime } from '../../helpers'; +import { DEPRECATION_LOGS_COUNT_POLL_INTERVAL_MS } from '../../../../common/constants'; const getLoggingResponse = (toggle: boolean): DeprecationLoggingStatus => ({ isDeprecationLogIndexingEnabled: toggle, @@ -308,5 +309,42 @@ describe('Overview - Fix deprecation logs step', () => { expect(exists('noWarningsCallout')).toBe(true); }); + + describe('Poll for logs count', () => { + beforeEach(async () => { + jest.useFakeTimers(); + + // First request should make the step be complete + httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse({ + count: 0, + }); + + testBed = await setupOverviewPage(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + test('renders step as incomplete when a success state is followed by an error state', async () => { + const { exists } = testBed; + + expect(exists('fixLogsStep-complete')).toBe(true); + + // second request will error + const error = { + statusCode: 500, + error: 'Internal server error', + message: 'Internal server error', + }; + httpRequestsMockHelpers.setLoadDeprecationLogsCountResponse(undefined, error); + + // Resolve the polling timeout. + await advanceTime(DEPRECATION_LOGS_COUNT_POLL_INTERVAL_MS); + testBed.component.update(); + + expect(exists('fixLogsStep-incomplete')).toBe(true); + }); + }); }); });