Skip to content

Commit 671f70c

Browse files
committed
refactor: streamline imports and improve eslint configuration; enhance CI/CD workflow
1 parent eecd3ed commit 671f70c

24 files changed

Lines changed: 52 additions & 81 deletions

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"rules": {
2828
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
2929
"no-console": "off",
30-
"quotes": ["error", "double"],
30+
"quotes": ["error", "double", { "allowTemplateLiterals": true }],
3131
"semi": ["error", "always"],
3232
"react/react-in-jsx-scope": "off",
3333
"react/prop-types": "off",

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
- name: Prettier check
4545
run: npm run format:check
4646

47-
# - name: ESLint
48-
# run: npm run lint
47+
- name: ESLint
48+
run: npm run lint
4949

5050
- name: Run tests (no watch) with coverage + summary
5151
run: |

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# npm run lint
21
npm run format:check
2+
npm run lint
33
npm test

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"lint:fix": "eslint src --ext .js,.jsx --format stylish --fix",
1717
"act": "act --env-file .env.act --quiet",
1818
"prepare": "husky",
19-
"check": "npm run format:check && npm run test"
19+
"check": "npm run format:check && npm run lint && npm run test"
2020
},
2121
"repository": {
2222
"type": "git",

src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useContext, useEffect, useState } from "react";
1+
import { useContext, useEffect, useState } from "react";
22
import { ConfigProvider, theme } from "antd";
33
import Footer from "./components/Footer";
44
import CSCalendar from "./components/CSCalendar";

src/__tests__/App.test.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,31 @@ jest.mock("../components/CSCalendar", () => {
2929
const React = require("react");
3030
return function MockCSCalendar(props) {
3131
mockCsCalendar(props);
32+
33+
const { setAnnouncementData } = props;
34+
3235
React.useEffect(() => {
33-
props.setAnnouncementData({
36+
setAnnouncementData({
3437
startWeekDate: "2025/01/13",
3538
endWeekDate: "2025/01/20",
3639
firstEventDate: "2025/01/15",
3740
secondEventDate: "2025/01/19",
3841
firstEvent: "First",
3942
secondEvent: "Second",
4043
});
41-
}, [props.setAnnouncementData]);
44+
}, [setAnnouncementData]);
45+
4246
return <div data-testid="calendar" />;
4347
};
4448
});
4549

46-
jest.mock("../components/Footer", () => () => (
47-
<div data-testid="footer">footer</div>
48-
));
50+
jest.mock("../components/Footer", () => {
51+
const MockFooter = () => <div data-testid="footer">footer</div>;
52+
53+
MockFooter.displayName = "MockFooter";
54+
55+
return MockFooter;
56+
});
4957

5058
jest.mock("../components/FloatButtonSection", () => {
5159
return function MockFloatButtonSection({ setIsModalOpen }) {

src/__tests__/components/AnnouncementModule.test.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jest.mock("antd", () => {
3737
<textarea value={value} onChange={onChange} {...props} />
3838
),
3939
},
40-
Spin: ({ size, className }) => (
40+
Spin: ({ _size, className }) => (
4141
<div data-testid="spinner" className={className}></div>
4242
),
4343
Flex: ({ children, ...props }) => (
@@ -80,7 +80,7 @@ describe("AnnouncementModule", () => {
8080
<AnnouncementModule {...defaultProps} isModalOpen={false} />
8181
);
8282
expect(
83-
container.querySelector('[data-testid="modal"]')
83+
container.querySelector(`[data-testid="modal"]`)
8484
).not.toBeInTheDocument();
8585
});
8686

@@ -384,7 +384,6 @@ describe("AnnouncementModule", () => {
384384
/>
385385
);
386386

387-
const buttons = screen.getAllByRole("button");
388387
const copyButton = screen.getByText("کپی پیام");
389388
const backButton = screen.getByText("بازگشت");
390389

src/__tests__/components/CSCalendar.test.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
2+
import { render, fireEvent, waitFor } from "@testing-library/react";
33
import { act } from "react-dom/test-utils";
44
import dayjs from "dayjs";
55
import moment from "jalali-moment";
@@ -22,9 +22,13 @@ jest.mock("../../components/EventPopup", () => {
2222
};
2323
});
2424

25-
jest.mock("../../components/CalendarIntro", () => () => (
26-
<div data-testid="calendar-intro" />
27-
));
25+
jest.mock("../../components/CalendarIntro", () => {
26+
const MockCalendarIntro = () => <div data-testid="calendar-intro" />;
27+
28+
MockCalendarIntro.displayName = "MockCalendarIntro";
29+
30+
return MockCalendarIntro;
31+
});
2832

2933
jest.mock("antd", () => {
3034
const React = require("react");
@@ -45,10 +49,14 @@ jest.mock("antd", () => {
4549
{children}
4650
</select>
4751
);
48-
Select.Option = ({ value, children }) => (
52+
const SelectOption = ({ value, children }) => (
4953
<option value={value}>{children}</option>
5054
);
5155

56+
SelectOption.displayName = "Select.Option";
57+
58+
Select.Option = SelectOption;
59+
5260
const Tag = ({ children, className, color }) => (
5361
<div className={className} data-color={color}>
5462
{children}

src/__tests__/components/EventPopup.test.jsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ describe("EventPopup", () => {
103103
expect(screen.getByText("تاریخ شمسی")).toBeInTheDocument();
104104
expect(screen.getByText("تاریخ میلادی")).toBeInTheDocument();
105105
expect(container.querySelector(".event-popup__link--primary")).toBe(
106-
container.querySelector('a[href="https://example.com/session"]')
106+
container.querySelector(`a[href="https://example.com/session"]`)
107107
);
108108
expect(
109-
container.querySelector('a[href="https://example.com/resource"]')
109+
container.querySelector(`a[href="https://example.com/resource"]`)
110110
).toBeInTheDocument();
111111

112112
const dot = container.querySelector(".event-popup__color-dot");
@@ -220,21 +220,4 @@ describe("EventPopup", () => {
220220
fireEvent.mouseDown(document.body);
221221
expect(onClose).toHaveBeenCalled();
222222
});
223-
224-
it("falls back to event title when full name is missing", () => {
225-
mockCalendarCreator.mockClear();
226-
const event = { ...baseEvent, fullName: undefined };
227-
const { getByText } = renderPopup({
228-
visible: true,
229-
anchorRect,
230-
date: dayjs("2025-01-14"),
231-
event,
232-
onClose: jest.fn(),
233-
});
234-
235-
expect(screen.getAllByText(event.title).length).toBeGreaterThan(0);
236-
expect(mockCalendarCreator).toHaveBeenCalledWith(
237-
expect.objectContaining({ eventText: event.title })
238-
);
239-
});
240223
});

src/__tests__/components/FloatButtonSection.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe("FloatButtonSection", () => {
208208

209209
it("should handle theme toggle with transition", () => {
210210
const setIsModalOpen = jest.fn();
211-
const { getAllByTestId, container } = render(
211+
const { getAllByTestId } = render(
212212
<FloatButtonSection setIsModalOpen={setIsModalOpen} />
213213
);
214214
const buttons = getAllByTestId("float-button");

0 commit comments

Comments
 (0)