github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/components/test/test-runs.html (about) 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <script src="../../node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script> 6 <script src="../../node_modules/wct-browser-legacy/browser.js"></script> 7 8 <script type="module"> 9 import { TestRunsBase } from '../test-runs.js'; 10 window.customElements.define(TestRunsBase.is, TestRunsBase); 11 </script> 12 </head> 13 <body> 14 <test-fixture id="wpt-results-base-fixture"> 15 <template> 16 <wpt-results-base aligned></wpt-results-base> 17 </template> 18 </test-fixture> 19 <script type="module"> 20 import { waitingOn, TEST_RUNS_DATA } from './util/helpers.js'; 21 import { TestRunsBase } from '../test-runs.js'; 22 import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js'; 23 24 suite('TestRunsBase', () => { 25 let sandbox; 26 27 setup(() => { 28 sandbox = sinon.sandbox.create(); 29 sandbox.stub(window, 'fetch', () => Promise.resolve(new Response(JSON.stringify(TEST_RUNS_DATA)))); 30 }); 31 32 teardown(() => { 33 sandbox.restore(); 34 }); 35 36 test('instanceof Polymer.Element', () => { 37 assert.isTrue(new TestRunsBase() instanceof PolymerElement); 38 assert.isTrue(document.createElement('wpt-results-base') instanceof PolymerElement); 39 }); 40 41 suite('static get is()', () => { 42 test('wpt-results-base', () => { 43 assert.equal(TestRunsBase.is, 'wpt-results-base'); 44 }); 45 }); 46 47 suite('static get properties()', () => { 48 test('testRuns', () => { 49 assert.property(TestRunsBase.properties, 'testRuns'); 50 assert.property(TestRunsBase.properties.testRuns, 'type'); 51 assert.equal(TestRunsBase.properties.testRuns.type, Array); 52 }); 53 }); 54 55 suite('TestRunsBase.prototype.*', () => { 56 suite('async loadRuns()', () => { 57 let wrbf; 58 59 setup(() => { 60 wrbf = fixture('wpt-results-base-fixture'); 61 wrbf.loadRuns(); 62 }); 63 64 teardown(() => { 65 sandbox.reset(); 66 }); 67 68 test('calls window.fetch(...)', () => { 69 return waitingOn(() => window.fetch.called) 70 .then(() => { 71 assert.equal(window.fetch.callCount, 1); 72 assert.equal(window.fetch.firstCall.args[0], '/api/runs?aligned'); 73 }); 74 }); 75 76 test('populates testRuns from fetch', () => { 77 assert.equal(wrbf.testRuns, null); 78 return waitingOn(() => wrbf.testRuns && wrbf.testRuns.length) 79 .then(() => { 80 assert.equal(wrbf.testRuns.length, 4); 81 for (const i in wrbf.testRuns) { 82 expect(wrbf.testRuns[i]).to.deep.equal(TEST_RUNS_DATA[i]); 83 } 84 }); 85 }); 86 }); 87 }); 88 }); 89 </script> 90 </body> 91 </html>