Skip to content

Commit

Permalink
🎨 format code for consistency with new biome config
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-schneider committed Nov 22, 2024
1 parent 453691f commit 420a2ee
Show file tree
Hide file tree
Showing 354 changed files with 13,656 additions and 13,666 deletions.
34 changes: 17 additions & 17 deletions apps/website/__mocks__/globals-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ import { vi } from "vitest";

// Mock implementation of ResizeObserver
const ResizeObserverMock = vi.fn(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));

// Stub the global ResizeObserver with the mock
vi.stubGlobal("ResizeObserver", ResizeObserverMock);

// Example: Mock implementation of window.fetch
const fetchMock = vi.fn(() =>
Promise.resolve({
json: () => Promise.resolve({}),
}),
Promise.resolve({
json: () => Promise.resolve({}),
}),
);

// Stub the global fetch with the mock
vi.stubGlobal("fetch", fetchMock);

Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
writable: true,
value: vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // Deprecated
removeListener: vi.fn(), // Deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
176 changes: 88 additions & 88 deletions apps/website/__tests__/components/component-categories.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,99 @@ import { SectionsList } from "@cuicui/ui";
import { getFileContentAsString } from "#/src/utils/get-file-content-as-string";

describe("SectionsList", () => {
it("should have the correct number of sections", () => {
expect(SectionsList).toHaveLength(7);
});
it("should have the correct number of sections", () => {
expect(SectionsList).toHaveLength(7);
});

it("should have the correct section slugs in the good order", () => {
const sectionSlugs = SectionsList.map((section) => section.slug);
expect(sectionSlugs).toEqual([
"common-ui",
"application-ui",
"marketing-ui",
"other",
"hooks",
"utils",
"tools",
]);
});
it("should have the correct section slugs in the good order", () => {
const sectionSlugs = SectionsList.map((section) => section.slug);
expect(sectionSlugs).toEqual([
"common-ui",
"application-ui",
"marketing-ui",
"other",
"hooks",
"utils",
"tools",
]);
});

it("category should have componentList === null if comingSoonCategory === true", () => {
for (const section of SectionsList) {
if (section.type !== "multiple-component") {
continue;
}
//TODO: Handle the single-component test
for (const category of section.categoriesList) {
if (category.comingSoonCategory) {
expect(category.componentList).toBeNull();
expect(category.componentList).not.toBeUndefined();
}
}
}
});
it("category should have componentList === null if comingSoonCategory === true", () => {
for (const section of SectionsList) {
if (section.type !== "multiple-component") {
continue;
}
//TODO: Handle the single-component test
for (const category of section.categoriesList) {
if (category.comingSoonCategory) {
expect(category.componentList).toBeNull();
expect(category.componentList).not.toBeUndefined();
}
}
}
});

it("should not return error when reading the file code", async () => {
const testComponentCode = async (
slug: string,
variantName: string,
shouldError: boolean,
) => {
const code = await getFileContentAsString({
componentSlug: slug,
variantName,
});
const errorMessage = `Failed for component slug: ${slug}, variant: ${variantName}`;
// Get first 2 words of the code
const firstTwoWords = code.split(" ").slice(0, 2).join(" ");
if (shouldError) {
expect(firstTwoWords, errorMessage).toEqual("An error");
} else {
expect(firstTwoWords, errorMessage).not.toEqual("An error");
}
};
it("should not return error when reading the file code", async () => {
const testComponentCode = async (
slug: string,
variantName: string,
shouldError: boolean,
) => {
const code = await getFileContentAsString({
componentSlug: slug,
variantName,
});
const errorMessage = `Failed for component slug: ${slug}, variant: ${variantName}`;
// Get first 2 words of the code
const firstTwoWords = code.split(" ").slice(0, 2).join(" ");
if (shouldError) {
expect(firstTwoWords, errorMessage).toEqual("An error");
} else {
expect(firstTwoWords, errorMessage).not.toEqual("An error");
}
};

for (const section of SectionsList) {
if (section.type !== "multiple-component") {
continue;
}
for (const category of section.categoriesList) {
if (category.componentList) {
for (const component of category.componentList) {
for (const variant of component.variantList) {
// Test without error
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugPreviewFile}`,
false,
);
for (const section of SectionsList) {
if (section.type !== "multiple-component") {
continue;
}
for (const category of section.categoriesList) {
if (category.componentList) {
for (const component of category.componentList) {
for (const variant of component.variantList) {
// Test without error
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugPreviewFile}`,
false,
);

if (variant.slugComponentFile) {
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugComponentFile}`,
false,
);
}
if (variant.slugComponentFile) {
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugComponentFile}`,
false,
);
}

// Test with forced error
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugPreviewFile}error`,
true,
);
// Test with forced error
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugPreviewFile}error`,
true,
);

if (variant.slugComponentFile) {
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugComponentFile}error`,
true,
);
}
}
}
}
}
}
});
if (variant.slugComponentFile) {
await testComponentCode(
category.slug,
`${component.slug}/${variant.slugComponentFile}error`,
true,
);
}
}
}
}
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { describe, expect, it } from "vitest";
import { getFileContentAsString } from "#/src/utils/get-file-content-as-string";

describe("getFileContentAsString", () => {
it("should return the content of the file", async () => {
const code = await getFileContentAsString({
componentSlug: "badges",
variantName: "modern-simple-badges/variant1",
});
it("should return the content of the file", async () => {
const code = await getFileContentAsString({
componentSlug: "badges",
variantName: "modern-simple-badges/variant1",
});

expect(code).toEqual(`export function BadgeSimpleVariantAmber() {
expect(code).toEqual(`export function BadgeSimpleVariantAmber() {
return (
<div className="inline rounded-md bg-amber-500/15 px-2 py-0.5 text-amber-500 text-sm">
Amber badge
</div>
);
}
`);
});
});
});
46 changes: 23 additions & 23 deletions apps/website/__tests__/sidemenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import InfoMenuList from "#/src/components/navigation/info-menu-list";
const gettingStartedRegex = /getting-started$/;

