-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
x-pack/plugins/upgrade_assistant/__jest__/client_integration/app/app.helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest'; | ||
|
||
import { AppWithRouter } from '../../../public/application/app'; | ||
import { WithAppDependencies } from '../helpers'; | ||
|
||
const testBedConfig: TestBedConfig = { | ||
memoryRouter: { | ||
initialEntries: [`/overview`], | ||
componentRoutePath: '/overview', | ||
}, | ||
doMountAsync: true, | ||
}; | ||
|
||
export type AppTestBed = TestBed & { | ||
actions: ReturnType<typeof createActions>; | ||
}; | ||
|
||
const createActions = (testBed: TestBed) => { | ||
const clickDeprecationToggle = async () => { | ||
const { find, component } = testBed; | ||
|
||
await act(async () => { | ||
find('deprecationLoggingToggle').simulate('click'); | ||
}); | ||
|
||
component.update(); | ||
}; | ||
|
||
return { | ||
clickDeprecationToggle, | ||
}; | ||
}; | ||
|
||
export const setupAppPage = async (overrides?: Record<string, unknown>): Promise<AppTestBed> => { | ||
const initTestBed = registerTestBed(WithAppDependencies(AppWithRouter, overrides), testBedConfig); | ||
const testBed = await initTestBed(); | ||
|
||
return { | ||
...testBed, | ||
actions: createActions(testBed), | ||
}; | ||
}; |
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/upgrade_assistant/__jest__/client_integration/app/cluster_upgrade.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { setupEnvironment } from '../helpers'; | ||
import { AppTestBed, setupAppPage } from './app.helpers'; | ||
|
||
describe('Cluster upgrade', () => { | ||
let testBed: AppTestBed; | ||
let server: ReturnType<typeof setupEnvironment>['server']; | ||
let httpRequestsMockHelpers: ReturnType<typeof setupEnvironment>['httpRequestsMockHelpers']; | ||
|
||
beforeEach(() => { | ||
({ server, httpRequestsMockHelpers } = setupEnvironment()); | ||
}); | ||
|
||
afterEach(() => { | ||
server.restore(); | ||
}); | ||
|
||
describe('when user is still preparing for upgrade', () => { | ||
beforeEach(async () => { | ||
testBed = await setupAppPage(); | ||
}); | ||
|
||
test('renders overview', () => { | ||
const { exists, find } = testBed; | ||
expect(exists('overview')).toBe(true); | ||
expect(exists('isUpgradingMessage')).toBe(false); | ||
expect(exists('isUpgradeCompleteMessage')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('when cluster is in the process of a rolling upgrade', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(null, { | ||
statusCode: 426, | ||
attributes: { | ||
allNodesUpgraded: false, | ||
}, | ||
}); | ||
|
||
await act(async () => { | ||
testBed = await setupAppPage(); | ||
}); | ||
}); | ||
|
||
test('renders rolling upgrade message', async () => { | ||
const { component, exists } = testBed; | ||
component.update(); | ||
expect(exists('overview')).toBe(false); | ||
expect(exists('isUpgradingMessage')).toBe(true); | ||
expect(exists('isUpgradeCompleteMessage')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('when cluster has been upgraded', () => { | ||
beforeEach(async () => { | ||
httpRequestsMockHelpers.setLoadDeprecationLoggingResponse(null, { | ||
statusCode: 426, | ||
attributes: { | ||
allNodesUpgraded: true, | ||
}, | ||
}); | ||
|
||
await act(async () => { | ||
testBed = await setupAppPage(); | ||
}); | ||
}); | ||
|
||
test('renders upgrade complete message', () => { | ||
const { component, exists } = testBed; | ||
component.update(); | ||
expect(exists('overview')).toBe(false); | ||
expect(exists('isUpgradingMessage')).toBe(false); | ||
expect(exists('isUpgradeCompleteMessage')).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters