Andrew Bonventre | 8061a65 | 2015-12-16 18:34:58 -0500 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (C) 2015 The Android Open Source Project |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | --> |
| 17 | |
| 18 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| 19 | <title>gr-patch-range-select</title> |
| 20 | |
Urs Wolfer | f2f936f | 2016-01-25 19:26:30 +0100 | [diff] [blame^] | 21 | <script src="../bower_components/webcomponentsjs/webcomponents.min.js"></script> |
| 22 | <script src="../bower_components/web-component-tester/browser.js"></script> |
| 23 | <script src="../bower_components/page/page.js"></script> |
Andrew Bonventre | 8061a65 | 2015-12-16 18:34:58 -0500 | [diff] [blame] | 24 | |
Urs Wolfer | f2f936f | 2016-01-25 19:26:30 +0100 | [diff] [blame^] | 25 | <link rel="import" href="../bower_components/iron-test-helpers/iron-test-helpers.html"> |
Andrew Bonventre | 8061a65 | 2015-12-16 18:34:58 -0500 | [diff] [blame] | 26 | <link rel="import" href="../elements/gr-patch-range-select.html"> |
| 27 | |
| 28 | <test-fixture id="basic"> |
| 29 | <template> |
| 30 | <gr-patch-range-select auto></gr-patch-range-select> |
| 31 | </template> |
| 32 | </test-fixture> |
| 33 | |
| 34 | <script> |
| 35 | suite('gr-patch-range-select tests', function() { |
| 36 | var element; |
| 37 | |
| 38 | setup(function() { |
| 39 | element = fixture('basic'); |
| 40 | }); |
| 41 | |
| 42 | test('enabled/disabled options', function() { |
| 43 | var patchRange = { |
| 44 | basePatchNum: 'PARENT', |
| 45 | patchNum: '3', |
| 46 | }; |
| 47 | ['1', '2', '3'].forEach(function(patchNum) { |
| 48 | assert.isFalse(element._computeRightDisabled(patchNum, patchRange)); |
| 49 | }); |
| 50 | ['PARENT', '1', '2'].forEach(function(patchNum) { |
| 51 | assert.isFalse(element._computeLeftDisabled(patchNum, patchRange)); |
| 52 | }); |
| 53 | assert.isTrue(element._computeLeftDisabled('3', patchRange)); |
| 54 | |
| 55 | patchRange.basePatchNum = '2'; |
| 56 | assert.isTrue(element._computeLeftDisabled('3', patchRange)); |
| 57 | assert.isTrue(element._computeRightDisabled('1', patchRange)); |
| 58 | assert.isTrue(element._computeRightDisabled('2', patchRange)); |
| 59 | assert.isFalse(element._computeRightDisabled('3', patchRange)); |
| 60 | }); |
| 61 | |
| 62 | test('navigation', function(done) { |
| 63 | var showStub = sinon.stub(page, 'show'); |
| 64 | var leftSelectEl = element.$.leftPatchSelect; |
| 65 | var rightSelectEl = element.$.rightPatchSelect; |
| 66 | element.changeNum = '42'; |
| 67 | element.path = 'path/to/file.txt'; |
| 68 | element.availablePatches = ['1', '2', '3']; |
| 69 | flushAsynchronousOperations(); |
| 70 | |
| 71 | var numEvents = 0; |
| 72 | leftSelectEl.addEventListener('change', function(e) { |
| 73 | numEvents++; |
| 74 | if (numEvents == 1) { |
| 75 | assert(showStub.lastCall.calledWithExactly( |
| 76 | '/c/42/3/path/to/file.txt'), |
| 77 | 'Should navigate to /c/42/3/path/to/file.txt'); |
| 78 | leftSelectEl.value = '1'; |
| 79 | element.fire('change', {}, {node: leftSelectEl}); |
| 80 | } else if (numEvents == 2) { |
| 81 | assert(showStub.lastCall.calledWithExactly( |
| 82 | '/c/42/1..3/path/to/file.txt'), |
| 83 | 'Should navigate to /c/42/1..3/path/to/file.txt'); |
| 84 | showStub.restore(); |
| 85 | done(); |
| 86 | } |
| 87 | }); |
| 88 | leftSelectEl.value = 'PARENT'; |
| 89 | rightSelectEl.value = '3'; |
| 90 | element.fire('change', {}, {node: leftSelectEl}); |
| 91 | }); |
| 92 | }); |
| 93 | </script> |