-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ilm navigation #81664
Fix ilm navigation #81664
Changes from 9 commits
85ae4c3
0577f4a
36349b9
5bd83e7
2d557aa
2798750
0e98681
f4015fc
9acc687
05459f2
c51af34
21338cf
0c16d97
0baccad
cc29641
42adcb2
5a735df
a0a4aaf
ab1c1d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { act } from 'react-dom/test-utils'; | ||
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../test_utils'; | ||
import { App } from '../../../public/application/app'; | ||
import { TestSubjects } from '../helpers'; | ||
|
||
const getTestBedConfig = (initialEntries: string[]): TestBedConfig => ({ | ||
memoryRouter: { | ||
initialEntries, | ||
}, | ||
defaultProps: { | ||
getUrlForApp: () => {}, | ||
navigateToApp: () => {}, | ||
}, | ||
}); | ||
|
||
const initTestBed = (initialEntries: string[]) => | ||
registerTestBed(App, getTestBedConfig(initialEntries))(); | ||
|
||
export interface AppTestBed extends TestBed<TestSubjects> { | ||
actions: { | ||
clickPolicyNameLink: () => void; | ||
clickCreatePolicyButton: () => void; | ||
}; | ||
} | ||
|
||
export const setup = async (initialEntries: string[]): Promise<AppTestBed> => { | ||
const testBed = await initTestBed(initialEntries); | ||
|
||
const clickPolicyNameLink = async () => { | ||
const { component, find } = testBed; | ||
await act(async () => { | ||
find('policyTablePolicyNameLink').simulate('click', { button: 0 }); | ||
}); | ||
component.update(); | ||
}; | ||
|
||
const clickCreatePolicyButton = async () => { | ||
const { component, find } = testBed; | ||
await act(async () => { | ||
find('createPolicyButton').simulate('click', { button: 0 }); | ||
}); | ||
component.update(); | ||
}; | ||
|
||
return { | ||
...testBed, | ||
actions: { clickPolicyNameLink, clickCreatePolicyButton }, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AppTestBed, setup } from './app.helpers'; | ||
import { setupEnvironment } from '../helpers/setup_environment'; | ||
import { getDefaultHotPhasePolicy, POLICY_NAME } from '../edit_policy/constants'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
const SPECIAL_CHARS_NAME = 'test?#$+=&@:'; | ||
const DOLLAR_SIGN_NAME = 'test%'; | ||
// navigation doesn't work for % with other special chars or sequence %25 | ||
// known issue https://github.com/elastic/kibana/issues/82440 | ||
const DOLLAR_SIGN_WITH_OTHER_CHARS_NAME = 'test%#'; | ||
const DOLLAR_SIGN_25_SEQUENCE = 'test%25'; | ||
|
||
window.scrollTo = jest.fn(); | ||
|
||
describe('<App />', () => { | ||
let testBed: AppTestBed; | ||
const { server, httpRequestsMockHelpers } = setupEnvironment(); | ||
afterAll(() => { | ||
server.restore(); | ||
}); | ||
|
||
describe('new policy creation', () => { | ||
test('when there are no policies', async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([]); | ||
await act(async () => { | ||
testBed = await setup(['/']); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
await actions.clickCreatePolicyButton(); | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe(`Create an index lifecycle policy`); | ||
expect(testBed.find('policyNameField').props().value).toBe(''); | ||
}); | ||
|
||
test('when there are policies', async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(POLICY_NAME)]); | ||
await act(async () => { | ||
testBed = await setup(['/']); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
await actions.clickCreatePolicyButton(); | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe(`Create an index lifecycle policy`); | ||
expect(testBed.find('policyNameField').props().value).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('navigation with special characters', () => { | ||
beforeAll(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(SPECIAL_CHARS_NAME)]); | ||
}); | ||
|
||
test('when clicked on policy name in table', async () => { | ||
await act(async () => { | ||
testBed = await setup(['/']); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
await actions.clickPolicyNameLink(); | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url', async () => { | ||
await act(async () => { | ||
testBed = await setup([`/policies/edit/${encodeURIComponent(SPECIAL_CHARS_NAME)}`]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url with double encoding', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
encodeURI(`/policies/edit/${encodeURIComponent(SPECIAL_CHARS_NAME)}`), | ||
]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${SPECIAL_CHARS_NAME}` | ||
); | ||
}); | ||
}); | ||
|
||
describe('navigation with dollar sign', () => { | ||
beforeAll(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(DOLLAR_SIGN_NAME)]); | ||
}); | ||
|
||
test('when loading edit policy page url', async () => { | ||
await act(async () => { | ||
testBed = await setup([`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_NAME)}`]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_NAME}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url with double encoding', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
encodeURI(`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_NAME)}`), | ||
]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_NAME}` | ||
); | ||
}); | ||
}); | ||
|
||
describe('navigation with dollar sign with other special characters', () => { | ||
beforeAll(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([ | ||
getDefaultHotPhasePolicy(DOLLAR_SIGN_WITH_OTHER_CHARS_NAME), | ||
]); | ||
}); | ||
|
||
test('when clicked on policy name in table', async () => { | ||
await act(async () => { | ||
testBed = await setup(['/']); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
await actions.clickPolicyNameLink(); | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_WITH_OTHER_CHARS_NAME}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_WITH_OTHER_CHARS_NAME)}`, | ||
]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
// known issue https://github.com/elastic/kibana/issues/82440 | ||
expect(testBed.find('policyTitle').text()).not.toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_WITH_OTHER_CHARS_NAME}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url with double encoding', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
encodeURI(`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_WITH_OTHER_CHARS_NAME)}`), | ||
]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_WITH_OTHER_CHARS_NAME}` | ||
); | ||
}); | ||
}); | ||
|
||
describe('navigation with %25 sequence', () => { | ||
beforeAll(async () => { | ||
httpRequestsMockHelpers.setLoadPolicies([getDefaultHotPhasePolicy(DOLLAR_SIGN_25_SEQUENCE)]); | ||
}); | ||
|
||
test('when clicked on policy name in table', async () => { | ||
await act(async () => { | ||
testBed = await setup(['/']); | ||
}); | ||
|
||
const { component, actions } = testBed; | ||
component.update(); | ||
|
||
await actions.clickPolicyNameLink(); | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_25_SEQUENCE}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we describe the assertion we're making, too? This will help me scan the tests and identify which ones verify things work and which ones verify things don't work. For example, if the prior test description was this: test('when clicked on policy name in table decodes correctly', async () => { I'd expect this one to be: test('when loading edit policy page url decodes incorrectly', async () => { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, it was not very clear which tests were confirming the navigation bug, so I changed the test titles similar to what you suggested. |
||
await act(async () => { | ||
testBed = await setup([`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_25_SEQUENCE)}`]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
// known issue https://github.com/elastic/kibana/issues/82440 | ||
expect(testBed.find('policyTitle').text()).not.toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_25_SEQUENCE}` | ||
); | ||
}); | ||
|
||
test('when loading edit policy page url with double encoding', async () => { | ||
await act(async () => { | ||
testBed = await setup([ | ||
encodeURI(`/policies/edit/${encodeURIComponent(DOLLAR_SIGN_25_SEQUENCE)}`), | ||
]); | ||
}); | ||
|
||
const { component } = testBed; | ||
component.update(); | ||
|
||
expect(testBed.find('policyTitle').text()).toBe( | ||
`Edit index lifecycle policy ${DOLLAR_SIGN_25_SEQUENCE}` | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a reader of this file, I'd benefit from some explanation about why we test double-encoding. I also noticed that we have three tests for double-encoding. I think we can simplify the code and help the reader understand why we're testing double-encoding by creating a helper function at the top of this file or inside of the helpers file, consuming it everywhere we test double-encoding, and adding a comment inside it. For example:
WDYT?