1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Adding HelmChartIcon tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-03-28 09:46:53 +03:00
parent 1deb988339
commit b569ab1be0

View File

@ -0,0 +1,56 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { HelmChartIcon } from '../icon';
const mainImageSrc = 'https://example.com/main-picture.jpg';
const mainPngImageSrc = 'https://example.com/main-picture.png';
const invalidImageSrc = 'file://invalid-image-url.png';
const svgImageSrc = 'https://example.com/main-picture.svg';
describe('HelmChartIcon', () => {
it('renders the placeholder image by default', () => {
render(<HelmChartIcon />);
const imageContainer = screen.getByTestId('image-container');
expect(imageContainer.style.backgroundImage).toContain("data:image/svg+xml");
});
it("renders img tag when image url is valid", () => {
render(<HelmChartIcon imageUrl={mainImageSrc} />);
const mainImage = screen.getByRole<HTMLImageElement>('img');
expect(mainImage).toBeInTheDocument();
});
it("renders jpg image when its loaded", () => {
render(<HelmChartIcon imageUrl={mainImageSrc} />);
const imageContainer = screen.getByTestId('image-container');
const mainImage = screen.getByRole<HTMLImageElement>('img');
mainImage.dispatchEvent(new Event('load'));
expect(imageContainer.style.backgroundImage).toBe('url(https://example.com/main-picture.jpg)');
})
it("renders png image when its loaded", () => {
render(<HelmChartIcon imageUrl={mainPngImageSrc} />);
const imageContainer = screen.getByTestId('image-container');
const mainImage = screen.getByRole<HTMLImageElement>('img');
mainImage.dispatchEvent(new Event('load'));
expect(imageContainer.style.backgroundImage).toBe('url(https://example.com/main-picture.png)');
})
it("does not render invalid image url", () => {
render(<HelmChartIcon imageUrl={invalidImageSrc} />);
const mainImage = screen.queryByRole<HTMLImageElement>('img');
expect(mainImage).not.toBeInTheDocument();
})
it("does not render svg image", () => {
render(<HelmChartIcon imageUrl={svgImageSrc} />);
const mainImage = screen.queryByRole<HTMLImageElement>('img');
expect(mainImage).not.toBeInTheDocument();
})
});