Skip to content

Commit

Permalink
fix(lib): issue with unit tests and new styles and setting
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed May 9, 2024
1 parent 8fad2b9 commit a663060
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/lib/icon-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import titleIcon from './icon-title';
import config from '@app/config';
import svg from './util/svg';

describe('add', () => {
let plugin: any;

beforeEach(() => {
plugin = {
getSettings: (): any => {
return {
iconInTitlePosition: 'above',
emojiStyle: 'native',
};
},
};
});

it('should create a title icon', () => {
const parentEl = document.createElement('div');
const inlineTitleEl = document.createElement('div');
parentEl.appendChild(inlineTitleEl);

titleIcon.add({} as any, inlineTitleEl, '<svg></svg>');
titleIcon.add(plugin, inlineTitleEl, '<svg></svg>');
expect(parentEl).toMatchInlineSnapshot(`<div>
<div
class="iconize-title-icon"
style="display: block;"
style="display: block; width: var(--line-width);"
>
<svg />
</div>
Expand All @@ -26,16 +39,11 @@ describe('add', () => {
const inlineTitleEl = document.createElement('div');
parentEl.appendChild(inlineTitleEl);

titleIcon.add(
{ getSettings: () => ({ emojiStyle: 'native' }) } as any,
inlineTitleEl,
'👍',
{ fontSize: 10 },
);
titleIcon.add(plugin, inlineTitleEl, '👍', { fontSize: 10 });
expect(parentEl).toMatchInlineSnapshot(`<div>
<div
class="iconize-title-icon"
style="display: block; font-size: 10px;"
style="display: block; width: var(--line-width); font-size: 10px;"
>
👍
</div>
Expand All @@ -51,11 +59,11 @@ describe('add', () => {
parentEl.appendChild(titleIconEl);
parentEl.appendChild(inlineTitleEl);

titleIcon.add({} as any, inlineTitleEl, '<svg></svg>');
titleIcon.add(plugin, inlineTitleEl, '<svg></svg>');
expect(parentEl).toMatchInlineSnapshot(`<div>
<div
class="iconize-title-icon"
style="display: block;"
style="display: block; width: var(--line-width);"
>
<svg />
</div>
Expand All @@ -71,7 +79,7 @@ describe('add', () => {
const inlineTitleEl = document.createElement('div');
parentEl.appendChild(inlineTitleEl);

titleIcon.add({} as any, inlineTitleEl, '<svg></svg>', { fontSize: 10 });
titleIcon.add(plugin, inlineTitleEl, '<svg></svg>', { fontSize: 10 });
expect(setFontSize).toBeCalledTimes(1);
expect(setFontSize).toHaveBeenCalledWith('<svg></svg>', 10);

Expand Down

0 comments on commit a663060

Please sign in to comment.