mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-29 23:41:16 -07:00
Chore: full react hooks eslint compliance (#7040)
This commit is contained in:
@@ -3,8 +3,9 @@ import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next/pages";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import withWidgetFields from "utils/widget-fields";
|
||||
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
const DEFAULT_FIELDS = ["activeSubscriptions", "nextRenewingSubscription", "thisMonthlyCost", "nextMonthlyCost"];
|
||||
|
||||
const todayDate = new Date();
|
||||
function toApiMonthYear(offset = 0) {
|
||||
@@ -16,16 +17,11 @@ function toApiMonthYear(offset = 0) {
|
||||
};
|
||||
}
|
||||
|
||||
export default function Component({ service }) {
|
||||
export default function Component({ service: configuredService }) {
|
||||
const { t } = useTranslation();
|
||||
const service = withWidgetFields(configuredService, DEFAULT_FIELDS);
|
||||
const { widget } = service;
|
||||
|
||||
if (!widget.fields) {
|
||||
widget.fields = ["activeSubscriptions", "nextRenewingSubscription", "thisMonthlyCost", "nextMonthlyCost"];
|
||||
} else if (widget.fields?.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
const subscriptionsEndPoint =
|
||||
widget.fields.includes("activeSubscriptions") || widget.fields.includes("nextRenewingSubscription")
|
||||
? "get_subscriptions"
|
||||
|
||||
@@ -22,12 +22,7 @@ describe("widgets/wallos/component", () => {
|
||||
const service = { widget: { type: "wallos" } };
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual([
|
||||
"activeSubscriptions",
|
||||
"nextRenewingSubscription",
|
||||
"thisMonthlyCost",
|
||||
"nextMonthlyCost",
|
||||
]);
|
||||
expect(service.widget.fields).toBeUndefined();
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
||||
expect(screen.getByText("wallos.activeSubscriptions")).toBeInTheDocument();
|
||||
expect(screen.getByText("wallos.nextRenewingSubscription")).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user