Skip to content

Commit

Permalink
test(icon): add tests for limel-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschmidt authored and jgroth committed Apr 4, 2024
1 parent d5caef1 commit c2c5a42
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1,184 deletions.
54 changes: 54 additions & 0 deletions src/components/icon/icon.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { E2EPage, newE2EPage } from '@stencil/core/testing';

describe('limel-icon', () => {
let page: E2EPage;

beforeEach(async () => {
page = await newE2EPage();
});

it('renders correctly with a provided icon name', async () => {
await page.setContent('<limel-icon name="unit-test"></limel-icon>');
await page.waitForChanges();

const svgElement = await page.find('limel-icon >>> svg');
expect(svgElement).toBeTruthy();
});

it('does not render an icon when name is not provided', async () => {
await page.setContent('<limel-icon></limel-icon>');
await page.waitForChanges();

const svgElement = await page.find('limel-icon >>> svg');
expect(svgElement).toBeFalsy();
});

it('updates the icon when the name prop changes', async () => {
await page.setContent('<limel-icon name="angle_left"></limel-icon>');
await page.waitForChanges();

// Get the title of the initially loaded SVG
let titleElement = await page.find('limel-icon >>> svg title');
expect(titleElement.textContent).toEqual('Angle Left');

// Update the name prop to change the icon
const element = await page.find('limel-icon');
element.setProperty('name', 'angle_right');
await page.waitForChanges();

// Get the title of the updated SVG
titleElement = await page.find('limel-icon >>> svg title');
expect(titleElement.textContent).toEqual('Angle Right');
});

it('renders with a badge when the badge and size props are provided', async () => {
await page.setContent(
'<limel-icon name="unit-test" size="small" badge></limel-icon>',
);
await page.waitForChanges();

// Note: This test assumes there is a CSS class or structure change when a badge is applied. Adjust the selector accordingly.
const badgeElement = await page.find('limel-icon[badge]');
expect(badgeElement).toBeTruthy();
});
});
Loading

0 comments on commit c2c5a42

Please sign in to comment.