Skip to content

Commit 65776c5

Browse files
committed
refactor: frontend CI pipeline and tests for AuthorImage component
1 parent 14ae0d1 commit 65776c5

File tree

4 files changed

+52
-59
lines changed

4 files changed

+52
-59
lines changed

.github/workflows/frontend.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ jobs:
2323
node-version: 18
2424
cache: "npm"
2525

26-
- name: Install dependencies
27-
run: npm ci
26+
- name: Clean node_modules and lockfile (workaround for Rollup native bindings)
27+
run: rm -rf node_modules package-lock.json
28+
29+
- name: Reinstall fresh dependencies
30+
run: npm install
2831

2932
- name: Run tests
3033
run: npm run test
Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
1-
import { expect, describe, it, vitest } from "vitest";
2-
1+
import { render, screen } from "@testing-library/react";
2+
import { expect, describe, it } from "vitest";
33
import React from "react";
4-
import { render } from "@testing-library/react";
54

65
import AuthorImage from "../../js/templates/AuthorImage";
7-
import defaultImage from "../../images/author_default.png";
8-
9-
describe("Author image component", () => {
10-
it("renders", () => {
11-
const result = render(
12-
<AuthorImage url="http://pictures.org/link-to-author" />
13-
);
146

15-
expect(result.container.childNodes.length).toBe(1);
16-
});
17-
18-
it("renders with correct link", () => {
19-
const LINK = "https://custom-link.com/12345";
7+
describe("AuthorImage Component", () => {
8+
it("renders with the provided URL", () => {
9+
render(<AuthorImage url="https://example.com/12345" />);
2010

21-
const result = render(<AuthorImage url={LINK} />);
11+
const imageLink = screen.getByRole("link", { name: /author image/i });
12+
expect(imageLink).toHaveAttribute("href", "https://example.com/12345");
2213

23-
expect(
24-
result.container.querySelector("#author_image_link").getAttribute("href")
25-
).toEqual(LINK);
26-
});
27-
28-
it("renders with correct image", () => {
29-
const LINK = "https://custom-link.com/12345";
30-
31-
const result = render(<AuthorImage url={LINK} />);
32-
33-
expect(
34-
result.container.querySelector("#author_image").getAttribute("style")
35-
).toContain(`background-image: url(${LINK})`);
14+
const imageDiv = screen.getByRole("img");
15+
expect(imageDiv).toHaveStyle(
16+
"background-image: url(https://example.com/12345)"
17+
);
3618
});
3719

38-
it("renders with correct default image", () => {
39-
const LINK = undefined;
40-
const EXPECTED_LINK = defaultImage;
20+
it("renders with the default image if no URL is provided", () => {
21+
render(<AuthorImage />); // No URL passed
4122

42-
const result = render(<AuthorImage url={LINK} />);
23+
const imageLink = screen.getByRole("link", { name: /author image/i });
24+
expect(imageLink).toHaveAttribute(
25+
"href",
26+
expect.stringContaining("author_default.png")
27+
);
4328

44-
expect(
45-
result.container.querySelector("#author_image").getAttribute("style")
46-
).toContain(`background-image: url(${EXPECTED_LINK})`);
29+
const imageDiv = screen.getByRole("img");
30+
expect(imageDiv).toHaveStyle(
31+
'background-image: url("/vis/images/author_default.png")'
32+
); // Adjust the path if needed
4733
});
4834
});
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1-
import { render, screen } from '@testing-library/react';
2-
import { expect, describe, it } from 'vitest';
3-
import React from 'react';
1+
// vis/test/component/authorimage.test.jsx
2+
import { render, screen } from "@testing-library/react";
3+
import { expect, describe, it } from "vitest";
4+
import React from "react";
5+
import AuthorImage from "../../js/templates/AuthorImage";
46

5-
import AuthorImage from '../../js/templates/AuthorImage';
6-
7-
describe('AuthorImage Component', () => {
8-
it('renders with the provided URL', () => {
7+
describe("AuthorImage Component", () => {
8+
it("renders with the provided URL", () => {
99
render(<AuthorImage url="https://example.com/12345" />);
10-
11-
const imageLink = screen.getByRole('link', { name: /author image/i });
12-
expect(imageLink).toHaveAttribute('href', 'https://example.com/12345');
13-
14-
const imageDiv = screen.getByRole('img');
15-
expect(imageDiv).toHaveStyle('background-image: url(https://example.com/12345)');
10+
11+
const imageLink = screen.getByRole("link", { name: /author image/i });
12+
expect(imageLink).toHaveAttribute("href", "https://example.com/12345");
13+
14+
const imageDiv = screen.getByRole("img");
15+
expect(imageDiv).toHaveStyle(
16+
'background-image: url("https://example.com/12345")'
17+
);
1618
});
1719

18-
it('renders with the default image if no URL is provided', () => {
19-
render(<AuthorImage />); // No URL passed
20+
it("renders with the default image if no URL is provided", () => {
21+
render(<AuthorImage />);
2022

21-
const imageLink = screen.getByRole('link', { name: /author image/i });
22-
expect(imageLink).toHaveAttribute('href', expect.stringContaining('author_default.png'));
23+
const imageLink = screen.getByRole("link", { name: /author image/i });
24+
expect(imageLink).toHaveAttribute("href");
25+
expect(imageLink.getAttribute("href")).toContain("author_default.png");
2326

24-
const imageDiv = screen.getByRole('img');
25-
expect(imageDiv).toHaveStyle('background-image: url(/vis/images/author_default.png)'); // Adjust the path if needed
27+
const imageDiv = screen.getByRole("img");
28+
expect(imageDiv).toHaveStyle(
29+
'background-image: url("/vis/images/author_default.png")'
30+
);
2631
});
27-
});
32+
});

webpack.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require("path");
2-
32
const { ProvidePlugin } = require("webpack");
43
const HtmlWebpackPlugin = require("html-webpack-plugin");
54
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

0 commit comments

Comments
 (0)