|
1 | 1 | import { expect } from '@esm-bundle/chai'; |
2 | 2 | import { fixtureSync } from '@vaadin/testing-helpers'; |
3 | 3 | import sinon from 'sinon'; |
4 | | -import '@vaadin/polymer-legacy-adapter/template-renderer.js'; |
5 | 4 | import '../vaadin-dialog.js'; |
6 | 5 |
|
7 | 6 | describe('vaadin-dialog renderer', () => { |
8 | | - describe('without template', () => { |
9 | | - let dialog, overlay; |
| 7 | + let dialog, overlay; |
10 | 8 |
|
11 | | - beforeEach(() => { |
12 | | - dialog = fixtureSync('<vaadin-dialog></vaadin-dialog>'); |
13 | | - overlay = dialog.$.overlay; |
14 | | - }); |
15 | | - |
16 | | - it('should render the content of renderer function when renderer function provided', () => { |
17 | | - dialog.renderer = (root) => { |
18 | | - const div = document.createElement('div'); |
19 | | - div.textContent = 'The content of the dialog'; |
20 | | - root.appendChild(div); |
21 | | - }; |
22 | | - dialog.opened = true; |
23 | | - |
24 | | - expect(overlay.textContent).to.include('The content of the dialog'); |
25 | | - }); |
26 | | - |
27 | | - it('should run renderers when requesting content update', () => { |
28 | | - dialog.renderer = sinon.spy(); |
29 | | - dialog.opened = true; |
30 | | - |
31 | | - expect(dialog.renderer.calledOnce).to.be.true; |
| 9 | + beforeEach(() => { |
| 10 | + dialog = fixtureSync('<vaadin-dialog></vaadin-dialog>'); |
| 11 | + overlay = dialog.$.overlay; |
| 12 | + }); |
32 | 13 |
|
33 | | - dialog.requestContentUpdate(); |
| 14 | + it('should render the content of renderer function when renderer function provided', () => { |
| 15 | + dialog.renderer = (root) => { |
| 16 | + const div = document.createElement('div'); |
| 17 | + div.textContent = 'The content of the dialog'; |
| 18 | + root.appendChild(div); |
| 19 | + }; |
| 20 | + dialog.opened = true; |
34 | 21 |
|
35 | | - expect(dialog.renderer.calledTwice).to.be.true; |
36 | | - }); |
| 22 | + expect(overlay.textContent).to.include('The content of the dialog'); |
| 23 | + }); |
37 | 24 |
|
38 | | - it('should not throw when requesting content update for an unupgraded dialog', () => { |
39 | | - const dialog = document.createElement('vaadin-dialog'); |
| 25 | + it('should run renderers when requesting content update', () => { |
| 26 | + dialog.renderer = sinon.spy(); |
| 27 | + dialog.opened = true; |
40 | 28 |
|
41 | | - expect(() => dialog.requestContentUpdate()).not.to.throw(); |
42 | | - }); |
| 29 | + expect(dialog.renderer.calledOnce).to.be.true; |
43 | 30 |
|
44 | | - it('should clear the content when removing the renderer', () => { |
45 | | - dialog.renderer = (root) => { |
46 | | - root.innerHTML = 'foo'; |
47 | | - }; |
48 | | - dialog.opened = true; |
| 31 | + dialog.requestContentUpdate(); |
49 | 32 |
|
50 | | - expect(overlay.textContent).to.equal('foo'); |
| 33 | + expect(dialog.renderer.calledTwice).to.be.true; |
| 34 | + }); |
51 | 35 |
|
52 | | - dialog.renderer = null; |
| 36 | + it('should not throw when requesting content update for an unupgraded dialog', () => { |
| 37 | + const dialog = document.createElement('vaadin-dialog'); |
53 | 38 |
|
54 | | - expect(overlay.textContent).to.equal(''); |
55 | | - }); |
| 39 | + expect(() => dialog.requestContentUpdate()).not.to.throw(); |
56 | 40 | }); |
57 | 41 |
|
58 | | - describe('with template', () => { |
59 | | - let dialog, overlay; |
| 42 | + it('should clear the content when removing the renderer', () => { |
| 43 | + dialog.renderer = (root) => { |
| 44 | + root.innerHTML = 'foo'; |
| 45 | + }; |
| 46 | + dialog.opened = true; |
| 47 | + |
| 48 | + expect(overlay.textContent).to.equal('foo'); |
60 | 49 |
|
61 | | - beforeEach(() => { |
62 | | - dialog = fixtureSync(` |
63 | | - <vaadin-dialog> |
64 | | - <template>foo</template> |
65 | | - </vaadin-dialog> |
66 | | - `); |
67 | | - overlay = dialog.$.overlay; |
68 | | - }); |
| 50 | + dialog.renderer = null; |
69 | 51 |
|
70 | | - it('should render the template', () => { |
71 | | - dialog.opened = true; |
72 | | - expect(overlay.textContent).to.equal('foo'); |
73 | | - }); |
| 52 | + expect(overlay.textContent).to.equal(''); |
74 | 53 | }); |
75 | 54 | }); |
0 commit comments