go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/common/tools/markdown/plugins/crbug_link.test.ts (about)

     1  // Copyright 2020 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { fixture } from '@open-wc/testing-helpers';
    16  import markdownIt from 'markdown-it';
    17  
    18  import { crbugLink } from './crbug_link';
    19  
    20  const crbugLinks = `
    21  crbug/123 crbug.com/234 not a link CRBUG.COM/345
    22  crbug/proj/456 crbug/proj/657not_a_link
    23  `;
    24  
    25  const md = markdownIt('zero', { linkify: true })
    26    .enable('linkify')
    27    .use(crbugLink);
    28  
    29  describe('crbug_link', () => {
    30    test('can render links correctly', async () => {
    31      const ele = await fixture(md.render(crbugLinks));
    32  
    33      const anchors = ele.querySelectorAll('a');
    34      expect(anchors.length).toStrictEqual(4);
    35  
    36      const anchor1 = anchors.item(0);
    37      expect(anchor1.href).toStrictEqual('https://crbug.com/123');
    38      expect(anchor1.text).toStrictEqual('crbug/123');
    39  
    40      const anchor2 = anchors.item(1);
    41      expect(anchor2.href).toStrictEqual('https://crbug.com/234');
    42      expect(anchor2.text).toStrictEqual('crbug.com/234');
    43  
    44      const anchor3 = anchors.item(2);
    45      expect(anchor3.href).toStrictEqual('https://crbug.com/345');
    46      expect(anchor3.text).toStrictEqual('CRBUG.COM/345');
    47  
    48      const anchor4 = anchors.item(3);
    49      expect(anchor4.href).toStrictEqual('https://crbug.com/proj/456');
    50      expect(anchor4.text).toStrictEqual('crbug/proj/456');
    51    });
    52  });