github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/components/test/wpt-app.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" src="../../views/wpt-app.js"></script> 9 </head> 10 11 <body> 12 <test-fixture id="wpt-app-fixture"> 13 <template> 14 <wpt-app></wpt-app> 15 </template> 16 </test-fixture> 17 18 <script type="module"> 19 import '../../views/wpt-app.js'; 20 import { TEST_RUNS_DATA } from './util/helpers.js'; 21 22 suiteSetup(() => { 23 window.fetch = (url) => { 24 const href = url instanceof URL ? url.href : 'unknown'; 25 assert.fail('actual', 'expected', `uncaptured fetch: ${href}`); 26 }; 27 }); 28 29 suite('<wpt-app>', () => { 30 let sandbox; 31 32 setup(() => { 33 sandbox = sinon.sandbox.create(); 34 // Spoof an empty result for APIs used in this suite. 35 const captured = new RegExp('/api/(shas|versions|interop)'); 36 sandbox.stub(window, 'fetch', url => { 37 if (url === undefined) { 38 throw 'url is undefined'; 39 } 40 if (captured.test(url.pathname)) { 41 return Promise.resolve(new Response('[]')); 42 } 43 throw url.pathname; 44 }); 45 }); 46 47 teardown(() => { 48 sandbox.restore(); 49 }); 50 51 suite('WPTApp.prototype.*', () => { 52 let appFixture; 53 54 setup(() => { 55 appFixture = fixture('wpt-app-fixture'); 56 appFixture.path = '/'; 57 appFixture.testRuns = Array.from(TEST_RUNS_DATA); 58 }); 59 60 suite('computeResultsTotalsRangeMessage', () => { 61 test('absent/zero', () => { 62 appFixture.searchResults = null; 63 expect(appFixture.resultsTotalsRangeMessage).to.not.contain('0 tests'); 64 appFixture.searchResults = []; 65 expect(appFixture.resultsTotalsRangeMessage).to.not.contain('0 tests'); 66 appFixture.page = 'results'; 67 expect(appFixture.resultsTotalsRangeMessage).to.not.contain('0 tests'); 68 }); 69 70 test('single', () => { 71 appFixture.searchResults = [ 72 {test: '/abc.html', legacy_status: [{total: 1}, {total: 1}]}, 73 ]; 74 appFixture.page = 'results'; 75 expect(appFixture.resultsTotalsRangeMessage).to.not.contain('1 tests'); 76 expect(appFixture.resultsTotalsRangeMessage).to.not.contain('1 subtests'); 77 }); 78 79 test('some sum', () => { 80 appFixture.searchResults = [ 81 {test: '/abc.html', legacy_status: [{total: 1}, {total: 5}]}, 82 {test: '/def.html', legacy_status: [{total: 2}, {total: 1}]}, 83 ]; 84 appFixture.page = 'results'; 85 expect(appFixture.resultsTotalsRangeMessage).to.contain('2 tests'); 86 expect(appFixture.resultsTotalsRangeMessage).to.contain('7 subtests'); 87 }); 88 }); 89 90 suite('computePathIsRootDir ', () => { 91 test('root dir', () => { 92 assert.isTrue(appFixture.computePathIsRootDir(appFixture.path)); 93 }); 94 test('not root dir', () => { 95 assert.isFalse(appFixture.computePathIsRootDir('/a/b')); 96 }); 97 }); 98 99 suite('wpt-results', () => { 100 // Background: Test for regression in issue 3370 101 // wpt-results and wpt-permalinks are siblings in the wpt-app parent component. 102 // When wpt-results loads testRuns, it needs to push it up to the parent 103 // wpt-app via dispatchEvent. Then wpt-app can push it down to wpt-permalinks. 104 test('testRuns from child wpt-results propagates to wpt-app testRuns', () => { 105 const wptResults = appFixture.shadowRoot.querySelector('wpt-results'); 106 // Reset the testRuns 107 wptResults.testRuns = []; 108 wptResults._fireTestRunsLoadEvent(); 109 assert.equal(appFixture.testRuns.length, 0); 110 111 // Set the wptResults testRuns. This simulates when loadRuns completes. 112 // Afterwards, fire an event. 113 wptResults.testRuns = Array.from(TEST_RUNS_DATA); 114 wptResults._fireTestRunsLoadEvent(); 115 // wpt-app should have the test runs now. 116 assert.equal(appFixture.testRuns.length, 4); 117 }); 118 }); 119 }); 120 }); 121 </script> 122 </body> 123 124 </html>