Commit c7ef15d4 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch 'djadmin-syntax-highlight-yaml' into 'master'

Add syntax highlighting to Security Configuration code snippets

See merge request gitlab-org/gitlab!63752
parents fc39029d f1a7089d
...@@ -4,6 +4,7 @@ import Clipboard from 'clipboard'; ...@@ -4,6 +4,7 @@ import Clipboard from 'clipboard';
import { getBaseURL, setUrlParams, redirectTo } from '~/lib/utils/url_utility'; import { getBaseURL, setUrlParams, redirectTo } from '~/lib/utils/url_utility';
import { sprintf, s__, __ } from '~/locale'; import { sprintf, s__, __ } from '~/locale';
import { CODE_SNIPPET_SOURCE_URL_PARAM } from '~/pipeline_editor/components/code_snippet_alert/constants'; import { CODE_SNIPPET_SOURCE_URL_PARAM } from '~/pipeline_editor/components/code_snippet_alert/constants';
import SourceEditor from '~/vue_shared/components/source_editor.vue';
import { CONFIGURATION_SNIPPET_MODAL_ID } from './constants'; import { CONFIGURATION_SNIPPET_MODAL_ID } from './constants';
export default { export default {
...@@ -12,6 +13,7 @@ export default { ...@@ -12,6 +13,7 @@ export default {
GlModal, GlModal,
GlSprintf, GlSprintf,
GlLink, GlLink,
SourceEditor,
}, },
i18n: { i18n: {
helpText: s__( helpText: s__(
...@@ -46,11 +48,27 @@ export default { ...@@ -46,11 +48,27 @@ export default {
scanType: this.scanType, scanType: this.scanType,
}); });
}, },
editorOptions() {
return {
readOnly: true,
lineNumbers: 'off',
folding: false,
renderIndentGuides: false,
renderLineHighlight: 'none',
lineDecorationsWidth: 0,
occurrencesHighlight: false,
hideCursorInOverviewRuler: true,
overviewRulerBorder: false,
};
},
}, },
methods: { methods: {
show() { show() {
this.$refs.modal.show(); this.$refs.modal.show();
}, },
resetEditor() {
this.$refs.editor.getEditor().layout();
},
onHide() { onHide() {
this.clipboard?.destroy(); this.clipboard?.destroy();
}, },
...@@ -94,6 +112,7 @@ export default { ...@@ -94,6 +112,7 @@ export default {
:modal-id="$options.CONFIGURATION_SNIPPET_MODAL_ID" :modal-id="$options.CONFIGURATION_SNIPPET_MODAL_ID"
:title="modalTitle" :title="modalTitle"
@hide="onHide" @hide="onHide"
@shown="resetEditor"
@primary="copySnippet" @primary="copySnippet"
@secondary="copySnippet(false)" @secondary="copySnippet(false)"
> >
...@@ -110,6 +129,11 @@ export default { ...@@ -110,6 +129,11 @@ export default {
</gl-sprintf> </gl-sprintf>
</p> </p>
<pre><code data-testid="configuration-modal-yaml-snippet" v-text="yaml"></code></pre> <div
class="gl-w-full gl-h-full gl-border-1 gl-border-solid gl-border-gray-100"
data-testid="configuration-modal-yaml-snippet"
>
<source-editor ref="editor" :value="yaml" file-name="*.yml" :editor-options="editorOptions" />
</div>
</gl-modal> </gl-modal>
</template> </template>
...@@ -2,4 +2,7 @@ ...@@ -2,4 +2,7 @@
- breadcrumb_title _("API Fuzzing Configuration") - breadcrumb_title _("API Fuzzing Configuration")
- page_title _("API Fuzzing Configuration") - page_title _("API Fuzzing Configuration")
- content_for :prefetch_asset_tags do
- webpack_preload_asset_tag('monaco')
.js-api-fuzzing-configuration{ data: api_fuzzing_configuration_data(@project) } .js-api-fuzzing-configuration{ data: api_fuzzing_configuration_data(@project) }
...@@ -2,4 +2,7 @@ ...@@ -2,4 +2,7 @@
- breadcrumb_title _("DAST Configuration") - breadcrumb_title _("DAST Configuration")
- page_title _("DAST Configuration") - page_title _("DAST Configuration")
- content_for :prefetch_asset_tags do
- webpack_preload_asset_tag('monaco')
.js-dast-configuration{ data: dast_configuration_data(@project) } .js-dast-configuration{ data: dast_configuration_data(@project) }
...@@ -5,6 +5,7 @@ import { merge } from 'lodash'; ...@@ -5,6 +5,7 @@ import { merge } from 'lodash';
import ConfigurationSnippetModal from 'ee/security_configuration/components/configuration_snippet_modal.vue'; import ConfigurationSnippetModal from 'ee/security_configuration/components/configuration_snippet_modal.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import SourceEditor from '~/vue_shared/components/source_editor.vue';
import { createApiFuzzingConfigurationMutationResponse } from '../api_fuzzing/mock_data'; import { createApiFuzzingConfigurationMutationResponse } from '../api_fuzzing/mock_data';
jest.mock('clipboard', () => jest.mock('clipboard', () =>
...@@ -12,13 +13,16 @@ jest.mock('clipboard', () => ...@@ -12,13 +13,16 @@ jest.mock('clipboard', () =>
on: jest.fn().mockImplementation((_event, cb) => cb()), on: jest.fn().mockImplementation((_event, cb) => cb()),
})), })),
); );
jest.mock('~/lib/utils/url_utility', () => ({
redirectTo: jest.fn(), jest.mock('~/lib/utils/url_utility', () => {
joinPaths: jest.fn(), const urlUtility = jest.requireActual('~/lib/utils/url_utility');
setUrlFragment: jest.fn(),
getBaseURL: jest.fn().mockReturnValue('http://gitlab.local/'), return {
setUrlParams: jest.requireActual('~/lib/utils/url_utility').setUrlParams, ...urlUtility,
})); getBaseURL: jest.fn().mockReturnValue('http://gitlab.local/'),
redirectTo: jest.fn(),
};
});
const { const {
gitlabCiYamlEditPath, gitlabCiYamlEditPath,
...@@ -30,8 +34,8 @@ describe('EE - SecurityConfigurationSnippetModal', () => { ...@@ -30,8 +34,8 @@ describe('EE - SecurityConfigurationSnippetModal', () => {
let wrapper; let wrapper;
const findModal = () => wrapper.find(GlModal); const findModal = () => wrapper.find(GlModal);
const findYamlSnippet = () => wrapper.findByTestId('configuration-modal-yaml-snippet');
const helpText = () => wrapper.findByTestId('configuration-modal-help-text'); const helpText = () => wrapper.findByTestId('configuration-modal-help-text');
const findEditor = () => wrapper.findComponent(SourceEditor);
const createWrapper = (options) => { const createWrapper = (options) => {
wrapper = extendedWrapper( wrapper = extendedWrapper(
...@@ -51,6 +55,7 @@ describe('EE - SecurityConfigurationSnippetModal', () => { ...@@ -51,6 +55,7 @@ describe('EE - SecurityConfigurationSnippetModal', () => {
}, },
stubs: { stubs: {
GlSprintf, GlSprintf,
SourceEditor,
}, },
}, },
options, options,
...@@ -68,7 +73,12 @@ describe('EE - SecurityConfigurationSnippetModal', () => { ...@@ -68,7 +73,12 @@ describe('EE - SecurityConfigurationSnippetModal', () => {
}); });
it('renders the YAML snippet', () => { it('renders the YAML snippet', () => {
expect(findYamlSnippet().text()).toBe(configurationYaml); expect(findEditor().exists()).toBe(true);
});
it('initializes editor with the provided configuration', () => {
const editorComponent = findEditor();
expect(editorComponent.vm.getEditor().getValue()).toBe(configurationYaml);
}); });
it('renders help text correctly', () => { it('renders help text correctly', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment