2020-04-28 09:47:35 +00:00
|
|
|
import mocha from 'mocha';
|
|
|
|
import chai from 'chai';
|
|
|
|
|
|
|
|
import { getNode } from './node';
|
|
|
|
import Iconify from '@iconify/iconify/lib/iconify';
|
|
|
|
|
|
|
|
const expect = chai.expect;
|
|
|
|
|
|
|
|
const selector =
|
|
|
|
'span.iconify, i.iconify, span.iconify-inline, i.iconify-inline';
|
|
|
|
|
2020-08-04 15:30:24 +00:00
|
|
|
// Do not observe document.body!
|
2021-06-16 12:36:51 +00:00
|
|
|
Iconify.stopObserving(document.documentElement);
|
2020-04-28 09:47:35 +00:00
|
|
|
|
2020-08-04 15:30:24 +00:00
|
|
|
// Create node to observe
|
|
|
|
const observedNode = getNode('iconify-api');
|
|
|
|
const ignoredNode = getNode('iconify-api');
|
|
|
|
|
|
|
|
Iconify.observe(observedNode);
|
|
|
|
|
|
|
|
observedNode.innerHTML =
|
2020-12-16 09:48:50 +00:00
|
|
|
'<div><p>Testing Iconify with API (should render SVG!)</p><ul>' +
|
2020-04-28 09:47:35 +00:00
|
|
|
'<li>Inline icons:' +
|
|
|
|
' <span class="iconify-inline" data-icon="mdi:home" style="color: red; box-shadow: 0 0 2px black;"></span>' +
|
|
|
|
' <i class="iconify iconify-inline test-icon iconify--mdi-account" data-icon="mdi:account" style="vertical-align: 0;" data-flip="horizontal" aria-hidden="false"></i>' +
|
|
|
|
'</li>' +
|
|
|
|
'<li>Block icons:' +
|
|
|
|
' <i class="iconify" data-icon="mdi:account-cash" title="<Cash>!"></i>' +
|
|
|
|
' <span class="iconify" data-icon="mdi:account-box" data-inline="true" data-rotate="2" data-width="42"></span>' +
|
|
|
|
'</li>' +
|
|
|
|
'</ul></div>';
|
|
|
|
|
2020-08-04 15:30:24 +00:00
|
|
|
ignoredNode.innerHTML =
|
|
|
|
'<div>This node should not have icons! <span class="iconify-inline" data-icon="mdi:home" style="color: red; box-shadow: 0 0 2px black;"></span>';
|
|
|
|
|
|
|
|
describe('Testing Iconify object with API', () => {
|
2020-04-28 09:47:35 +00:00
|
|
|
it('Rendering icons with API', () => {
|
|
|
|
// Icons should have been replaced by now
|
2020-08-04 15:30:24 +00:00
|
|
|
let list = observedNode.querySelectorAll(selector);
|
2020-04-28 09:47:35 +00:00
|
|
|
expect(list.length).to.be.equal(0);
|
|
|
|
|
2020-08-04 15:30:24 +00:00
|
|
|
list = observedNode.querySelectorAll('svg.iconify');
|
2020-04-28 09:47:35 +00:00
|
|
|
expect(list.length).to.be.equal(4);
|
2020-08-04 15:30:24 +00:00
|
|
|
|
|
|
|
// Icons in ignored node should not have been replaced
|
|
|
|
list = ignoredNode.querySelectorAll(selector);
|
|
|
|
expect(list.length).to.be.equal(1);
|
|
|
|
|
|
|
|
list = ignoredNode.querySelectorAll('svg.iconify');
|
|
|
|
expect(list.length).to.be.equal(0);
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
|
|
|
});
|