github.com/web-platform-tests/wpt.fyi@v0.0.0-20240530210107-70cf978996f1/webapp/components/test/test-runs-query.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  </head>
     8  
     9  <body>
    10  <dom-module id="test-runs-query-concrete">
    11    <script type="module">
    12  import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js';
    13  import { TestRunsQuery, TestRunsUIQuery } from '../test-runs-query.js';
    14  
    15  class ConcreteType extends TestRunsQuery(PolymerElement) {}
    16  window.customElements.define('test-runs-query-concrete', ConcreteType);
    17  
    18  class ConcreteUIType extends TestRunsUIQuery(PolymerElement) {}
    19  window.customElements.define('test-runs-ui-query-concrete', ConcreteUIType);
    20  </script>
    21  </dom-module>
    22  
    23  <test-fixture id="test-runs-query-fixture">
    24    <template>
    25      <test-runs-query-concrete></test-runs-query-concrete>
    26    </template>
    27  </test-fixture>
    28  
    29  <test-fixture id="test-runs-ui-query-fixture">
    30    <template>
    31      <test-runs-ui-query-concrete></test-runs-ui-query-concrete>
    32    </template>
    33  </test-fixture>
    34  
    35    <script type="module">
    36  import { PolymerElement } from '../../node_modules/@polymer/polymer/polymer-element.js';
    37  import '../test-runs-query.js';
    38  import { DefaultProducts, Channels } from '../product-info.js';
    39  suite('TestRunsQuery', () => {
    40    let testRunsQuery, testRunsUIQuery;
    41  
    42    setup(() => {
    43      testRunsQuery = fixture('test-runs-query-fixture');
    44      testRunsUIQuery = fixture('test-runs-ui-query-fixture');
    45    });
    46  
    47    test('instanceof Polymer.Element', () => {
    48      assert.isTrue(testRunsQuery instanceof PolymerElement);
    49    });
    50  
    51    test('isDefaultProducts', () => {
    52      testRunsQuery.products = DefaultProducts.map(p => Object.assign({}, p));
    53      expect(testRunsQuery.isDefaultProducts).to.equal(true);
    54      testRunsQuery.products = DefaultProducts.slice(0, 1);
    55      expect(testRunsQuery.isDefaultProducts).to.equal(false);
    56    });
    57  
    58    suite('collapses shared channels', () => {
    59      for (const channel of Channels) {
    60        test(channel, () => {
    61          testRunsQuery.products = DefaultProducts
    62            .map(p => Object.assign({}, p, { labels: [channel] }));
    63          expect(testRunsQuery.query).to.equal(`label=${channel}`);
    64        });
    65      }
    66    });
    67  
    68    suite('expands channel labels', () => {
    69      for (const channel of Channels) {
    70        test(channel, () => {
    71          testRunsQuery.updateQueryParams({ label: [channel] });
    72          expect(testRunsQuery.products.length).to.equal(DefaultProducts.length);
    73          for (const product of testRunsQuery.products) {
    74            expect(product.labels).to.contain(channel);
    75          }
    76          expect(testRunsQuery.labels).to.not.contain(channel);
    77        });
    78      }
    79    });
    80  
    81    suite('TestRunsQuery.prototype.*', () => {
    82  
    83      const revision = '1234512345';
    84      const chrome = 'chrome';
    85      const labels = ['foo', 'bar'];
    86      const specStr = `${chrome}[${labels.join(',')}]@${revision}`;
    87      test(`parseProductSpec("${specStr}")`, () => {
    88        const parsed = testRunsQuery.parseProductSpec(specStr);
    89        assert.equal(parsed.browser_name, chrome);
    90        assert.equal(parsed.revision, revision);
    91        for (const label of labels) {
    92          expect(Array.from(parsed.labels)).to.include(label);
    93        }
    94      });
    95  
    96      const version63 = '63.0';
    97      const chrome63 = `chrome-${version63}`;
    98      test(`parseProduct(${chrome63})`, () => {
    99        const parsed = testRunsQuery.parseProduct(chrome63);
   100        assert.equal(parsed.browser_name, chrome);
   101        assert.equal(parsed.browser_version, version63);
   102      });
   103  
   104      test('no closing bracket', () => {
   105        expect(() => testRunsQuery.parseProductSpec('chrome[foo')).to.throw();
   106        expect(() => testRunsQuery.parseProductSpec('chrome[foo]')).to.not.throw();
   107      });
   108  
   109      suite('updateQueryParams', () => {
   110        test('product', () => {
   111          const params = {
   112            product: ['safari', 'safari[experimental]'],
   113          };
   114          testRunsQuery.updateQueryParams(params);
   115          expect(testRunsQuery.products[0].browser_name).to.equal('safari');
   116          expect(testRunsQuery.products[1].browser_name).to.equal('safari');
   117          expect(testRunsQuery.products[1].labels).to.contain('experimental');
   118        });
   119  
   120        test('label', () => {
   121          testRunsQuery.products = DefaultProducts
   122            .map(p => Object.assign({}, p, { labels: ['experimental'] }));
   123          for (const channel of Channels) {
   124            testRunsQuery.updateQueryParams({
   125              label: [channel],
   126            });
   127            expect(testRunsQuery.productSpecs.join(',')).to.equal(
   128              DefaultProducts
   129                .map(p => Object.assign({}, p, { labels: [channel] }))
   130                .map(p => testRunsQuery.getSpec(p))
   131                .join(',')
   132            );
   133          }
   134        });
   135      });
   136  
   137      suite('queryParams', () => {
   138        test('products', () => {
   139          testRunsQuery.products = [
   140            Object.assign({}, DefaultProducts[0], { labels: ['experimental'] }),
   141            Object.assign({}, DefaultProducts[1], { labels: ['stable'] })
   142          ];
   143          expect(testRunsQuery.queryParams.product).to.contain(
   144            `${DefaultProducts[0].browser_name}[experimental]`);
   145          expect(testRunsQuery.queryParams.product).to.contain(
   146            `${DefaultProducts[1].browser_name}[stable]`);
   147        });
   148  
   149        test('aligned', () => {
   150          testRunsQuery.aligned = true;
   151          expect(testRunsQuery.queryParams.aligned).to.be.true;
   152        });
   153  
   154        test('shas', () => {
   155          testRunsQuery.shas = ['1234567890'];
   156          testRunsQuery.aligned = true;
   157          expect(testRunsQuery.queryParams.sha).to.equal(testRunsQuery.shas);
   158          expect(testRunsQuery.queryParams.aligned).to.not.be.defined;
   159  
   160          testRunsQuery.shas = [];
   161          expect(testRunsQuery.sha).to.equal('latest');
   162        });
   163      });
   164    });
   165  
   166    suite('TestRunsUIQuery.prototype.*', () => {
   167      test('diff', () => {
   168        testRunsUIQuery.diff = true;
   169        expect(testRunsUIQuery.query).to.contain('diff');
   170  
   171        testRunsUIQuery.diff = false;
   172        expect(testRunsUIQuery.query).to.not.contain('diff');
   173      });
   174    });
   175  
   176  });
   177  </script>
   178  </body>
   179  </html>