Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-11-21 00:14:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-11-21 00:14:21 +0300
commit235f755398a6a199b22e4924e7a81670b0dfdaef (patch)
tree84a23b2343ef5a4c0bd03d5ab03ba5370f2b5503 /spec/frontend/vue_shared/components
parente12ad88e786d7a91d94d92b26bce9e984d9692f5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/vue_shared/components')
-rw-r--r--spec/frontend/vue_shared/components/source_viewer/highlight_util_spec.js35
-rw-r--r--spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js30
2 files changed, 57 insertions, 8 deletions
diff --git a/spec/frontend/vue_shared/components/source_viewer/highlight_util_spec.js b/spec/frontend/vue_shared/components/source_viewer/highlight_util_spec.js
index 49e3083f8ed..c84a39274f8 100644
--- a/spec/frontend/vue_shared/components/source_viewer/highlight_util_spec.js
+++ b/spec/frontend/vue_shared/components/source_viewer/highlight_util_spec.js
@@ -6,6 +6,7 @@ import { LINES_PER_CHUNK, NEWLINE } from '~/vue_shared/components/source_viewer/
jest.mock('highlight.js/lib/core', () => ({
highlight: jest.fn().mockReturnValue({ value: 'highlighted content' }),
registerLanguage: jest.fn(),
+ getLanguage: jest.fn(),
}));
jest.mock('~/vue_shared/components/source_viewer/plugins/index', () => ({
@@ -28,11 +29,37 @@ describe('Highlight utility', () => {
expect(registerPlugins).toHaveBeenCalled();
});
+ describe('sub-languages', () => {
+ const languageDefinition = {
+ subLanguage: 'xml',
+ contains: [{ subLanguage: 'javascript' }, { subLanguage: 'typescript' }],
+ };
+
+ beforeEach(async () => {
+ jest.spyOn(hljs, 'getLanguage').mockReturnValue(languageDefinition);
+ await highlight(fileType, rawContent, language);
+ });
+
+ it('registers the primary sub-language', () => {
+ expect(hljs.registerLanguage).toHaveBeenCalledWith(
+ languageDefinition.subLanguage,
+ expect.any(Function),
+ );
+ });
+
+ it.each(languageDefinition.contains)(
+ 'registers the rest of the sub-languages',
+ ({ subLanguage }) => {
+ expect(hljs.registerLanguage).toHaveBeenCalledWith(subLanguage, expect.any(Function));
+ },
+ );
+ });
+
it('highlights the content', () => {
expect(hljs.highlight).toHaveBeenCalledWith(rawContent, { language });
});
- it('splits the content into chunks', () => {
+ it('splits the content into chunks', async () => {
const contentArray = Array.from({ length: 140 }, () => 'newline'); // simulate 140 lines of code
const chunks = [
@@ -52,7 +79,7 @@ describe('Highlight utility', () => {
},
];
- expect(highlight(fileType, contentArray.join(NEWLINE), language)).toEqual(
+ expect(await highlight(fileType, contentArray.join(NEWLINE), language)).toEqual(
expect.arrayContaining(chunks),
);
});
@@ -71,7 +98,7 @@ describe('unsupported languages', () => {
expect(hljs.highlight).not.toHaveBeenCalled();
});
- it('does not return a result', () => {
- expect(highlight(fileType, rawContent, unsupportedLanguage)).toBe(undefined);
+ it('does not return a result', async () => {
+ expect(await highlight(fileType, rawContent, unsupportedLanguage)).toBe(undefined);
});
});
diff --git a/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js b/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
index ee7164515f6..58d5a1a63ba 100644
--- a/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
+++ b/spec/frontend/vue_shared/components/source_viewer/source_viewer_new_spec.js
@@ -1,11 +1,15 @@
-import Vue from 'vue';
+import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { setHTMLFixture } from 'helpers/fixtures';
import SourceViewer from '~/vue_shared/components/source_viewer/source_viewer_new.vue';
import Chunk from '~/vue_shared/components/source_viewer/components/chunk_new.vue';
-import { EVENT_ACTION, EVENT_LABEL_VIEWER } from '~/vue_shared/components/source_viewer/constants';
+import {
+ EVENT_ACTION,
+ EVENT_LABEL_VIEWER,
+ CODEOWNERS_FILE_NAME,
+} from '~/vue_shared/components/source_viewer/constants';
import Tracking from '~/tracking';
import LineHighlighter from '~/blob/line_highlighter';
import addBlobLinksTracking from '~/blob/blob_links_tracking';
@@ -13,6 +17,7 @@ import waitForPromises from 'helpers/wait_for_promises';
import blameDataQuery from '~/vue_shared/components/source_viewer/queries/blame_data.query.graphql';
import Blame from '~/vue_shared/components/source_viewer/components/blame_info.vue';
import * as utils from '~/vue_shared/components/source_viewer/utils';
+import CodeownersValidation from 'ee_component/blob/components/codeowners_validation.vue';
import {
BLOB_DATA_MOCK,
@@ -43,16 +48,17 @@ describe('Source Viewer component', () => {
const blameInfo =
BLAME_DATA_QUERY_RESPONSE_MOCK.data.project.repository.blobs.nodes[0].blame.groups;
- const createComponent = ({ showBlame = true } = {}) => {
+ const createComponent = ({ showBlame = true, blob = {} } = {}) => {
fakeApollo = createMockApollo([[blameDataQuery, blameDataQueryHandlerSuccess]]);
wrapper = shallowMountExtended(SourceViewer, {
apolloProvider: fakeApollo,
mocks: { $route: { hash } },
propsData: {
- blob: BLOB_DATA_MOCK,
+ blob: { ...blob, ...BLOB_DATA_MOCK },
chunks: CHUNKS_MOCK,
projectPath: 'test',
+ currentRef: 'main',
showBlame,
},
});
@@ -156,4 +162,20 @@ describe('Source Viewer component', () => {
expect(lineHighlighter.highlightHash).toHaveBeenCalledWith(hash);
});
});
+
+ describe('Codeowners validation', () => {
+ const findCodeownersValidation = () => wrapper.findComponent(CodeownersValidation);
+
+ it('does not render codeowners validation when file is not CODEOWNERS', async () => {
+ await createComponent();
+ await nextTick();
+ expect(findCodeownersValidation().exists()).toBe(false);
+ });
+
+ it('renders codeowners validation when file is CODEOWNERS', async () => {
+ await createComponent({ blob: { name: CODEOWNERS_FILE_NAME } });
+ await nextTick();
+ expect(findCodeownersValidation().exists()).toBe(true);
+ });
+ });
});