Skip to content

Commit

Permalink
🎨 format code for consistency across all the monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-schneider committed Nov 23, 2024
1 parent 34f4e7c commit 9122ea3
Show file tree
Hide file tree
Showing 347 changed files with 13,230 additions and 13,242 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>
);
}
`);
});
});
});
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;
Loading

0 comments on commit 9122ea3

Please sign in to comment.