ryosei-f 1 week ago
parent
commit
3502d20d66

+ 2 - 1
packages/presentation/package.json

@@ -37,7 +37,8 @@
     "lint:biome": "biome check",
     "lint:styles": "stylelint --allow-empty-input \"src/**/*.scss\" \"src/**/*.css\"",
     "lint:typecheck": "tsgo --noEmit",
-    "lint": "run-p lint:*"
+    "lint": "run-p lint:*",
+    "test": "vitest run"
   },
   "dependencies": {
   },

+ 53 - 0
packages/presentation/src/client/components/GrowiSlides.spec.tsx

@@ -0,0 +1,53 @@
+import { render } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { GrowiSlides } from './GrowiSlides';
+
+vi.mock('next/head', () => ({
+  default: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}));
+
+vi.mock('../consts/marpit-base-css.vendor-styles.prebuilt', () => ({
+  PRESENTATION_MARPIT_CSS: '',
+  SLIDE_MARPIT_CSS: '',
+}));
+
+vi.mock('../services/renderer/extract-sections', () => ({
+  remarkPlugin: vi.fn(),
+}));
+
+vi.mock('./RichSlideSection', () => ({
+  RichSlideSection: () => <div />,
+  PresentationRichSlideSection: () => <div />,
+}));
+
+describe('GrowiSlides', () => {
+  it('does not throw when rendererOptions is undefined', () => {
+    expect(() =>
+      render(
+        <GrowiSlides options={{ rendererOptions: undefined as any }}>
+          {'# Slide'}
+        </GrowiSlides>,
+      ),
+    ).not.toThrow();
+  });
+
+  it('does not throw when rendererOptions is null', () => {
+    expect(() =>
+      render(
+        <GrowiSlides options={{ rendererOptions: null as any }}>
+          {'# Slide'}
+        </GrowiSlides>,
+      ),
+    ).not.toThrow();
+  });
+
+  it('renders nothing when rendererOptions is null', () => {
+    const { container } = render(
+      <GrowiSlides options={{ rendererOptions: null as any }}>
+        {'# Slide'}
+      </GrowiSlides>,
+    );
+    expect(container.firstChild).toBeNull();
+  });
+});

+ 10 - 0
packages/presentation/vitest.config.ts

@@ -0,0 +1,10 @@
+import react from '@vitejs/plugin-react';
+import { defineConfig } from 'vitest/config';
+
+export default defineConfig({
+  plugins: [react()],
+  test: {
+    environment: 'happy-dom',
+    globals: true,
+  },
+});