summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/stores
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-14 18:09:54 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-14 18:09:54 +0000
commitf697dc5e76dfc5894df006d53b2b7e751653cf05 (patch)
tree1387cd225039e611f3683f96b318bb17d4c422cb /spec/frontend/releases/stores
parent874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff)
downloadgitlab-ce-f697dc5e76dfc5894df006d53b2b7e751653cf05.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/releases/stores')
-rw-r--r--spec/frontend/releases/stores/modules/detail/getters_spec.js154
1 files changed, 154 insertions, 0 deletions
diff --git a/spec/frontend/releases/stores/modules/detail/getters_spec.js b/spec/frontend/releases/stores/modules/detail/getters_spec.js
index 7dc95c24055..8945ad97c93 100644
--- a/spec/frontend/releases/stores/modules/detail/getters_spec.js
+++ b/spec/frontend/releases/stores/modules/detail/getters_spec.js
@@ -56,4 +56,158 @@ describe('Release detail getters', () => {
expect(getters.releaseLinksToDelete(state)).toEqual(originalLinks);
});
});
+
+ describe('validationErrors', () => {
+ describe('when the form is valid', () => {
+ it('returns no validation errors', () => {
+ const state = {
+ release: {
+ assets: {
+ links: [
+ { id: 1, url: 'https://example.com/valid', name: 'Link 1' },
+ { id: 2, url: '', name: '' },
+ { id: 3, url: '', name: ' ' },
+ { id: 4, url: ' ', name: '' },
+ { id: 5, url: ' ', name: ' ' },
+ ],
+ },
+ },
+ };
+
+ const expectedErrors = {
+ assets: {
+ links: {
+ 1: {},
+ 2: {},
+ 3: {},
+ 4: {},
+ 5: {},
+ },
+ },
+ };
+
+ expect(getters.validationErrors(state)).toEqual(expectedErrors);
+ });
+ });
+
+ describe('when the form is invalid', () => {
+ let actualErrors;
+
+ beforeEach(() => {
+ const state = {
+ release: {
+ assets: {
+ links: [
+ // Duplicate URLs
+ { id: 1, url: 'https://example.com/duplicate', name: 'Link 1' },
+ { id: 2, url: 'https://example.com/duplicate', name: 'Link 2' },
+
+ // the validation check ignores leading/trailing
+ // whitespace and is case-insensitive
+ { id: 3, url: ' \tHTTPS://EXAMPLE.COM/DUPLICATE\n\r\n ', name: 'Link 3' },
+
+ // Invalid URL format
+ { id: 4, url: 'invalid', name: 'Link 4' },
+
+ // Missing URL
+ { id: 5, url: '', name: 'Link 5' },
+ { id: 6, url: ' ', name: 'Link 6' },
+
+ // Missing title
+ { id: 7, url: 'https://example.com/valid/1', name: '' },
+ { id: 8, url: 'https://example.com/valid/2', name: ' ' },
+ ],
+ },
+ },
+ };
+
+ actualErrors = getters.validationErrors(state);
+ });
+
+ it('returns a validation errors if links share a URL', () => {
+ const expectedErrors = {
+ assets: {
+ links: {
+ 1: { isDuplicate: true },
+ 2: { isDuplicate: true },
+ 3: { isDuplicate: true },
+ },
+ },
+ };
+
+ expect(actualErrors).toMatchObject(expectedErrors);
+ });
+
+ it('returns a validation error if the URL is in the wrong format', () => {
+ const expectedErrors = {
+ assets: {
+ links: {
+ 4: { isBadFormat: true },
+ },
+ },
+ };
+
+ expect(actualErrors).toMatchObject(expectedErrors);
+ });
+
+ it('returns a validation error if the URL missing (and the title is populated)', () => {
+ const expectedErrors = {
+ assets: {
+ links: {
+ 6: { isUrlEmpty: true },
+ 5: { isUrlEmpty: true },
+ },
+ },
+ };
+
+ expect(actualErrors).toMatchObject(expectedErrors);
+ });
+
+ it('returns a validation error if the title missing (and the URL is populated)', () => {
+ const expectedErrors = {
+ assets: {
+ links: {
+ 7: { isNameEmpty: true },
+ 8: { isNameEmpty: true },
+ },
+ },
+ };
+
+ expect(actualErrors).toMatchObject(expectedErrors);
+ });
+ });
+ });
+
+ describe('isValid', () => {
+ // the value of state is not actually used by this getter
+ const state = {};
+
+ it('returns true when the form is valid', () => {
+ const mockGetters = {
+ validationErrors: {
+ assets: {
+ links: {
+ 1: {},
+ },
+ },
+ },
+ };
+
+ expect(getters.isValid(state, mockGetters)).toBe(true);
+ });
+
+ it('returns false when the form is invalid', () => {
+ const mockGetters = {
+ validationErrors: {
+ assets: {
+ links: {
+ 1: { isNameEmpty: true },
+ },
+ },
+ },
+ };
+
+ expect(getters.isValid(state, mockGetters)).toBe(false);
+ });
+ });
});