summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/change/gr-change-metadata/gr-change-metadata-it_test.html
blob: 90776c08fed8fed98b78fa49120c9ac5c516a756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!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-change-metadata</title>

<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="../../plugins/gr-plugin-host/gr-plugin-host.html">
<link rel="import" href="gr-change-metadata.html">

<script>void(0);</script>

<test-fixture id="element">
  <template>
    <gr-change-metadata></gr-change-metadata>
  </template>
</test-fixture>

<test-fixture id="plugin-host">
  <template>
    <gr-plugin-host></gr-plugin-host>
  </template>
</test-fixture>

<script>
  suite('gr-change-metadata integration tests', () => {
    let sandbox;
    let element;

    const sectionSelectors = [
      'section.assignee',
      'section.labelStatus',
      'section.strategy',
      'section.topic',
    ];

    const getStyle = function(selector, name) {
      return window.getComputedStyle(
          Polymer.dom(element.root).querySelector(selector))[name];
    };

    setup(() => {
      sandbox = sinon.sandbox.create();
      stub('gr-change-metadata', {
        _computeShowLabelStatus() { return true; },
        _computeShowReviewersByState() { return true; },
        ready() {
          this.change = {labels: [], status: 'NEW'};
          this.serverConfig = {};
        },
      });
    });

    teardown(() => {
      Gerrit._pluginsPending = -1;
      Gerrit._allPluginsPromise = undefined;
      sandbox.restore();
    });

    suite('by default', () => {
      setup(done => {
        element = fixture('element');
        flush(done);
      });

      for (const sectionSelector of sectionSelectors) {
        test(sectionSelector + ' does not have display: none', () => {
          assert.notEqual(getStyle(sectionSelector, 'display'), 'none');
        });
      }
    });

    suite('with plugin style', () => {
      setup(done => {
        const pluginHost = fixture('plugin-host');
        pluginHost.config = {
          plugin: {
            js_resource_paths: [],
            html_resource_paths: [
              new URL('test/plugin.html?' + Math.random(),
                      window.location.href).toString(),
            ],
          },
        };
        element = fixture('element');
        const importSpy = sandbox.spy(element.$.externalStyle, '_import');
        Gerrit.awaitPluginsLoaded().then(() => {
          Promise.all(importSpy.returnValues).then(() => {
            flush(done);
          });
        });
      });

      for (const sectionSelector of sectionSelectors) {
        test(sectionSelector + ' may have display: none', () => {
          assert.equal(getStyle(sectionSelector, 'display'), 'none');
        });
      }
    });
  });
</script>