| <!DOCTYPE html> |
| <!-- |
| Copyright (C) 2017 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| <title>gr-project-branches</title> |
| |
| <script src="../../../bower_components/page/page.js"></script> |
| <script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script> |
| <script src="../../../bower_components/web-component-tester/browser.js"></script> |
| <link rel="import" href="../../../test/common-test-setup.html"/> |
| <link rel="import" href="gr-project-branches.html"> |
| |
| <script>void(0);</script> |
| |
| <test-fixture id="basic"> |
| <template> |
| <gr-project-branches></gr-project-branches> |
| </template> |
| </test-fixture> |
| |
| <script> |
| let counter; |
| const branchGenerator = () => { |
| return { |
| ref: `refs/heads/test${++counter}`, |
| revision: '9c9d08a438e55e52f33b608415e6dddd9b18550d', |
| web_links: [ |
| { |
| name: 'diffusion', |
| url: `https://git.example.org/branch/test;refs/heads/test${counter}`, |
| }, |
| ], |
| }; |
| }; |
| |
| suite('gr-project-branches tests', () => { |
| let element; |
| let branches; |
| let sandbox; |
| |
| setup(() => { |
| sandbox = sinon.sandbox.create(); |
| element = fixture('basic'); |
| counter = 0; |
| }); |
| |
| teardown(() => { |
| sandbox.restore(); |
| }); |
| |
| suite('list with project branches', () => { |
| setup(done => { |
| branches = _.times(26, branchGenerator); |
| |
| stub('gr-rest-api-interface', { |
| getProjectBranches(num, project, offset) { |
| return Promise.resolve(branches); |
| }, |
| }); |
| |
| const params = { |
| project: 'test', |
| }; |
| |
| element._paramsChanged(params).then(() => { flush(done); }); |
| }); |
| |
| test('test for test branch in the list', done => { |
| flush(() => { |
| assert.equal(element._branches[1].ref, 'refs/heads/test2'); |
| done(); |
| }); |
| }); |
| |
| test('test for test web links in the branches list', done => { |
| flush(() => { |
| assert.equal(element._branches[1].web_links[0].url, |
| 'https://git.example.org/branch/test;refs/heads/test2'); |
| done(); |
| }); |
| }); |
| |
| test('test for refs/heads/ being striped from ref', done => { |
| flush(() => { |
| assert.equal(element._stripRefsHeads(element._branches[1].ref), |
| 'test2'); |
| done(); |
| }); |
| }); |
| |
| test('_shownBranches', () => { |
| assert.equal(element._shownBranches.length, 25); |
| }); |
| }); |
| |
| suite('list with less then 25 branches', () => { |
| setup(done => { |
| branches = _.times(25, branchGenerator); |
| |
| stub('gr-rest-api-interface', { |
| getProjectBranches(num, project, offset) { |
| return Promise.resolve(branches); |
| }, |
| }); |
| |
| const params = { |
| project: 'test', |
| }; |
| |
| element._paramsChanged(params).then(() => { flush(done); }); |
| }); |
| |
| test('_shownProjectsBranches', () => { |
| assert.equal(element._shownBranches.length, 25); |
| }); |
| }); |
| |
| suite('filter', () => { |
| test('_paramsChanged', done => { |
| sandbox.stub(element.$.restAPI, 'getProjectBranches', () => { |
| return Promise.resolve(branches); |
| }); |
| const params = { |
| project: 'test', |
| filter: 'test', |
| offset: 25, |
| }; |
| element._paramsChanged(params).then(() => { |
| assert.isTrue(element.$.restAPI.getProjectBranches.lastCall |
| .calledWithExactly('test', 'test', 25, 25)); |
| done(); |
| }); |
| }); |
| }); |
| }); |
| </script> |