vi.mock("next/navigation", () => ({
usePathname: () => {
return "/common-ui";
},
useSelectedLayoutSegments: () => [],
usePathname: () => {
return "/common-ui";
},
useSelectedLayoutSegments: () => [],
}));

describe("Sidemenu component", () => {
render(
<div>
<InfoMenuList />
<NavigationMenu />
</div>,
);
render(
<div>
<InfoMenuList />
<NavigationMenu />
</div>,
);

it("should have href attribute of the 'Contribute' element set to https://github.com/damien-schneider/cuicui", () => {
const contributeElement = screen.getByTestId("navigation-link-Contribute");
it("should have href attribute of the 'Contribute' element set to https://github.com/damien-schneider/cuicui", () => {
const contributeElement = screen.getByTestId("navigation-link-Contribute");

const hrefValue = contributeElement.getAttribute("href");
expect(hrefValue).toBe("https://github.com/damien-schneider/cuicui");
});
it("should have href attribute of the 'Getting started' element to finish by getting-started", () => {
const contributeElement = screen.getByTestId(
"navigation-link-Getting Started",
);
const hrefValue = contributeElement.getAttribute("href");
expect(hrefValue).toBe("https://github.com/damien-schneider/cuicui");
});
it("should have href attribute of the 'Getting started' element to finish by getting-started", () => {
const contributeElement = screen.getByTestId(
"navigation-link-Getting Started",
);

// Check if the href attribute of the 'Getting started' element finishes by getting-started
const hrefValue = contributeElement.getAttribute("href");
expect(hrefValue).toMatch(gettingStartedRegex);
});
// Check if the href attribute of the 'Getting started' element finishes by getting-started
const hrefValue = contributeElement.getAttribute("href");
expect(hrefValue).toMatch(gettingStartedRegex);
});
});
24 changes: 12 additions & 12 deletions apps/website/next.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
// experimental: {
// serverComponentsExternalPackages: ["shiki", "vscode-oniguruma"],
// },
transpilePackages: ["shiki", "next-mdx-remote"],
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
// experimental: {
// serverComponentsExternalPackages: ["shiki", "vscode-oniguruma"],
// },
transpilePackages: ["shiki", "next-mdx-remote"],
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
};

module.exports = nextConfig;
7 changes: 1 addition & 6 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
},
"description": "An open-source all-in-one library for building an advanced SaaS application, a personal website, or anything else with micro-interactions, advanced user experiences, and a focus on performance and code quality.",
"devDependencies": {
"@biomejs/biome": "1.9.2",
"@tailwindcss/forms": "0.5.7",
"@tailwindcss/typography": "0.5.12",
"@testing-library/dom": "10.4.0",
Expand Down Expand Up @@ -81,18 +80,14 @@
"build": "next build",
"dev": "next dev --turbo",
"start": "next start",
"format:check": "biome format --check ./src",
"format:write": "biome format --write ./src",
"generate-package-list-check": "node scripts/generate-package-list-check.js",
"lint": "next lint",
"lint-format:check": "pnpm format:check && pnpm lint",
"lint-staged": "lint-staged",
"lint:apply": "biome check --apply ./src",
"lint:check": "biome check ./src",
"lint:write-unsafe": "biome check --write --unsafe ./src",
"test": "vitest",
"test:watch": "vitest --watch",
"type-check": "tsc --noEmit"
},
"version": "0.1.2"
}
}
Loading

0 comments on commit 420a2ee

Please sign in to comment.