-
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
[SOM] Preserve saved object references when saving the object #66584
Changes from all commits
dab3b5c
bc85d91
8fa82c0
f109ec8
c2f2730
c7f6304
d453272
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 |
---|---|---|
|
@@ -26,6 +26,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { | |
const esArchiver = getService('esArchiver'); | ||
const testSubjects = getService('testSubjects'); | ||
const PageObjects = getPageObjects(['common', 'settings']); | ||
const browser = getService('browser'); | ||
const find = getService('find'); | ||
|
||
const setFieldValue = async (fieldName: string, value: string) => { | ||
return testSubjects.setValue(`savedObjects-editField-${fieldName}`, value); | ||
|
@@ -35,6 +37,26 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { | |
return testSubjects.getAttribute(`savedObjects-editField-${fieldName}`, 'value'); | ||
}; | ||
|
||
const setAceEditorFieldValue = async (fieldName: string, fieldValue: string) => { | ||
const editorId = `savedObjects-editField-${fieldName}-aceEditor`; | ||
await find.clickByCssSelector(`#${editorId}`); | ||
return browser.execute( | ||
(editor: string, value: string) => { | ||
return (window as any).ace.edit(editor).setValue(value); | ||
}, | ||
editorId, | ||
Comment on lines
+43
to
+47
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. Using the Same things with |
||
fieldValue | ||
); | ||
}; | ||
|
||
const getAceEditorFieldValue = async (fieldName: string) => { | ||
const editorId = `savedObjects-editField-${fieldName}-aceEditor`; | ||
await find.clickByCssSelector(`#${editorId}`); | ||
return browser.execute((editor: string) => { | ||
return (window as any).ace.edit(editor).getValue() as string; | ||
}, editorId); | ||
}; | ||
|
||
const focusAndClickButton = async (buttonSubject: string) => { | ||
const button = await testSubjects.find(buttonSubject); | ||
await button.scrollIntoViewIfNecessary(); | ||
|
@@ -99,5 +121,52 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { | |
const objects = await PageObjects.settings.getSavedObjectsInTable(); | ||
expect(objects.includes('A Dashboard')).to.be(false); | ||
}); | ||
|
||
it('preserves the object references when saving', 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. testing that references are properly displayed and preserved during |
||
const testVisualizationUrl = | ||
'/management/kibana/objects/savedVisualizations/75c3e060-1e7c-11e9-8488-65449e65d0ed'; | ||
const visualizationRefs = [ | ||
{ | ||
name: 'kibanaSavedObjectMeta.searchSourceJSON.index', | ||
type: 'index-pattern', | ||
id: 'logstash-*', | ||
}, | ||
]; | ||
|
||
await PageObjects.settings.navigateTo(); | ||
await PageObjects.settings.clickKibanaSavedObjects(); | ||
|
||
const objects = await PageObjects.settings.getSavedObjectsInTable(); | ||
expect(objects.includes('A Pie')).to.be(true); | ||
|
||
await PageObjects.common.navigateToActualUrl('kibana', testVisualizationUrl); | ||
|
||
await testSubjects.existOrFail('savedObjectEditSave'); | ||
|
||
let displayedReferencesValue = await getAceEditorFieldValue('references'); | ||
|
||
expect(JSON.parse(displayedReferencesValue)).to.eql(visualizationRefs); | ||
|
||
await focusAndClickButton('savedObjectEditSave'); | ||
|
||
await PageObjects.settings.getSavedObjectsInTable(); | ||
|
||
await PageObjects.common.navigateToActualUrl('kibana', testVisualizationUrl); | ||
|
||
// Parsing to avoid random keys ordering issues in raw string comparison | ||
expect(JSON.parse(await getAceEditorFieldValue('references'))).to.eql(visualizationRefs); | ||
|
||
await setAceEditorFieldValue('references', JSON.stringify([], undefined, 2)); | ||
|
||
await focusAndClickButton('savedObjectEditSave'); | ||
|
||
await PageObjects.settings.getSavedObjectsInTable(); | ||
|
||
await PageObjects.common.navigateToActualUrl('kibana', testVisualizationUrl); | ||
|
||
displayedReferencesValue = await getAceEditorFieldValue('references'); | ||
|
||
expect(JSON.parse(displayedReferencesValue)).to.eql([]); | ||
}); | ||
}); | ||
} |
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.
This was missed when migrating from legacy.
Ideally, we would create fields with full path instead of assuming all fields are in
attributes
to avoid that kind of hack (that would break for example if a given editable SO type had areferences
attributes), but this is outside of the scope of this mere fix.