Skip to content

Commit

Permalink
Merge branch 'ddd-refactor-simple'
Browse files Browse the repository at this point in the history
  • Loading branch information
rare-magma committed Aug 28, 2024
2 parents cd0ee2a + 0ef4833 commit 9500448
Show file tree
Hide file tree
Showing 73 changed files with 1,133 additions and 753 deletions.
81 changes: 14 additions & 67 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,28 @@
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"recommended": true,
"a11y": {
"noAccessKey": "warn",
"noAriaUnsupportedElements": "warn",
"noBlankTarget": "warn",
"noDistractingElements": "warn",
"noHeaderScope": "warn",
"noRedundantAlt": "warn",
"noRedundantRoles": "warn",
"useAltText": "warn",
"useAnchorContent": "warn",
"useAriaActivedescendantWithTabindex": "warn",
"useAriaPropsForRole": "warn",
"useHeadingContent": "warn",
"useIframeTitle": "warn",
"useValidAnchor": "warn",
"useValidAriaProps": "warn",
"useValidAriaRole": {
"level": "warn",
"options": { "allowInvalidRoles": [], "ignoreNonDom": true }
},
"useValidAriaValues": "warn"
"all": true
},
"complexity": {
"noMultipleSpacesInRegularExpressionLiterals": "warn",
"noUselessConstructor": "warn",
"noUselessLabel": "warn",
"noUselessLoneBlockStatements": "warn",
"noUselessRename": "warn",
"noWith": "warn"
"noExcessiveCognitiveComplexity": "error"
},
"correctness": {
"noConstAssign": "warn",
"noEmptyCharacterClassInRegex": "warn",
"noEmptyPattern": "warn",
"noGlobalObjectCalls": "warn",
"noInvalidUseBeforeDeclaration": "warn",
"noNewSymbol": "warn",
"noSelfAssign": "warn",
"noUndeclaredVariables": "error",
"noUnreachable": "warn",
"noUnreachableSuper": "warn",
"noUnusedLabels": "warn",
"noUnusedVariables": "warn",
"useArrayLiterals": "warn",
"useExhaustiveDependencies": "warn",
"useHookAtTopLevel": "error",
"useIsNan": "warn",
"useYield": "warn"
"noUnusedImports": "error",
"useArrayLiterals": "error",
"useHookAtTopLevel": "error"
},
"performance": {
"all": true
},
"security": {
"noDangerouslySetInnerHtmlWithChildren": "warn",
"noGlobalEval": "warn"
"all": true
},
"style": {
"noCommaOperator": "warn",
"noDefaultExport": "error",
"noImplicitBoolean": "error",
"noRestrictedGlobals": {
"level": "error",
"options": {
Expand Down Expand Up @@ -142,27 +108,8 @@
}
},
"suspicious": {
"noAssignInExpressions": "warn",
"noCatchAssign": "warn",
"noCommentText": "warn",
"noConfusingLabels": "warn",
"noControlCharactersInRegex": "warn",
"noDoubleEquals": "warn",
"noDuplicateCase": "warn",
"noDuplicateClassMembers": "warn",
"noDuplicateJsxProps": "warn",
"noDuplicateObjectKeys": "warn",
"noDuplicateParameters": "warn",
"noFallthroughSwitchClause": "warn",
"noFunctionAssign": "warn",
"noGlobalAssign": "warn",
"noLabelVar": "warn",
"noRedeclare": "warn",
"noSelfCompare": "warn",
"noShadowRestrictedNames": "warn",
"noUnsafeNegation": "warn",
"useGetterReturn": "warn",
"useValidTypeof": "warn"
"noEmptyBlockStatements": "error",
"useAwait": "error"
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions e2e/settingsHappyPath.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "node:fs";
import { expect, test } from "@playwright/test";

test("should complete the settings happy path", async ({ page, isMobile }) => {
Expand Down Expand Up @@ -64,7 +64,7 @@ test("should complete the settings happy path", async ({ page, isMobile }) => {
page.getByLabel("export budget as json").click(),
]);

let downloadError = await jsonDownload.failure();
const downloadError = await jsonDownload.failure();
if (downloadError !== null) {
console.log("Error on download:", downloadError);
throw new Error(downloadError);
Expand All @@ -82,8 +82,8 @@ test("should complete the settings happy path", async ({ page, isMobile }) => {
.getByTestId("import-form-control")
.setInputFiles("./docs/guitos-sample.json");

await expect(page.getByLabel("go to older budget")).toBeVisible();
await page.getByLabel("go to older budget").click();
await expect(page.getByLabel("go to newer budget")).toBeVisible();
await page.getByLabel("go to newer budget").click();

if (isMobile) {
await page.getByLabel("Toggle navigation").click();
Expand All @@ -93,7 +93,7 @@ test("should complete the settings happy path", async ({ page, isMobile }) => {
page.getByRole("combobox", { name: "search in budgets" }),
).toBeVisible();

await expect(page.getByLabel("budget name")).toHaveValue("2023-08");
await expect(page.getByLabel("budget name")).toHaveValue("2023-07");

await page.close();
});
2 changes: 2 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { defineConfig, devices } from "@playwright/test";
/**
* See https://playwright.dev/docs/test-configuration.
*/

// biome-ignore lint/style/noDefaultExport: <explanation>
export default defineConfig({
timeout: 11 * 1000, // 11 seconds
testDir: "./e2e",
Expand Down
20 changes: 13 additions & 7 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { act, cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import App from "./App";
import { App } from "./App";
import { budgetsDB, calcHistDB, optionsDB } from "./db";
import {
budgetContextSpy,
Expand All @@ -28,7 +28,9 @@ describe("App", () => {
expect(optionsDB.config("storeName")).toBe("options");
expect(calcHistDB.config("name")).toBe("guitos");
expect(calcHistDB.config("storeName")).toBe("calcHistDB");
await expect(budgetsDB.getItem(testBudget.id)).resolves.toBeNull();
await expect(
budgetsDB.getItem(testBudget.id.toString()),
).resolves.toBeNull();
});

it("shows new budget when clicking new button", async () => {
Expand All @@ -42,15 +44,17 @@ describe("App", () => {
expect(await screen.findByText("Statistics")).toBeInTheDocument();
expect(await screen.findByText("Revenue")).toBeInTheDocument();
expect(await screen.findByText("Expenses")).toBeInTheDocument();
await expect(budgetsDB.getItem(testBudget.id)).resolves.toEqual(testBudget);
await expect(budgetsDB.getItem(testBudget.id.toString())).resolves.toEqual(
testBudget,
);
});

it.skip("deletes budget when clicking delete button", async () => {
render(comp);
await act(async () => {
await expect(budgetsDB.getItem(testBudget.id)).resolves.toEqual(
testBudget,
);
await expect(
budgetsDB.getItem(testBudget.id.toString()),
).resolves.toEqual(testBudget);
});

const newButton = await screen.findAllByRole("button", {
Expand All @@ -68,7 +72,9 @@ describe("App", () => {
);

await act(async () => {
await expect(budgetsDB.getItem(testBudget.id)).resolves.toBeNull();
await expect(
budgetsDB.getItem(testBudget.id.toString()),
).resolves.toBeNull();
});
});
});
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BudgetProvider } from "./context/BudgetContext";
import { ConfigProvider } from "./context/ConfigContext";
import { GeneralProvider } from "./context/GeneralContext";

export default function App() {
export function App() {
return (
<GeneralProvider>
<ConfigProvider>
Expand Down
34 changes: 0 additions & 34 deletions src/components/Budget/Budget.test.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/components/Budget/Budget.ts

This file was deleted.

11 changes: 6 additions & 5 deletions src/components/Budget/BudgetPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { act } from "react-dom/test-utils";
import { BrowserRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
import { budgetsDB } from "../../db";
import {
Expand All @@ -14,7 +15,6 @@ import {
undoMock,
} from "../../setupTests";
import { BudgetPage } from "./BudgetPage";
import { BrowserRouter } from "react-router-dom";

describe("BudgetPage", () => {
const comp = (
Expand Down Expand Up @@ -45,18 +45,19 @@ describe("BudgetPage", () => {

it("removes budget when clicking on delete budget button", async () => {
render(comp);
await expect(budgetsDB.getItem(testBudget.id)).resolves.toEqual(testBudget);
const deleteButton = await screen.findAllByRole("button", {
name: "delete budget",
});
await userEvent.click(deleteButton[0]);
await userEvent.click(
await screen.findByRole("button", { name: "confirm budget deletion" }),
);
await expect(budgetsDB.getItem(testBudget.id)).resolves.toBeNull();
await expect(
budgetsDB.getItem(testBudget.id.toString()),
).resolves.toBeNull();
});

it("clones budget when clicking on clone budget button", async () => {
it.skip("clones budget when clicking on clone budget button", async () => {
render(comp);
const newButton = await screen.findAllByRole("button", {
name: "new budget",
Expand All @@ -70,7 +71,7 @@ describe("BudgetPage", () => {
expect(setBudgetMock).toHaveBeenCalledWith(testBudgetClone, true);
});

it("responds to clone budget keyboard shortcut", async () => {
it.skip("responds to clone budget keyboard shortcut", async () => {
render(comp);
const newButton = await screen.findAllByRole("button", {
name: "new budget",
Expand Down
10 changes: 6 additions & 4 deletions src/components/Budget/BudgetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useHotkeys } from "react-hotkeys-hook";
import { useParams } from "react-router-dom";
import { useBudget } from "../../context/BudgetContext";
import { useGeneralContext } from "../../context/GeneralContext";
import type { Budget } from "../../guitos/domain/budget";
import { useDB } from "../../hooks/useDB";
import { createBudgetNameList } from "../../utils";
import { ErrorModal } from "../ErrorModal/ErrorModal";
Expand All @@ -12,7 +13,6 @@ import { Loading } from "../Loading/Loading";
import { NavBar } from "../NavBar/NavBar";
import { Notification } from "../Notification/Notification";
import { StatCard } from "../StatCard/StatCard";
import { Budget } from "./Budget";
// import { useWhatChanged } from "@simbathesailor/use-what-changed";

const ChartsPage = lazy(() => import("../ChartsPage/ChartsPage"));
Expand Down Expand Up @@ -103,7 +103,7 @@ export function BudgetPage() {

return (
<Container
fluid
fluid={true}
style={{ zIndex: 1 }}
key={`${budget?.id}-${needReload}`}
role="main"
Expand All @@ -113,9 +113,11 @@ export function BudgetPage() {
position={"bottom-center"}
style={{ zIndex: 100 }}
>
{notifications.map((notification, i) => {
{notifications.map((notification) => {
return (
notification && <Notification key={i} notification={notification} />
notification && (
<Notification key={notification.id} notification={notification} />
)
);
})}
</ToastContainer>
Expand Down
19 changes: 0 additions & 19 deletions src/components/Budget/CsvItem.test.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/Budget/CsvItem.ts

This file was deleted.

Loading

0 comments on commit 9500448

Please sign in to comment.