Skip to content

Commit 0665a5a

Browse files
rajat1saxenaRajat
andauthored
Test suite for Queue (#673)
* Test suite for Queue * CodeQL fixes --------- Co-authored-by: Rajat <hi@rajatsaxena.dev>
1 parent 9ad49bb commit 0665a5a

24 files changed

Lines changed: 2200 additions & 668 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Re-export only renderEmailToHtml and types to avoid loading EmailEditor and its dependencies
2+
// This allows us to test the real renderEmailToHtml without loading React UI components
3+
export type {
4+
Email,
5+
EmailBlock,
6+
EmailMeta,
7+
EmailStyle,
8+
BlockComponent,
9+
} from "../../../../packages/email-editor/src/types/email-editor";
10+
export type { BlockRegistry } from "../../../../packages/email-editor/src/types/block-registry";
11+
export { renderEmailToHtml } from "../../../../packages/email-editor/src/lib/email-renderer";
12+
export { defaultEmail } from "../../../../packages/email-editor/src/lib/default-email";

apps/queue/__mocks__/css.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock for CSS imports
2+
export default {};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock for lucide-react icons
2+
export const Plus = () => null;

apps/queue/__mocks__/nanoid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const nanoid = jest.fn(() => "mock-nanoid-id");

apps/queue/__mocks__/radix-ui.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mock for Radix UI components
2+
export const Popover = { Root: ({ children }: any) => children };
3+
export const PopoverContent = ({ children }: any) => children;
4+
export const PopoverTrigger = ({ children }: any) => children;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Mock for settings components used by email-editor
2+
import * as React from "react";
3+
4+
export const SettingsSelect = ({ children }: { children?: React.ReactNode }) =>
5+
React.createElement(React.Fragment, null, children);
6+
export const SettingsSection = ({ children }: { children?: React.ReactNode }) =>
7+
React.createElement(React.Fragment, null, children);
8+
export const SettingsSlider = ({ children }: { children?: React.ReactNode }) =>
9+
React.createElement(React.Fragment, null, children);

apps/queue/__mocks__/slugify.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default jest.fn((str: string) => str.toLowerCase().replace(/\s+/g, "-"));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Mock for UI components that aren't needed for renderEmailToHtml testing
2+
export const Popover = ({ children }: { children: React.ReactNode }) =>
3+
children;
4+
export const PopoverContent = ({ children }: { children: React.ReactNode }) =>
5+
children;
6+
export const PopoverTrigger = ({ children }: { children: React.ReactNode }) =>
7+
children;

apps/queue/jest-mongodb-config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
mongodbMemoryServerOptions: {
3+
binary: {
4+
version: "7.0.0",
5+
skipMD5: true,
6+
},
7+
instance: {
8+
dbName: "jest",
9+
},
10+
autoStart: false,
11+
},
12+
useSharedDBForAllJestWorkers: true,
13+
};

apps/queue/jest.config.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const config = {
2+
preset: "@shelf/jest-mongodb",
3+
setupFilesAfterEnv: ["<rootDir>/setupTests.ts"],
4+
watchPathIgnorePatterns: ["globalConfig"],
5+
moduleNameMapper: {
6+
"@courselit/utils": "<rootDir>/../../packages/utils/src",
7+
"@courselit/common-logic": "<rootDir>/../../packages/common-logic/src",
8+
"@courselit/common-models":
9+
"<rootDir>/../../packages/common-models/src",
10+
"@courselit/email-editor":
11+
"<rootDir>/__mocks__/@courselit/email-editor.ts",
12+
nanoid: "<rootDir>/__mocks__/nanoid.ts",
13+
"@sindresorhus/slugify": "<rootDir>/__mocks__/slugify.ts",
14+
// Handle @/ paths - prioritize email-editor package paths, then queue app paths
15+
// These must come before the generic @/ pattern
16+
"^@/components/ui/(.*)$":
17+
"<rootDir>/../../packages/email-editor/src/components/ui/$1",
18+
"^@/components/settings/(.*)$":
19+
"<rootDir>/__mocks__/settings-components.tsx",
20+
"^@/components/(.*)$":
21+
"<rootDir>/../../packages/email-editor/src/components/$1",
22+
"^@/lib/(.*)$": "<rootDir>/../../packages/email-editor/src/lib/$1",
23+
"^@/blocks$": "<rootDir>/../../packages/email-editor/src/blocks",
24+
"^@/blocks/(.*)$":
25+
"<rootDir>/../../packages/email-editor/src/blocks/$1",
26+
"^@/types/(.*)$": "<rootDir>/../../packages/email-editor/src/types/$1",
27+
"^@/(.*)$": "<rootDir>/src/$1",
28+
// Mock React UI components and dependencies that aren't available in Node.js
29+
"^@radix-ui/(.*)$": "<rootDir>/__mocks__/radix-ui.ts",
30+
"^lucide-react$": "<rootDir>/__mocks__/lucide-react.ts",
31+
// Mock CSS imports
32+
"\\.css$": "<rootDir>/__mocks__/css.ts",
33+
},
34+
transformIgnorePatterns: ["node_modules/(?!(nanoid)/)"],
35+
extensionsToTreatAsEsm: [],
36+
transform: {
37+
"^.+\\.(ts|tsx)$": [
38+
"ts-jest",
39+
{
40+
tsconfig: {
41+
jsx: "react-jsx",
42+
},
43+
},
44+
],
45+
},
46+
testMatch: ["**/__tests__/**/*.test.ts", "**/?(*.)+(spec|test).ts"],
47+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
48+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json"],
49+
testEnvironment: "node",
50+
};
51+
52+
export default config;

0 commit comments

Comments
 (0)