Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 3 | @license |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 4 | Copyright (C) 2017 The Android Open Source Project |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | --> |
| 18 | |
| 19 | <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes"> |
| 20 | <title>gr-popup-interface</title> |
Tao Zhou | 8ef16f7 | 2019-11-18 14:14:36 -0800 | [diff] [blame] | 21 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 22 | <script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script> |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 23 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 24 | <script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script> |
| 25 | <script src="/components/wct-browser-legacy/browser.js"></script> |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 26 | |
| 27 | <test-fixture id="container"> |
| 28 | <template> |
| 29 | <div></div> |
| 30 | </template> |
| 31 | </test-fixture> |
| 32 | |
| 33 | <dom-module id="gr-user-test-popup"> |
| 34 | <template> |
| 35 | <div id="barfoo">some test module</div> |
| 36 | </template> |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 37 | <script type="module"> |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 38 | import '../../../test/common-test-setup.js'; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 39 | import '../../shared/gr-js-api-interface/gr-js-api-interface.js'; |
| 40 | import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js'; |
| 41 | Polymer({is: 'gr-user-test-popup'}); |
| 42 | </script> |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 43 | </dom-module> |
| 44 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 45 | <script type="module"> |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 46 | import '../../../test/common-test-setup.js'; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 47 | import '../../shared/gr-js-api-interface/gr-js-api-interface.js'; |
| 48 | import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js'; |
Dmitrii Filippov | 44f47c0 | 2020-03-24 13:53:22 +0100 | [diff] [blame] | 49 | import {GrPopupInterface} from './gr-popup-interface.js'; |
Dmitrii Filippov | 35aea69 | 2020-04-07 12:14:11 +0200 | [diff] [blame^] | 50 | import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js'; |
Dmitrii Filippov | 44f47c0 | 2020-03-24 13:53:22 +0100 | [diff] [blame] | 51 | |
Dmitrii Filippov | 35aea69 | 2020-04-07 12:14:11 +0200 | [diff] [blame^] | 52 | initGerritPluginApi(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 53 | suite('gr-popup-interface tests', () => { |
| 54 | let container; |
| 55 | let instance; |
| 56 | let plugin; |
| 57 | let sandbox; |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 58 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 59 | setup(() => { |
| 60 | sandbox = sinon.sandbox.create(); |
| 61 | Gerrit.install(p => { plugin = p; }, '0.1', |
| 62 | 'http://test.com/plugins/testplugin/static/test.js'); |
| 63 | container = fixture('container'); |
| 64 | sandbox.stub(plugin, 'hook').returns({ |
| 65 | getLastAttached() { |
| 66 | return Promise.resolve(container); |
| 67 | }, |
| 68 | }); |
| 69 | }); |
| 70 | |
| 71 | teardown(() => { |
| 72 | sandbox.restore(); |
| 73 | }); |
| 74 | |
| 75 | suite('manual', () => { |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 76 | setup(() => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 77 | instance = new GrPopupInterface(plugin); |
| 78 | }); |
| 79 | |
| 80 | test('open', done => { |
| 81 | instance.open().then(api => { |
| 82 | assert.strictEqual(api, instance); |
| 83 | const manual = document.createElement('div'); |
| 84 | manual.id = 'foobar'; |
| 85 | manual.innerHTML = 'manual content'; |
| 86 | api._getElement().appendChild(manual); |
| 87 | flushAsynchronousOperations(); |
| 88 | assert.equal( |
| 89 | container.querySelector('#foobar').textContent, 'manual content'); |
| 90 | done(); |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 91 | }); |
| 92 | }); |
| 93 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 94 | test('close', done => { |
| 95 | instance.open().then(api => { |
| 96 | assert.isTrue(api._getElement().node.opened); |
| 97 | api.close(); |
| 98 | assert.isFalse(api._getElement().node.opened); |
| 99 | done(); |
Tao Zhou | b6fdc67 | 2020-01-13 14:21:49 +0100 | [diff] [blame] | 100 | }); |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 101 | }); |
| 102 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 103 | |
| 104 | suite('components', () => { |
| 105 | setup(() => { |
| 106 | instance = new GrPopupInterface(plugin, 'gr-user-test-popup'); |
| 107 | }); |
| 108 | |
| 109 | test('open', done => { |
| 110 | instance.open().then(api => { |
| 111 | assert.isNotNull( |
| 112 | dom(container).querySelector('gr-user-test-popup')); |
| 113 | done(); |
| 114 | }); |
| 115 | }); |
| 116 | |
| 117 | test('close', done => { |
| 118 | instance.open().then(api => { |
| 119 | assert.isTrue(api._getElement().node.opened); |
| 120 | api.close(); |
| 121 | assert.isFalse(api._getElement().node.opened); |
| 122 | done(); |
| 123 | }); |
| 124 | }); |
| 125 | }); |
| 126 | }); |
Viktar Donich | 2f3ee89 | 2017-08-04 09:48:19 -0700 | [diff] [blame] | 127 | </script> |