mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Linter fixes
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
0094d4bcfa
commit
cc193ae30c
@ -1,56 +1,64 @@
|
|||||||
import React from 'react';
|
/**
|
||||||
import { render, screen } from '@testing-library/react';
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
import { HelmChartIcon } from '../icon';
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import React from "react";
|
||||||
|
import { render, screen } from "@testing-library/react";
|
||||||
|
import { HelmChartIcon } from "../icon";
|
||||||
|
|
||||||
const mainImageSrc = 'https://example.com/main-picture.jpg';
|
const mainImageSrc = "https://example.com/main-picture.jpg";
|
||||||
const mainPngImageSrc = 'https://example.com/main-picture.png';
|
const mainPngImageSrc = "https://example.com/main-picture.png";
|
||||||
const invalidImageSrc = 'file://invalid-image-url.png';
|
const invalidImageSrc = "file://invalid-image-url.png";
|
||||||
const svgImageSrc = 'https://example.com/main-picture.svg';
|
const svgImageSrc = "https://example.com/main-picture.svg";
|
||||||
|
|
||||||
describe('HelmChartIcon', () => {
|
describe("HelmChartIcon", () => {
|
||||||
it('renders the placeholder image by default', () => {
|
it("renders the placeholder image by default", () => {
|
||||||
render(<HelmChartIcon />);
|
render(<HelmChartIcon />);
|
||||||
const imageContainer = screen.getByTestId('image-container');
|
const imageContainer = screen.getByTestId("image-container");
|
||||||
|
|
||||||
expect(imageContainer.style.backgroundImage).toContain("data:image/svg+xml");
|
expect(imageContainer.style.backgroundImage).toContain("data:image/svg+xml");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders img tag when image url is valid", () => {
|
it("renders img tag when image url is valid", () => {
|
||||||
render(<HelmChartIcon imageUrl={mainImageSrc} />);
|
render(<HelmChartIcon imageUrl={mainImageSrc} />);
|
||||||
const mainImage = screen.getByRole<HTMLImageElement>('img');
|
const mainImage = screen.getByRole<HTMLImageElement>("img");
|
||||||
|
|
||||||
expect(mainImage).toBeInTheDocument();
|
expect(mainImage).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders jpg image when its loaded", () => {
|
it("renders jpg image when its loaded", () => {
|
||||||
render(<HelmChartIcon imageUrl={mainImageSrc} />);
|
render(<HelmChartIcon imageUrl={mainImageSrc} />);
|
||||||
|
|
||||||
const imageContainer = screen.getByTestId('image-container');
|
const imageContainer = screen.getByTestId("image-container");
|
||||||
const mainImage = screen.getByRole<HTMLImageElement>('img');
|
const mainImage = screen.getByRole<HTMLImageElement>("img");
|
||||||
|
|
||||||
mainImage.dispatchEvent(new Event('load'));
|
mainImage.dispatchEvent(new Event("load"));
|
||||||
expect(imageContainer.style.backgroundImage).toBe('url(https://example.com/main-picture.jpg)');
|
expect(imageContainer.style.backgroundImage).toBe("url(https://example.com/main-picture.jpg)");
|
||||||
})
|
});
|
||||||
|
|
||||||
it("renders png image when its loaded", () => {
|
it("renders png image when its loaded", () => {
|
||||||
render(<HelmChartIcon imageUrl={mainPngImageSrc} />);
|
render(<HelmChartIcon imageUrl={mainPngImageSrc} />);
|
||||||
|
|
||||||
const imageContainer = screen.getByTestId('image-container');
|
const imageContainer = screen.getByTestId("image-container");
|
||||||
const mainImage = screen.getByRole<HTMLImageElement>('img');
|
const mainImage = screen.getByRole<HTMLImageElement>("img");
|
||||||
|
|
||||||
mainImage.dispatchEvent(new Event('load'));
|
mainImage.dispatchEvent(new Event("load"));
|
||||||
expect(imageContainer.style.backgroundImage).toBe('url(https://example.com/main-picture.png)');
|
expect(imageContainer.style.backgroundImage).toBe("url(https://example.com/main-picture.png)");
|
||||||
})
|
});
|
||||||
|
|
||||||
it("does not render invalid image url", () => {
|
it("does not render invalid image url", () => {
|
||||||
render(<HelmChartIcon imageUrl={invalidImageSrc} />);
|
render(<HelmChartIcon imageUrl={invalidImageSrc} />);
|
||||||
|
|
||||||
const mainImage = screen.queryByRole<HTMLImageElement>('img');
|
const mainImage = screen.queryByRole<HTMLImageElement>("img");
|
||||||
|
|
||||||
expect(mainImage).not.toBeInTheDocument();
|
expect(mainImage).not.toBeInTheDocument();
|
||||||
})
|
});
|
||||||
|
|
||||||
it("does not render svg image", () => {
|
it("does not render svg image", () => {
|
||||||
render(<HelmChartIcon imageUrl={svgImageSrc} />);
|
render(<HelmChartIcon imageUrl={svgImageSrc} />);
|
||||||
|
|
||||||
const mainImage = screen.queryByRole<HTMLImageElement>('img');
|
const mainImage = screen.queryByRole<HTMLImageElement>("img");
|
||||||
|
|
||||||
expect(mainImage).not.toBeInTheDocument();
|
expect(mainImage).not.toBeInTheDocument();
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user