2022-01-09 21:23:02 +00:00
|
|
|
import { promises as fs } from 'fs';
|
2021-12-11 23:26:58 +00:00
|
|
|
import { getCustomIcon } from '../lib';
|
|
|
|
|
2022-01-09 21:23:02 +00:00
|
|
|
const fixturesDir = __dirname + '/fixtures';
|
2021-12-11 23:26:58 +00:00
|
|
|
|
|
|
|
describe('Testing getCustomIcon', () => {
|
2022-01-09 20:44:48 +00:00
|
|
|
test('CustomIconLoader', async () => {
|
2022-01-09 21:23:02 +00:00
|
|
|
const svg = await fs.readFile(fixturesDir + '/circle.svg', 'utf8');
|
2022-01-09 20:44:48 +00:00
|
|
|
const result = await getCustomIcon(() => svg, 'a', 'b');
|
2021-12-11 23:26:58 +00:00
|
|
|
expect(svg).toEqual(result);
|
|
|
|
});
|
2022-01-09 20:44:48 +00:00
|
|
|
|
|
|
|
test('CustomIconLoader with transform', async () => {
|
2022-01-09 21:23:02 +00:00
|
|
|
const svg = await fs.readFile(fixturesDir + '/circle.svg', 'utf8');
|
2022-01-09 20:44:48 +00:00
|
|
|
const result = await getCustomIcon(
|
|
|
|
() => svg,
|
|
|
|
'a',
|
|
|
|
'b',
|
2022-01-10 12:43:35 +00:00
|
|
|
{
|
|
|
|
transform(icon) {
|
|
|
|
return icon.replace('<svg ', '<svg width="1em" height="1em" ');
|
|
|
|
}
|
2022-01-09 20:44:48 +00:00
|
|
|
}
|
2022-01-10 12:43:35 +00:00
|
|
|
|
2022-01-09 20:44:48 +00:00
|
|
|
);
|
2021-12-11 23:26:58 +00:00
|
|
|
expect(result && result.indexOf('width="1em"') > -1).toBeTruthy();
|
|
|
|
expect(result && result.indexOf('height="1em"') > -1).toBeTruthy();
|
|
|
|
});
|
2022-01-09 21:23:02 +00:00
|
|
|
|
|
|
|
test('Icon with XML heading', async () => {
|
|
|
|
// Intercept console.warn
|
|
|
|
let warned = false;
|
|
|
|
const warn = console.warn;
|
|
|
|
console.warn = (/*...args*/) => {
|
|
|
|
// warn.apply(this, args);
|
|
|
|
warned = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
const svg = await fs.readFile(fixturesDir + '/1f3eb.svg', 'utf8');
|
|
|
|
const result = await getCustomIcon(() => svg, 'a', 'b');
|
|
|
|
|
|
|
|
// Restore console.warn
|
|
|
|
console.warn = warn;
|
|
|
|
|
|
|
|
expect(svg).toEqual(result);
|
|
|
|
expect(warned).toEqual(true);
|
|
|
|
});
|
2021-12-11 23:26:58 +00:00
|
|
|
});
|