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:
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r--spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js150
-rw-r--r--spec/frontend/lib/utils/common_utils_spec.js23
-rw-r--r--spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js59
-rw-r--r--spec/frontend/lib/utils/datetime_utility_spec.js10
-rw-r--r--spec/frontend/lib/utils/file_upload_spec.js28
-rw-r--r--spec/frontend/lib/utils/text_markdown_spec.js4
-rw-r--r--spec/frontend/lib/utils/url_utility_spec.js8
7 files changed, 185 insertions, 97 deletions
diff --git a/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js b/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js
index 852106db44e..7b604724977 100644
--- a/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js
+++ b/spec/frontend/lib/apollo/suppress_network_errors_during_navigation_link_spec.js
@@ -47,107 +47,95 @@ describe('getSuppressNetworkErrorsDuringNavigationLink', () => {
subscription = link.request(mockOperation).subscribe(observer);
};
- describe('when disabled', () => {
- it('returns null', () => {
- expect(getSuppressNetworkErrorsDuringNavigationLink()).toBe(null);
- });
+ it('returns an ApolloLink', () => {
+ expect(getSuppressNetworkErrorsDuringNavigationLink()).toEqual(expect.any(ApolloLink));
});
- describe('when enabled', () => {
- beforeEach(() => {
- window.gon = { features: { suppressApolloErrorsDuringNavigation: true } };
- });
-
- it('returns an ApolloLink', () => {
- expect(getSuppressNetworkErrorsDuringNavigationLink()).toEqual(expect.any(ApolloLink));
- });
-
- describe('suppression case', () => {
- describe('when navigating away', () => {
- beforeEach(() => {
- isNavigatingAway.mockReturnValue(true);
- });
-
- describe('given a network error', () => {
- it('does not forward the error', async () => {
- const spy = jest.fn();
+ describe('suppression case', () => {
+ describe('when navigating away', () => {
+ beforeEach(() => {
+ isNavigatingAway.mockReturnValue(true);
+ });
- createSubscription(makeMockNetworkErrorLink(), {
- next: spy,
- error: spy,
- complete: spy,
- });
+ describe('given a network error', () => {
+ it('does not forward the error', async () => {
+ const spy = jest.fn();
- // It's hard to test for something _not_ happening. The best we can
- // do is wait a bit to make sure nothing happens.
- await waitForPromises();
- expect(spy).not.toHaveBeenCalled();
+ createSubscription(makeMockNetworkErrorLink(), {
+ next: spy,
+ error: spy,
+ complete: spy,
});
+
+ // It's hard to test for something _not_ happening. The best we can
+ // do is wait a bit to make sure nothing happens.
+ await waitForPromises();
+ expect(spy).not.toHaveBeenCalled();
});
});
});
+ });
- describe('non-suppression cases', () => {
- describe('when not navigating away', () => {
- beforeEach(() => {
- isNavigatingAway.mockReturnValue(false);
- });
+ describe('non-suppression cases', () => {
+ describe('when not navigating away', () => {
+ beforeEach(() => {
+ isNavigatingAway.mockReturnValue(false);
+ });
- it('forwards successful requests', (done) => {
- createSubscription(makeMockSuccessLink(), {
- next({ data }) {
- expect(data).toEqual({ foo: { id: 1 } });
- },
- error: () => done.fail('Should not happen'),
- complete: () => done(),
- });
+ it('forwards successful requests', (done) => {
+ createSubscription(makeMockSuccessLink(), {
+ next({ data }) {
+ expect(data).toEqual({ foo: { id: 1 } });
+ },
+ error: () => done.fail('Should not happen'),
+ complete: () => done(),
});
+ });
- it('forwards GraphQL errors', (done) => {
- createSubscription(makeMockGraphQLErrorLink(), {
- next({ errors }) {
- expect(errors).toEqual([{ message: 'foo' }]);
- },
- error: () => done.fail('Should not happen'),
- complete: () => done(),
- });
+ it('forwards GraphQL errors', (done) => {
+ createSubscription(makeMockGraphQLErrorLink(), {
+ next({ errors }) {
+ expect(errors).toEqual([{ message: 'foo' }]);
+ },
+ error: () => done.fail('Should not happen'),
+ complete: () => done(),
});
+ });
- it('forwards network errors', (done) => {
- createSubscription(makeMockNetworkErrorLink(), {
- next: () => done.fail('Should not happen'),
- error: (error) => {
- expect(error.message).toBe('NetworkError');
- done();
- },
- complete: () => done.fail('Should not happen'),
- });
+ it('forwards network errors', (done) => {
+ createSubscription(makeMockNetworkErrorLink(), {
+ next: () => done.fail('Should not happen'),
+ error: (error) => {
+ expect(error.message).toBe('NetworkError');
+ done();
+ },
+ complete: () => done.fail('Should not happen'),
});
});
+ });
- describe('when navigating away', () => {
- beforeEach(() => {
- isNavigatingAway.mockReturnValue(true);
- });
+ describe('when navigating away', () => {
+ beforeEach(() => {
+ isNavigatingAway.mockReturnValue(true);
+ });
- it('forwards successful requests', (done) => {
- createSubscription(makeMockSuccessLink(), {
- next({ data }) {
- expect(data).toEqual({ foo: { id: 1 } });
- },
- error: () => done.fail('Should not happen'),
- complete: () => done(),
- });
+ it('forwards successful requests', (done) => {
+ createSubscription(makeMockSuccessLink(), {
+ next({ data }) {
+ expect(data).toEqual({ foo: { id: 1 } });
+ },
+ error: () => done.fail('Should not happen'),
+ complete: () => done(),
});
+ });
- it('forwards GraphQL errors', (done) => {
- createSubscription(makeMockGraphQLErrorLink(), {
- next({ errors }) {
- expect(errors).toEqual([{ message: 'foo' }]);
- },
- error: () => done.fail('Should not happen'),
- complete: () => done(),
- });
+ it('forwards GraphQL errors', (done) => {
+ createSubscription(makeMockGraphQLErrorLink(), {
+ next({ errors }) {
+ expect(errors).toEqual([{ message: 'foo' }]);
+ },
+ error: () => done.fail('Should not happen'),
+ complete: () => done(),
});
});
});
diff --git a/spec/frontend/lib/utils/common_utils_spec.js b/spec/frontend/lib/utils/common_utils_spec.js
index f5a74ee7f09..de1be5bc337 100644
--- a/spec/frontend/lib/utils/common_utils_spec.js
+++ b/spec/frontend/lib/utils/common_utils_spec.js
@@ -279,6 +279,14 @@ describe('common_utils', () => {
top: elementTopWithContext,
});
});
+
+ it('passes through behaviour', () => {
+ commonUtils.scrollToElementWithContext(`#${id}`, { behavior: 'smooth' });
+ expect(window.scrollTo).toHaveBeenCalledWith({
+ behavior: 'smooth',
+ top: elementTopWithContext,
+ });
+ });
});
});
@@ -1000,6 +1008,21 @@ describe('common_utils', () => {
});
});
+ describe('scopedLabelKey', () => {
+ it.each`
+ label | expectedLabelKey
+ ${undefined} | ${''}
+ ${''} | ${''}
+ ${'title'} | ${'title'}
+ ${'scoped::value'} | ${'scoped'}
+ ${'scoped::label::value'} | ${'scoped::label'}
+ ${'scoped::label-some::value'} | ${'scoped::label-some'}
+ ${'scoped::label::some::value'} | ${'scoped::label::some'}
+ `('returns "$expectedLabelKey" when label is "$label"', ({ label, expectedLabelKey }) => {
+ expect(commonUtils.scopedLabelKey({ title: label })).toBe(expectedLabelKey);
+ });
+ });
+
describe('getDashPath', () => {
it('returns the path following /-/', () => {
expect(commonUtils.getDashPath('/some/-/url-with-dashes-/')).toEqual('url-with-dashes-/');
diff --git a/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js
new file mode 100644
index 00000000000..d19f9352bbc
--- /dev/null
+++ b/spec/frontend/lib/utils/confirm_via_gl_modal/confirm_modal_spec.js
@@ -0,0 +1,59 @@
+import { GlModal } from '@gitlab/ui';
+import { mount } from '@vue/test-utils';
+import ConfirmModal from '~/lib/utils/confirm_via_gl_modal/confirm_modal.vue';
+
+describe('Confirm Modal', () => {
+ let wrapper;
+ let modal;
+
+ const createComponent = ({ primaryText, primaryVariant } = {}) => {
+ wrapper = mount(ConfirmModal, {
+ propsData: {
+ primaryText,
+ primaryVariant,
+ },
+ });
+ };
+
+ afterEach(() => {
+ wrapper.destroy();
+ });
+
+ const findGlModal = () => wrapper.findComponent(GlModal);
+
+ describe('Modal events', () => {
+ beforeEach(() => {
+ createComponent();
+ modal = findGlModal();
+ });
+
+ it('should emit `confirmed` event on `primary` modal event', () => {
+ findGlModal().vm.$emit('primary');
+ expect(wrapper.emitted('confirmed')).toBeTruthy();
+ });
+
+ it('should emit closed` event on `hidden` modal event', () => {
+ modal.vm.$emit('hidden');
+ expect(wrapper.emitted('closed')).toBeTruthy();
+ });
+ });
+
+ describe('Custom properties', () => {
+ it('should pass correct custom primary text & button variant to the modal when provided', () => {
+ const primaryText = "Let's do it!";
+ const primaryVariant = 'danger';
+
+ createComponent({ primaryText, primaryVariant });
+ const customProps = findGlModal().props('actionPrimary');
+ expect(customProps.text).toBe(primaryText);
+ expect(customProps.attributes.variant).toBe(primaryVariant);
+ });
+
+ it('should pass default primary text & button variant to the modal if no custom values provided', () => {
+ createComponent();
+ const customProps = findGlModal().props('actionPrimary');
+ expect(customProps.text).toBe('OK');
+ expect(customProps.attributes.variant).toBe('confirm');
+ });
+ });
+});
diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js
index f6ad41d5478..7a64b654baa 100644
--- a/spec/frontend/lib/utils/datetime_utility_spec.js
+++ b/spec/frontend/lib/utils/datetime_utility_spec.js
@@ -185,15 +185,15 @@ describe('dateInWords', () => {
const date = new Date('07/01/2016');
it('should return date in words', () => {
- expect(datetimeUtility.dateInWords(date)).toEqual(s__('July 1, 2016'));
+ expect(datetimeUtility.dateInWords(date)).toEqual(__('July 1, 2016'));
});
it('should return abbreviated month name', () => {
- expect(datetimeUtility.dateInWords(date, true)).toEqual(s__('Jul 1, 2016'));
+ expect(datetimeUtility.dateInWords(date, true)).toEqual(__('Jul 1, 2016'));
});
it('should return date in words without year', () => {
- expect(datetimeUtility.dateInWords(date, true, true)).toEqual(s__('Jul 1'));
+ expect(datetimeUtility.dateInWords(date, true, true)).toEqual(__('Jul 1'));
});
});
@@ -201,11 +201,11 @@ describe('monthInWords', () => {
const date = new Date('2017-01-20');
it('returns month name from provided date', () => {
- expect(datetimeUtility.monthInWords(date)).toBe(s__('January'));
+ expect(datetimeUtility.monthInWords(date)).toBe(__('January'));
});
it('returns abbreviated month name from provided date', () => {
- expect(datetimeUtility.monthInWords(date, true)).toBe(s__('Jan'));
+ expect(datetimeUtility.monthInWords(date, true)).toBe(__('Jan'));
});
});
diff --git a/spec/frontend/lib/utils/file_upload_spec.js b/spec/frontend/lib/utils/file_upload_spec.js
index 1dff5d4f925..ff11107ea60 100644
--- a/spec/frontend/lib/utils/file_upload_spec.js
+++ b/spec/frontend/lib/utils/file_upload_spec.js
@@ -1,4 +1,4 @@
-import fileUpload, { getFilename } from '~/lib/utils/file_upload';
+import fileUpload, { getFilename, validateImageName } from '~/lib/utils/file_upload';
describe('File upload', () => {
beforeEach(() => {
@@ -64,13 +64,23 @@ describe('File upload', () => {
});
describe('getFilename', () => {
- it('returns first value correctly', () => {
- const event = {
- clipboardData: {
- getData: () => 'test.png\rtest.txt',
- },
- };
-
- expect(getFilename(event)).toBe('test.png');
+ it('returns file name', () => {
+ const file = new File([], 'test.jpg');
+
+ expect(getFilename(file)).toBe('test.jpg');
+ });
+});
+
+describe('file name validator', () => {
+ it('validate file name', () => {
+ const file = new File([], 'test.jpg');
+
+ expect(validateImageName(file)).toBe('test.jpg');
+ });
+
+ it('illegal file name should be rename to image.png', () => {
+ const file = new File([], 'test<.png');
+
+ expect(validateImageName(file)).toBe('image.png');
});
});
diff --git a/spec/frontend/lib/utils/text_markdown_spec.js b/spec/frontend/lib/utils/text_markdown_spec.js
index acbf1a975b8..ab81ec47b64 100644
--- a/spec/frontend/lib/utils/text_markdown_spec.js
+++ b/spec/frontend/lib/utils/text_markdown_spec.js
@@ -100,11 +100,11 @@ describe('init markdown', () => {
text: textArea.value,
tag: '```suggestion:-0+0\n{text}\n```',
blockTag: true,
- selected: '# Does not parse the %br currently.',
+ selected: '# Does not %br parse the %br currently.',
wrap: false,
});
- expect(textArea.value).toContain('# Does not parse the \\n currently.');
+ expect(textArea.value).toContain('# Does not \\n parse the \\n currently.');
});
it('inserts the tag on the same line if the current line only contains spaces', () => {
diff --git a/spec/frontend/lib/utils/url_utility_spec.js b/spec/frontend/lib/utils/url_utility_spec.js
index 36e1a453ef4..c6edba19c56 100644
--- a/spec/frontend/lib/utils/url_utility_spec.js
+++ b/spec/frontend/lib/utils/url_utility_spec.js
@@ -1060,4 +1060,12 @@ describe('URL utility', () => {
},
);
});
+
+ describe('defaultPromoUrl', () => {
+ it('Gitlab about page url', () => {
+ const url = 'https://about.gitlab.com';
+
+ expect(urlUtils.PROMO_URL).toBe(url);
+ });
+ });
});