Skip to content

Commit

Permalink
update functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Aug 16, 2021
1 parent a30a25b commit 5bb656e
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,50 @@ export const AdvancedRuntimeMappingsEditor: FC<StepDefineFormHook['runtimeMappin
state: { advancedEditorRuntimeMappingsLastApplied, advancedRuntimeMappingsConfig, xJsonMode },
}) => {
return (
<CodeEditor
data-test-subj="transformAdvancedRuntimeMappingsEditor"
height={250}
languageId={'json'}
onChange={(d: string) => {
setAdvancedRuntimeMappingsConfig(d);
<div data-test-subj="transformAdvancedRuntimeMappingsEditor">
<CodeEditor
height={250}
languageId={'json'}
onChange={(d: string) => {
setAdvancedRuntimeMappingsConfig(d);

// Disable the "Apply"-Button if the config hasn't changed.
if (advancedEditorRuntimeMappingsLastApplied === d) {
setRuntimeMappingsEditorApplyButtonEnabled(false);
return;
}
// Disable the "Apply"-Button if the config hasn't changed.
if (advancedEditorRuntimeMappingsLastApplied === d) {
setRuntimeMappingsEditorApplyButtonEnabled(false);
return;
}

// Try to parse the string passed on from the editor.
// If parsing fails, the "Apply"-Button will be disabled
try {
// if the user deletes the json in the editor
// they should still be able to apply changes
const isEmptyStr = d === '';
const parsedJson = isEmptyStr ? {} : JSON.parse(convertToJson(d));
setRuntimeMappingsEditorApplyButtonEnabled(isEmptyStr || isRuntimeMappings(parsedJson));
} catch (e) {
setRuntimeMappingsEditorApplyButtonEnabled(false);
}
}}
options={{
ariaLabel: i18n.translate('xpack.transform.stepDefineForm.advancedEditorAriaLabel', {
defaultMessage: 'Advanced pivot editor',
}),
automaticLayout: true,
fontSize: 12,
scrollBeyondLastLine: false,
quickSuggestions: true,
minimap: {
enabled: false,
},
wordWrap: 'on',
wrappingIndent: 'indent',
}}
value={advancedRuntimeMappingsConfig}
/>
// Try to parse the string passed on from the editor.
// If parsing fails, the "Apply"-Button will be disabled
try {
// if the user deletes the json in the editor
// they should still be able to apply changes
const isEmptyStr = d === '';
const parsedJson = isEmptyStr ? {} : JSON.parse(convertToJson(d));
setRuntimeMappingsEditorApplyButtonEnabled(
isEmptyStr || isRuntimeMappings(parsedJson)
);
} catch (e) {
setRuntimeMappingsEditorApplyButtonEnabled(false);
}
}}
options={{
ariaLabel: i18n.translate('xpack.transform.stepDefineForm.advancedEditorAriaLabel', {
defaultMessage: 'Advanced pivot editor',
}),
automaticLayout: true,
fontSize: 12,
scrollBeyondLastLine: false,
quickSuggestions: true,
minimap: {
enabled: false,
},
wordWrap: 'on',
wrappingIndent: 'indent',
}}
value={advancedRuntimeMappingsConfig}
/>
</div>
);
},
(prevProps, nextProps) => isEqual(pickProps(prevProps), pickProps(nextProps))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,48 @@ export const AdvancedSourceEditor: FC<StepDefineFormHook> = ({
},
}) => {
return (
<CodeEditor
data-test-subj="transformAdvancedRuntimeMappingsEditor"
height={250}
languageId={'json'}
onChange={(d: string) => {
setSearchString(undefined);
setAdvancedEditorSourceConfig(d);
<div data-test-subj="transformAdvancedRuntimeMappingsEditor">
<CodeEditor
height={250}
languageId={'json'}
onChange={(d: string) => {
setSearchString(undefined);
setAdvancedEditorSourceConfig(d);

// Disable the "Apply"-Button if the config hasn't changed.
if (advancedEditorSourceConfigLastApplied === d) {
setAdvancedSourceEditorApplyButtonEnabled(false);
return;
}
// Disable the "Apply"-Button if the config hasn't changed.
if (advancedEditorSourceConfigLastApplied === d) {
setAdvancedSourceEditorApplyButtonEnabled(false);
return;
}

// Try to parse the string passed on from the editor.
// If parsing fails, the "Apply"-Button will be disabled
try {
JSON.parse(d);
setAdvancedSourceEditorApplyButtonEnabled(true);
} catch (e) {
setAdvancedSourceEditorApplyButtonEnabled(false);
}
}}
options={{
ariaLabel: i18n.translate('xpack.transform.stepDefineForm.advancedSourceEditorAriaLabel', {
defaultMessage: 'Advanced query editor',
}),
automaticLayout: true,
fontSize: 12,
scrollBeyondLastLine: false,
quickSuggestions: true,
minimap: {
enabled: false,
},
wordWrap: 'on',
wrappingIndent: 'indent',
}}
value={advancedEditorSourceConfig}
/>
// Try to parse the string passed on from the editor.
// If parsing fails, the "Apply"-Button will be disabled
try {
JSON.parse(d);
setAdvancedSourceEditorApplyButtonEnabled(true);
} catch (e) {
setAdvancedSourceEditorApplyButtonEnabled(false);
}
}}
options={{
ariaLabel: i18n.translate(
'xpack.transform.stepDefineForm.advancedSourceEditorAriaLabel',
{
defaultMessage: 'Advanced query editor',
}
),
automaticLayout: true,
fontSize: 12,
scrollBeyondLastLine: false,
quickSuggestions: true,
minimap: {
enabled: false,
},
wordWrap: 'on',
wrappingIndent: 'indent',
}}
value={advancedEditorSourceConfig}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha
{isUnsupportedAgg && (
<EuiCodeBlock
aria-label={i18n.translate('xpack.transform.agg.popoverForm.codeBlock', {
defaultMessage: 'Read only code editor',
defaultMessage: 'JSON of transform aggregation',
})}
fontSize="s"
language="json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export const PopoverForm: React.FC<Props> = ({ defaultData, otherAggNames, onCha
<EuiSpacer size="m" />
<EuiCodeBlock
aria-label={i18n.translate('xpack.transform.agg.popoverForm.codeBlock', {
defaultMessage: 'Read only code editor',
defaultMessage: 'JSON of transform aggregation',
})}
fontSize="s"
language="json"
Expand Down
10 changes: 6 additions & 4 deletions x-pack/test/functional/services/transform/wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
async assertRuntimeMappingsEditorContent(expectedContent: string[]) {
await this.assertRuntimeMappingsEditorExists();

const runtimeMappingsEditorString = await aceEditor.getValue(
'transformAdvancedRuntimeMappingsEditor'
);
const wrapper = await testSubjects.find('transformAdvancedRuntimeMappingsEditor');
const editor = await wrapper.findByCssSelector('.monaco-editor .view-lines');
const runtimeMappingsEditorString = await editor.getVisibleText();
// Not all lines may be visible in the editor and thus aceEditor may not return all lines.
// This means we might not get back valid JSON so we only test against the first few lines
// and see if the string matches.
Expand Down Expand Up @@ -624,7 +624,9 @@ export function TransformWizardProvider({ getService, getPageObjects }: FtrProvi
},

async assertAdvancedPivotEditorContent(expectedValue: string[]) {
const advancedEditorString = await aceEditor.getValue('transformAdvancedPivotEditor');
const wrapper = await testSubjects.find('transformAdvancedPivotEditor');
const editor = await wrapper.findByCssSelector('.monaco-editor .view-lines');
const advancedEditorString = await editor.getVisibleText();
// Not all lines may be visible in the editor and thus aceEditor may not return all lines.
// This means we might not get back valid JSON so we only test against the first few lines
// and see if the string matches.
Expand Down

0 comments on commit 5bb656e

Please sign in to comment.