blob: 612c61fd4f227c9d741bef244e184b8e07493446 [file] [log] [blame]
Viktar Donich2f3ee892017-08-04 09:48:19 -07001<!DOCTYPE html>
2<!--
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04003@license
Viktar Donich2f3ee892017-08-04 09:48:19 -07004Copyright (C) 2017 The Android Open Source Project
5
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9
10http://www.apache.org/licenses/LICENSE-2.0
11
12Unless required by applicable law or agreed to in writing, software
13distributed under the License is distributed on an "AS IS" BASIS,
14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15See the License for the specific language governing permissions and
16limitations 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 Zhou8ef16f72019-11-18 14:14:36 -080021
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010022<script src="/node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
Viktar Donich2f3ee892017-08-04 09:48:19 -070023
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010024<script src="/node_modules/@webcomponents/webcomponentsjs/webcomponents-lite.js"></script>
25<script src="/components/wct-browser-legacy/browser.js"></script>
Viktar Donich2f3ee892017-08-04 09:48:19 -070026
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 Filippovdaf0ec92020-03-17 11:27:28 +010037 <script type="module">
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010038import '../../../test/common-test-setup.js';
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010039import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
40import {Polymer} from '@polymer/polymer/lib/legacy/polymer-fn.js';
41Polymer({is: 'gr-user-test-popup'});
42</script>
Viktar Donich2f3ee892017-08-04 09:48:19 -070043</dom-module>
44
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010045<script type="module">
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010046import '../../../test/common-test-setup.js';
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010047import '../../shared/gr-js-api-interface/gr-js-api-interface.js';
48import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
Dmitrii Filippov44f47c02020-03-24 13:53:22 +010049import {GrPopupInterface} from './gr-popup-interface.js';
Dmitrii Filippov35aea692020-04-07 12:14:11 +020050import {initGerritPluginApi} from '../../shared/gr-js-api-interface/gr-gerrit.js';
Dmitrii Filippov44f47c02020-03-24 13:53:22 +010051
Dmitrii Filippov35aea692020-04-07 12:14:11 +020052initGerritPluginApi();
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010053suite('gr-popup-interface tests', () => {
54 let container;
55 let instance;
56 let plugin;
57 let sandbox;
Viktar Donich2f3ee892017-08-04 09:48:19 -070058
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010059 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 Donich2f3ee892017-08-04 09:48:19 -070076 setup(() => {
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010077 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 Donich2f3ee892017-08-04 09:48:19 -070091 });
92 });
93
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010094 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 Zhoub6fdc672020-01-13 14:21:49 +0100100 });
Viktar Donich2f3ee892017-08-04 09:48:19 -0700101 });
102 });
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +0100103
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 Donich2f3ee892017-08-04 09:48:19 -0700127</script>