code.gitea.io/gitea@v1.22.3/web_src/js/svg.test.js (about)

     1  import {svg, SvgIcon, svgParseOuterInner} from './svg.js';
     2  import {createApp, h} from 'vue';
     3  
     4  test('svg', () => {
     5    expect(svg('octicon-repo')).toMatch(/^<svg/);
     6    expect(svg('octicon-repo', 16)).toContain('width="16"');
     7    expect(svg('octicon-repo', 32)).toContain('width="32"');
     8  });
     9  
    10  test('svgParseOuterInner', () => {
    11    const {svgOuter, svgInnerHtml} = svgParseOuterInner('octicon-repo');
    12    expect(svgOuter.nodeName).toMatch('svg');
    13    expect(svgOuter.classList.contains('octicon-repo')).toBeTruthy();
    14    expect(svgInnerHtml).toContain('<path');
    15  });
    16  
    17  test('SvgIcon', () => {
    18    const root = document.createElement('div');
    19    createApp({render: () => h(SvgIcon, {name: 'octicon-link', size: 24, class: 'base', className: 'extra'})}).mount(root);
    20    const node = root.firstChild;
    21    expect(node.nodeName).toEqual('svg');
    22    expect(node.getAttribute('width')).toEqual('24');
    23    expect(node.getAttribute('height')).toEqual('24');
    24    expect(node.classList.contains('octicon-link')).toBeTruthy();
    25    expect(node.classList.contains('base')).toBeTruthy();
    26    expect(node.classList.contains('extra')).toBeTruthy();
    27  });