From 572f9782d5e8d6307784b61db0dfce48f5118445 Mon Sep 17 00:00:00 2001 From: winniehell Date: Sun, 5 Mar 2017 20:43:05 +0100 Subject: Remove .es6 from file extensions (!9241) --- .../vue_shared/components/commit_spec.js | 131 +++++++++++++++++ .../vue_shared/components/commit_spec.js.es6 | 131 ----------------- .../components/pipelines_table_row_spec.js | 87 ++++++++++++ .../components/pipelines_table_row_spec.js.es6 | 87 ------------ .../vue_shared/components/pipelines_table_spec.js | 64 +++++++++ .../components/pipelines_table_spec.js.es6 | 64 --------- .../vue_shared/components/table_pagination_spec.js | 158 +++++++++++++++++++++ .../components/table_pagination_spec.js.es6 | 158 --------------------- 8 files changed, 440 insertions(+), 440 deletions(-) create mode 100644 spec/javascripts/vue_shared/components/commit_spec.js delete mode 100644 spec/javascripts/vue_shared/components/commit_spec.js.es6 create mode 100644 spec/javascripts/vue_shared/components/pipelines_table_row_spec.js delete mode 100644 spec/javascripts/vue_shared/components/pipelines_table_row_spec.js.es6 create mode 100644 spec/javascripts/vue_shared/components/pipelines_table_spec.js delete mode 100644 spec/javascripts/vue_shared/components/pipelines_table_spec.js.es6 create mode 100644 spec/javascripts/vue_shared/components/table_pagination_spec.js delete mode 100644 spec/javascripts/vue_shared/components/table_pagination_spec.js.es6 (limited to 'spec/javascripts/vue_shared') diff --git a/spec/javascripts/vue_shared/components/commit_spec.js b/spec/javascripts/vue_shared/components/commit_spec.js new file mode 100644 index 00000000000..15ab10b9b69 --- /dev/null +++ b/spec/javascripts/vue_shared/components/commit_spec.js @@ -0,0 +1,131 @@ +require('~/vue_shared/components/commit'); + +describe('Commit component', () => { + let props; + let component; + + it('should render a code-fork icon if it does not represent a tag', () => { + setFixtures('
'); + component = new window.gl.CommitComponent({ + el: document.querySelector('.test-commit-container'), + propsData: { + tag: false, + commitRef: { + name: 'master', + ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', + }, + commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', + shortSha: 'b7836edd', + title: 'Commit message', + author: { + avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png', + web_url: 'https://gitlab.com/jschatz1', + username: 'jschatz1', + }, + }, + }); + + expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-code-fork'); + }); + + describe('Given all the props', () => { + beforeEach(() => { + setFixtures('
'); + + props = { + tag: true, + commitRef: { + name: 'master', + ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', + }, + commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', + shortSha: 'b7836edd', + title: 'Commit message', + author: { + avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png', + web_url: 'https://gitlab.com/jschatz1', + username: 'jschatz1', + }, + commitIconSvg: '', + }; + + component = new window.gl.CommitComponent({ + el: document.querySelector('.test-commit-container'), + propsData: props, + }); + }); + + it('should render a tag icon if it represents a tag', () => { + expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-tag'); + }); + + it('should render a link to the ref url', () => { + expect(component.$el.querySelector('.branch-name').getAttribute('href')).toEqual(props.commitRef.ref_url); + }); + + it('should render the ref name', () => { + expect(component.$el.querySelector('.branch-name').textContent).toContain(props.commitRef.name); + }); + + it('should render the commit short sha with a link to the commit url', () => { + expect(component.$el.querySelector('.commit-id').getAttribute('href')).toEqual(props.commitUrl); + expect(component.$el.querySelector('.commit-id').textContent).toContain(props.shortSha); + }); + + it('should render the given commitIconSvg', () => { + expect(component.$el.querySelector('.js-commit-icon').children).toContain('svg'); + }); + + describe('Given commit title and author props', () => { + it('should render a link to the author profile', () => { + expect( + component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href'), + ).toEqual(props.author.web_url); + }); + + it('Should render the author avatar with title and alt attributes', () => { + expect( + component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('title'), + ).toContain(props.author.username); + expect( + component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('alt'), + ).toContain(`${props.author.username}'s avatar`); + }); + }); + + it('should render the commit title', () => { + expect( + component.$el.querySelector('a.commit-row-message').getAttribute('href'), + ).toEqual(props.commitUrl); + expect( + component.$el.querySelector('a.commit-row-message').textContent, + ).toContain(props.title); + }); + }); + + describe('When commit title is not provided', () => { + it('should render default message', () => { + setFixtures('
'); + props = { + tag: false, + commitRef: { + name: 'master', + ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', + }, + commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', + shortSha: 'b7836edd', + title: null, + author: {}, + }; + + component = new window.gl.CommitComponent({ + el: document.querySelector('.test-commit-container'), + propsData: props, + }); + + expect( + component.$el.querySelector('.commit-title span').textContent, + ).toContain('Cant find HEAD commit for this branch'); + }); + }); +}); diff --git a/spec/javascripts/vue_shared/components/commit_spec.js.es6 b/spec/javascripts/vue_shared/components/commit_spec.js.es6 deleted file mode 100644 index 15ab10b9b69..00000000000 --- a/spec/javascripts/vue_shared/components/commit_spec.js.es6 +++ /dev/null @@ -1,131 +0,0 @@ -require('~/vue_shared/components/commit'); - -describe('Commit component', () => { - let props; - let component; - - it('should render a code-fork icon if it does not represent a tag', () => { - setFixtures('
'); - component = new window.gl.CommitComponent({ - el: document.querySelector('.test-commit-container'), - propsData: { - tag: false, - commitRef: { - name: 'master', - ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', - }, - commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', - shortSha: 'b7836edd', - title: 'Commit message', - author: { - avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png', - web_url: 'https://gitlab.com/jschatz1', - username: 'jschatz1', - }, - }, - }); - - expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-code-fork'); - }); - - describe('Given all the props', () => { - beforeEach(() => { - setFixtures('
'); - - props = { - tag: true, - commitRef: { - name: 'master', - ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', - }, - commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', - shortSha: 'b7836edd', - title: 'Commit message', - author: { - avatar_url: 'https://gitlab.com/uploads/user/avatar/300478/avatar.png', - web_url: 'https://gitlab.com/jschatz1', - username: 'jschatz1', - }, - commitIconSvg: '', - }; - - component = new window.gl.CommitComponent({ - el: document.querySelector('.test-commit-container'), - propsData: props, - }); - }); - - it('should render a tag icon if it represents a tag', () => { - expect(component.$el.querySelector('.icon-container i').classList).toContain('fa-tag'); - }); - - it('should render a link to the ref url', () => { - expect(component.$el.querySelector('.branch-name').getAttribute('href')).toEqual(props.commitRef.ref_url); - }); - - it('should render the ref name', () => { - expect(component.$el.querySelector('.branch-name').textContent).toContain(props.commitRef.name); - }); - - it('should render the commit short sha with a link to the commit url', () => { - expect(component.$el.querySelector('.commit-id').getAttribute('href')).toEqual(props.commitUrl); - expect(component.$el.querySelector('.commit-id').textContent).toContain(props.shortSha); - }); - - it('should render the given commitIconSvg', () => { - expect(component.$el.querySelector('.js-commit-icon').children).toContain('svg'); - }); - - describe('Given commit title and author props', () => { - it('should render a link to the author profile', () => { - expect( - component.$el.querySelector('.commit-title .avatar-image-container').getAttribute('href'), - ).toEqual(props.author.web_url); - }); - - it('Should render the author avatar with title and alt attributes', () => { - expect( - component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('title'), - ).toContain(props.author.username); - expect( - component.$el.querySelector('.commit-title .avatar-image-container img').getAttribute('alt'), - ).toContain(`${props.author.username}'s avatar`); - }); - }); - - it('should render the commit title', () => { - expect( - component.$el.querySelector('a.commit-row-message').getAttribute('href'), - ).toEqual(props.commitUrl); - expect( - component.$el.querySelector('a.commit-row-message').textContent, - ).toContain(props.title); - }); - }); - - describe('When commit title is not provided', () => { - it('should render default message', () => { - setFixtures('
'); - props = { - tag: false, - commitRef: { - name: 'master', - ref_url: 'http://localhost/namespace2/gitlabhq/tree/master', - }, - commitUrl: 'https://gitlab.com/gitlab-org/gitlab-ce/commit/b7836eddf62d663c665769e1b0960197fd215067', - shortSha: 'b7836edd', - title: null, - author: {}, - }; - - component = new window.gl.CommitComponent({ - el: document.querySelector('.test-commit-container'), - propsData: props, - }); - - expect( - component.$el.querySelector('.commit-title span').textContent, - ).toContain('Cant find HEAD commit for this branch'); - }); - }); -}); diff --git a/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js b/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js new file mode 100644 index 00000000000..412abfd5e41 --- /dev/null +++ b/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js @@ -0,0 +1,87 @@ +require('~/vue_shared/components/pipelines_table_row'); +const pipeline = require('../../commit/pipelines/mock_data'); + +describe('Pipelines Table Row', () => { + let component; + preloadFixtures('static/environments/element.html.raw'); + + beforeEach(() => { + loadFixtures('static/environments/element.html.raw'); + + component = new gl.pipelines.PipelinesTableRowComponent({ + el: document.querySelector('.test-dom-element'), + propsData: { + pipeline, + svgs: {}, + }, + }); + }); + + it('should render a table row', () => { + expect(component.$el).toEqual('TR'); + }); + + describe('status column', () => { + it('should render a pipeline link', () => { + expect( + component.$el.querySelector('td.commit-link a').getAttribute('href'), + ).toEqual(pipeline.path); + }); + + it('should render status text', () => { + expect( + component.$el.querySelector('td.commit-link a').textContent, + ).toContain(pipeline.details.status.text); + }); + }); + + describe('information column', () => { + it('should render a pipeline link', () => { + expect( + component.$el.querySelector('td:nth-child(2) a').getAttribute('href'), + ).toEqual(pipeline.path); + }); + + it('should render pipeline ID', () => { + expect( + component.$el.querySelector('td:nth-child(2) a > span').textContent, + ).toEqual(`#${pipeline.id}`); + }); + + describe('when a user is provided', () => { + it('should render user information', () => { + expect( + component.$el.querySelector('td:nth-child(2) a:nth-child(3)').getAttribute('href'), + ).toEqual(pipeline.user.web_url); + + expect( + component.$el.querySelector('td:nth-child(2) img').getAttribute('title'), + ).toEqual(pipeline.user.name); + }); + }); + }); + + describe('commit column', () => { + it('should render link to commit', () => { + expect( + component.$el.querySelector('td:nth-child(3) .commit-id').getAttribute('href'), + ).toEqual(pipeline.commit.commit_path); + }); + }); + + describe('stages column', () => { + it('should render an icon for each stage', () => { + expect( + component.$el.querySelectorAll('td:nth-child(4) .js-builds-dropdown-button').length, + ).toEqual(pipeline.details.stages.length); + }); + }); + + describe('actions column', () => { + it('should render the provided actions', () => { + expect( + component.$el.querySelectorAll('td:nth-child(6) ul li').length, + ).toEqual(pipeline.details.manual_actions.length); + }); + }); +}); diff --git a/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js.es6 b/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js.es6 deleted file mode 100644 index 412abfd5e41..00000000000 --- a/spec/javascripts/vue_shared/components/pipelines_table_row_spec.js.es6 +++ /dev/null @@ -1,87 +0,0 @@ -require('~/vue_shared/components/pipelines_table_row'); -const pipeline = require('../../commit/pipelines/mock_data'); - -describe('Pipelines Table Row', () => { - let component; - preloadFixtures('static/environments/element.html.raw'); - - beforeEach(() => { - loadFixtures('static/environments/element.html.raw'); - - component = new gl.pipelines.PipelinesTableRowComponent({ - el: document.querySelector('.test-dom-element'), - propsData: { - pipeline, - svgs: {}, - }, - }); - }); - - it('should render a table row', () => { - expect(component.$el).toEqual('TR'); - }); - - describe('status column', () => { - it('should render a pipeline link', () => { - expect( - component.$el.querySelector('td.commit-link a').getAttribute('href'), - ).toEqual(pipeline.path); - }); - - it('should render status text', () => { - expect( - component.$el.querySelector('td.commit-link a').textContent, - ).toContain(pipeline.details.status.text); - }); - }); - - describe('information column', () => { - it('should render a pipeline link', () => { - expect( - component.$el.querySelector('td:nth-child(2) a').getAttribute('href'), - ).toEqual(pipeline.path); - }); - - it('should render pipeline ID', () => { - expect( - component.$el.querySelector('td:nth-child(2) a > span').textContent, - ).toEqual(`#${pipeline.id}`); - }); - - describe('when a user is provided', () => { - it('should render user information', () => { - expect( - component.$el.querySelector('td:nth-child(2) a:nth-child(3)').getAttribute('href'), - ).toEqual(pipeline.user.web_url); - - expect( - component.$el.querySelector('td:nth-child(2) img').getAttribute('title'), - ).toEqual(pipeline.user.name); - }); - }); - }); - - describe('commit column', () => { - it('should render link to commit', () => { - expect( - component.$el.querySelector('td:nth-child(3) .commit-id').getAttribute('href'), - ).toEqual(pipeline.commit.commit_path); - }); - }); - - describe('stages column', () => { - it('should render an icon for each stage', () => { - expect( - component.$el.querySelectorAll('td:nth-child(4) .js-builds-dropdown-button').length, - ).toEqual(pipeline.details.stages.length); - }); - }); - - describe('actions column', () => { - it('should render the provided actions', () => { - expect( - component.$el.querySelectorAll('td:nth-child(6) ul li').length, - ).toEqual(pipeline.details.manual_actions.length); - }); - }); -}); diff --git a/spec/javascripts/vue_shared/components/pipelines_table_spec.js b/spec/javascripts/vue_shared/components/pipelines_table_spec.js new file mode 100644 index 00000000000..54d81e2ea7d --- /dev/null +++ b/spec/javascripts/vue_shared/components/pipelines_table_spec.js @@ -0,0 +1,64 @@ +require('~/vue_shared/components/pipelines_table'); +require('~/lib/utils/datetime_utility'); +const pipeline = require('../../commit/pipelines/mock_data'); + +describe('Pipelines Table', () => { + preloadFixtures('static/environments/element.html.raw'); + + beforeEach(() => { + loadFixtures('static/environments/element.html.raw'); + }); + + describe('table', () => { + let component; + beforeEach(() => { + component = new gl.pipelines.PipelinesTableComponent({ + el: document.querySelector('.test-dom-element'), + propsData: { + pipelines: [], + svgs: {}, + }, + }); + }); + + it('should render a table', () => { + expect(component.$el).toEqual('TABLE'); + }); + + it('should render table head with correct columns', () => { + expect(component.$el.querySelector('th.js-pipeline-status').textContent).toEqual('Status'); + expect(component.$el.querySelector('th.js-pipeline-info').textContent).toEqual('Pipeline'); + expect(component.$el.querySelector('th.js-pipeline-commit').textContent).toEqual('Commit'); + expect(component.$el.querySelector('th.js-pipeline-stages').textContent).toEqual('Stages'); + expect(component.$el.querySelector('th.js-pipeline-date').textContent).toEqual(''); + expect(component.$el.querySelector('th.js-pipeline-actions').textContent).toEqual(''); + }); + }); + + describe('without data', () => { + it('should render an empty table', () => { + const component = new gl.pipelines.PipelinesTableComponent({ + el: document.querySelector('.test-dom-element'), + propsData: { + pipelines: [], + svgs: {}, + }, + }); + expect(component.$el.querySelectorAll('tbody tr').length).toEqual(0); + }); + }); + + describe('with data', () => { + it('should render rows', () => { + const component = new gl.pipelines.PipelinesTableComponent({ + el: document.querySelector('.test-dom-element'), + propsData: { + pipelines: [pipeline], + svgs: {}, + }, + }); + + expect(component.$el.querySelectorAll('tbody tr').length).toEqual(1); + }); + }); +}); diff --git a/spec/javascripts/vue_shared/components/pipelines_table_spec.js.es6 b/spec/javascripts/vue_shared/components/pipelines_table_spec.js.es6 deleted file mode 100644 index 54d81e2ea7d..00000000000 --- a/spec/javascripts/vue_shared/components/pipelines_table_spec.js.es6 +++ /dev/null @@ -1,64 +0,0 @@ -require('~/vue_shared/components/pipelines_table'); -require('~/lib/utils/datetime_utility'); -const pipeline = require('../../commit/pipelines/mock_data'); - -describe('Pipelines Table', () => { - preloadFixtures('static/environments/element.html.raw'); - - beforeEach(() => { - loadFixtures('static/environments/element.html.raw'); - }); - - describe('table', () => { - let component; - beforeEach(() => { - component = new gl.pipelines.PipelinesTableComponent({ - el: document.querySelector('.test-dom-element'), - propsData: { - pipelines: [], - svgs: {}, - }, - }); - }); - - it('should render a table', () => { - expect(component.$el).toEqual('TABLE'); - }); - - it('should render table head with correct columns', () => { - expect(component.$el.querySelector('th.js-pipeline-status').textContent).toEqual('Status'); - expect(component.$el.querySelector('th.js-pipeline-info').textContent).toEqual('Pipeline'); - expect(component.$el.querySelector('th.js-pipeline-commit').textContent).toEqual('Commit'); - expect(component.$el.querySelector('th.js-pipeline-stages').textContent).toEqual('Stages'); - expect(component.$el.querySelector('th.js-pipeline-date').textContent).toEqual(''); - expect(component.$el.querySelector('th.js-pipeline-actions').textContent).toEqual(''); - }); - }); - - describe('without data', () => { - it('should render an empty table', () => { - const component = new gl.pipelines.PipelinesTableComponent({ - el: document.querySelector('.test-dom-element'), - propsData: { - pipelines: [], - svgs: {}, - }, - }); - expect(component.$el.querySelectorAll('tbody tr').length).toEqual(0); - }); - }); - - describe('with data', () => { - it('should render rows', () => { - const component = new gl.pipelines.PipelinesTableComponent({ - el: document.querySelector('.test-dom-element'), - propsData: { - pipelines: [pipeline], - svgs: {}, - }, - }); - - expect(component.$el.querySelectorAll('tbody tr').length).toEqual(1); - }); - }); -}); diff --git a/spec/javascripts/vue_shared/components/table_pagination_spec.js b/spec/javascripts/vue_shared/components/table_pagination_spec.js new file mode 100644 index 00000000000..9cb067921a7 --- /dev/null +++ b/spec/javascripts/vue_shared/components/table_pagination_spec.js @@ -0,0 +1,158 @@ +require('~/lib/utils/common_utils'); +require('~/vue_shared/components/table_pagination'); + +describe('Pagination component', () => { + let component; + + const changeChanges = { + one: '', + }; + + const change = (one) => { + changeChanges.one = one; + }; + + it('should render and start at page 1', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 2, + previousPage: '', + }, + change, + }, + }); + + expect(component.$el.classList).toContain('gl-pagination'); + + component.changePage({ target: { innerText: '1' } }); + + expect(changeChanges.one).toEqual(1); + }); + + it('should go to the previous page', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 3, + previousPage: 1, + }, + change, + }, + }); + + component.changePage({ target: { innerText: 'Prev' } }); + + expect(changeChanges.one).toEqual(1); + }); + + it('should go to the next page', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 5, + previousPage: 3, + }, + change, + }, + }); + + component.changePage({ target: { innerText: 'Next' } }); + + expect(changeChanges.one).toEqual(5); + }); + + it('should go to the last page', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 5, + previousPage: 3, + }, + change, + }, + }); + + component.changePage({ target: { innerText: 'Last >>' } }); + + expect(changeChanges.one).toEqual(10); + }); + + it('should go to the first page', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 5, + previousPage: 3, + }, + change, + }, + }); + + component.changePage({ target: { innerText: '<< First' } }); + + expect(changeChanges.one).toEqual(1); + }); + + it('should do nothing', () => { + setFixtures('
'); + + component = new window.gl.VueGlPagination({ + el: document.querySelector('.test-pagination-container'), + propsData: { + pageInfo: { + totalPages: 10, + nextPage: 2, + previousPage: '', + }, + change, + }, + }); + + component.changePage({ target: { innerText: '...' } }); + + expect(changeChanges.one).toEqual(1); + }); +}); + +describe('paramHelper', () => { + it('can parse url parameters correctly', () => { + window.history.pushState({}, null, '?scope=all&p=2'); + + const scope = gl.utils.getParameterByName('scope'); + const p = gl.utils.getParameterByName('p'); + + expect(scope).toEqual('all'); + expect(p).toEqual('2'); + }); + + it('returns null if param not in url', () => { + window.history.pushState({}, null, '?p=2'); + + const scope = gl.utils.getParameterByName('scope'); + const p = gl.utils.getParameterByName('p'); + + expect(scope).toEqual(null); + expect(p).toEqual('2'); + }); +}); diff --git a/spec/javascripts/vue_shared/components/table_pagination_spec.js.es6 b/spec/javascripts/vue_shared/components/table_pagination_spec.js.es6 deleted file mode 100644 index 9cb067921a7..00000000000 --- a/spec/javascripts/vue_shared/components/table_pagination_spec.js.es6 +++ /dev/null @@ -1,158 +0,0 @@ -require('~/lib/utils/common_utils'); -require('~/vue_shared/components/table_pagination'); - -describe('Pagination component', () => { - let component; - - const changeChanges = { - one: '', - }; - - const change = (one) => { - changeChanges.one = one; - }; - - it('should render and start at page 1', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 2, - previousPage: '', - }, - change, - }, - }); - - expect(component.$el.classList).toContain('gl-pagination'); - - component.changePage({ target: { innerText: '1' } }); - - expect(changeChanges.one).toEqual(1); - }); - - it('should go to the previous page', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 3, - previousPage: 1, - }, - change, - }, - }); - - component.changePage({ target: { innerText: 'Prev' } }); - - expect(changeChanges.one).toEqual(1); - }); - - it('should go to the next page', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 5, - previousPage: 3, - }, - change, - }, - }); - - component.changePage({ target: { innerText: 'Next' } }); - - expect(changeChanges.one).toEqual(5); - }); - - it('should go to the last page', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 5, - previousPage: 3, - }, - change, - }, - }); - - component.changePage({ target: { innerText: 'Last >>' } }); - - expect(changeChanges.one).toEqual(10); - }); - - it('should go to the first page', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 5, - previousPage: 3, - }, - change, - }, - }); - - component.changePage({ target: { innerText: '<< First' } }); - - expect(changeChanges.one).toEqual(1); - }); - - it('should do nothing', () => { - setFixtures('
'); - - component = new window.gl.VueGlPagination({ - el: document.querySelector('.test-pagination-container'), - propsData: { - pageInfo: { - totalPages: 10, - nextPage: 2, - previousPage: '', - }, - change, - }, - }); - - component.changePage({ target: { innerText: '...' } }); - - expect(changeChanges.one).toEqual(1); - }); -}); - -describe('paramHelper', () => { - it('can parse url parameters correctly', () => { - window.history.pushState({}, null, '?scope=all&p=2'); - - const scope = gl.utils.getParameterByName('scope'); - const p = gl.utils.getParameterByName('p'); - - expect(scope).toEqual('all'); - expect(p).toEqual('2'); - }); - - it('returns null if param not in url', () => { - window.history.pushState({}, null, '?p=2'); - - const scope = gl.utils.getParameterByName('scope'); - const p = gl.utils.getParameterByName('p'); - - expect(scope).toEqual(null); - expect(p).toEqual('2'); - }); -}); -- cgit v1.2.3