Skip to content

Commit

Permalink
add test-overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
valdrinkoshi committed Mar 30, 2017
1 parent bfa48f4 commit 2f20d8b
Show file tree
Hide file tree
Showing 3 changed files with 462 additions and 455 deletions.
184 changes: 70 additions & 114 deletions test/iron-overlay-container.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,120 +10,76 @@
-->
<html>

<head>

<title>iron-overlay-container tests</title>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">

<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>

<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../iron-overlay-container.html">

</head>

<body>

<dom-module id="test-overlay">
<script>
HTMLImports.whenReady(function () {
class TestOverlay extends Polymer.Element {
static get is() {
return 'test-overlay';
}
_onTap() {}
_onEsc() {}

fireAttach() {
this.renderer = this.renderer || document.createElement('div');

var event = new Event('iron-overlay-attach', {
bubbles: true,
cancelable: true,
composed: true
});
event.detail = {
overlay: this
};
this.dispatchEvent(event);
return event;
}

fireDetach() {
var event = new Event('iron-overlay-detach', {
bubbles: true,
cancelable: true,
composed: true
});
event.detail = {
overlay: this
};
this.renderer.dispatchEvent(event);
return event;
}
}

customElements.define(TestOverlay.is, TestOverlay);
});
</script>
</dom-module>

<test-fixture id="basic">
<template>
<iron-overlay-container></iron-overlay-container>
</template>
</test-fixture>

<test-fixture id="overlays">
<template>
<test-overlay></test-overlay>
<test-overlay></test-overlay>
</template>
</test-fixture>

<script>

suite('<iron-overlay-container>', function () {
var container;
var overlay1;
var overlay2;

setup(function () {
container = fixture('basic');
var overlays = fixture('overlays');
overlay1 = overlays[0];
overlay2 = overlays[1];
});

test('handles iron-overlay-attach', function () {
assert.isTrue(overlay1.fireAttach().defaultPrevented, 'event handled');
assert.equal(overlay1.renderer.parentNode, container, 'renderer hosted');
assert.equal(overlay1, container.currentOverlay, 'currentOverlay updated');
});

test('handles iron-overlay-detach', function () {
overlay1.fireAttach();
assert.isTrue(overlay1.fireDetach().defaultPrevented, 'event handled');
assert.isNotOk(overlay1.renderer.parentNode, 'renderer detached');
assert.isNotOk(container.currentOverlay, 'currentOverlay updated');
});

test('detach and attach to bring overlay on top', function () {
overlay1.fireAttach();
overlay2.fireAttach();
assert.equal(overlay2, container.currentOverlay, 'renderer2 on top');
// Bring overlay1 on top.
overlay1.fireDetach();
overlay1.fireAttach();
assert.equal(overlay1, container.currentOverlay, 'renderer1 on top');
});
<head>

<title>iron-overlay-container tests</title>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">

<script src="../../webcomponentsjs/webcomponents-loader.js"></script>
<script src="../../web-component-tester/browser.js"></script>

<link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="../iron-overlay-container.html">
<link rel="import" href="test-overlay.html">

</head>

<body>

<test-fixture id="basic">
<template>
<iron-overlay-container></iron-overlay-container>
</template>
</test-fixture>

<test-fixture id="overlays">
<template>
<test-overlay></test-overlay>
<test-overlay></test-overlay>
</template>
</test-fixture>

<script>
suite('<iron-overlay-container>', function() {
var container;
var overlay1;
var overlay2;

setup(function() {
container = fixture('basic');
var overlays = fixture('overlays');
overlay1 = overlays[0];
overlay2 = overlays[1];
});

test('handles iron-overlay-attach', function() {
assert.isTrue(overlay1.fireAttach().defaultPrevented, 'event handled');
assert.equal(overlay1.renderer.parentNode, container, 'renderer hosted');
assert.equal(overlay1, container.currentOverlay, 'currentOverlay updated');
});

test('handles iron-overlay-detach', function() {
overlay1.fireAttach();
assert.isTrue(overlay1.fireDetach().defaultPrevented, 'event handled');
assert.isNotOk(overlay1.renderer.parentNode, 'renderer detached');
assert.isNotOk(container.currentOverlay, 'currentOverlay updated');
});

test('detach and attach to bring overlay on top', function() {
overlay1.fireAttach();
overlay2.fireAttach();
assert.equal(overlay2, container.currentOverlay, 'renderer2 on top');
// Bring overlay1 on top.
overlay1.fireDetach();
overlay1.fireAttach();
assert.equal(overlay1, container.currentOverlay, 'renderer1 on top');
});
</script>
});
</script>

</body>
</body>

</html>
</html>
Loading

0 comments on commit 2f20d8b

Please sign in to comment.