Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

*storybook.log
*storybook.log

/prisma/dmmf.json
4 changes: 2 additions & 2 deletions app/(planner)/events/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { redirect } from 'next/navigation';
import { getUser } from '../../actions/user';
import { getEvents } from '../../actions/events';
import { getUser } from '#app/actions/user';
import { getEvents } from '#app/actions/events';
import Planner from '../../../components/ui/Planner';

async function getData() {
Expand Down
6 changes: 3 additions & 3 deletions app/(planner)/print/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { redirect } from 'next/navigation';
import Planner from '@/components/ui/PlannerPDF';
import { getUser } from '@/app/actions/user';
import { getEvents } from '@/app/actions/events';
import Planner from '#components/ui/PlannerPDF';
import { getUser } from '#app/actions/user';
import { getEvents } from '#app/actions/events';

async function getData() {
const user = await getUser();
Expand Down
4 changes: 2 additions & 2 deletions app/actions/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use server';
import { getUser } from './user';
import prisma from '../../lib/prisma';
import { getUser } from '#app/actions/user';
import prisma from '#lib/prisma';

export type Event = {
id?: string;
Expand Down
8 changes: 3 additions & 5 deletions app/actions/user.mock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use server';
import { fn } from '@storybook/test';
import * as actual from './user';

export * from './user';
export const getUser = fn(actual.getUser).mockName('getUser');
export const getSignInUrl = fn(actual.getSignInUrl).mockName('getSignInUrl');
export const signOut = fn(actual.signOut).mockName('signOut');
export const getUser = fn(async() => {}).mockName('getUser');
export const getSignInUrl = fn(async() => {}).mockName('getSignInUrl');
export const signOut = fn(async() => {}).mockName('signOut');
8 changes: 4 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import NextLink from 'next/link';
import { getUser, getSignInUrl, signOut } from '@/app/actions/user';
import { Input } from '@/components/ui/input';
import { Button as ShadButton } from '@/components/ui/button';
import { getUser, getSignInUrl, signOut } from '#app/actions/user.mock';
import { Input } from '#components/ui/input';
import { Button as ShadButton } from '#components/ui/button';
// import { Button, Flex, Heading, Text } from '@radix-ui/themes';
import { SignInButton } from '@/components/ui/signInButton';
import { SignInButton } from '#components/ui/signInButton';
import Image from 'next/image';

async function getData() {
Expand Down
2 changes: 1 addition & 1 deletion components/ui/PDF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
TableCell,
} from './table';
import { BlankTable } from './BlankTable';
import type { Event } from '@/app/actions/events';
import type { Event } from '#app/actions/events';

function compare(a: Event, b: Event) {
if (a.endAt > b.endAt) return -1;
Expand Down
6 changes: 3 additions & 3 deletions components/ui/Planner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import React, { useState } from 'react';
import NextLink from 'next/link';
import { format } from 'date-fns';
import type { User } from '@/app/actions/user';
import type { Event } from '@/app/actions/events';
import type { User } from '#app/actions/user';
import type { Event } from '#app/actions/events';
import { CirclePicker } from 'react-color';

import { Popover, PopoverTrigger, PopoverContent } from './popover';
Expand Down Expand Up @@ -41,7 +41,7 @@ import {
TableBody,
TableCell,
} from './table';
import { createEvent } from '@/app/actions/events';
import { createEvent } from '#app/actions/events';

export default function Planner({
currentDate = new Date(),
Expand Down
2 changes: 1 addition & 1 deletion components/ui/PlannerPDF.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { addDays, format } from 'date-fns';
import PDF from './PDF';
import { Popover, PopoverTrigger, PopoverContent } from './popover';
import { Button } from './button';
import type { Event } from '@/app/actions/events';
import type { Event } from '#app/actions/events';

function generateDateArray(dateRange: { from: Date; to: Date }) {
const { from, to } = dateRange;
Expand Down
2 changes: 1 addition & 1 deletion components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '@/lib/utils';
import { cn } from '#lib/utils';

const buttonVariants = cva(
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
Expand Down
4 changes: 2 additions & 2 deletions components/ui/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import * as React from 'react';
import { DayPicker } from 'react-day-picker';

import { cn } from '@/lib/utils';
import { buttonVariants } from '@/components/ui/button';
import { cn } from '#lib/utils';
import { buttonVariants } from '#components/ui/button';
import 'react-day-picker/style.css';
export type CalendarProps = React.ComponentProps<typeof DayPicker>;

Expand Down
2 changes: 1 addition & 1 deletion components/ui/label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import * as LabelPrimitive from '@radix-ui/react-label';
import { cva, type VariantProps } from 'class-variance-authority';

import { cn } from '@/lib/utils';
import { cn } from '#lib/utils';

const labelVariants = cva(
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70'
Expand Down
2 changes: 1 addition & 1 deletion components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import * as SelectPrimitive from '@radix-ui/react-select';
import { Check, ChevronDown, ChevronUp } from 'lucide-react';

import { cn } from '@/lib/utils';
import { cn } from '#lib/utils';

const Select = SelectPrimitive.Root;

Expand Down
2 changes: 1 addition & 1 deletion components/ui/table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';

import { cn } from '@/lib/utils';
import { cn } from '#lib/utils';

const Table = React.forwardRef<
HTMLTableElement,
Expand Down
38 changes: 38 additions & 0 deletions lib/prisma.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Prisma, type PrismaClient } from '@prisma/client'
import { fn, isMockFunction } from '@storybook/test'
import createPrismaMock from 'prisma-mock'
import json from '#prisma/dmmf.json'

// @ts-expect-error Specify jest.fn as it is used by prisma-mock
globalThis.jest = { fn }

const createPrismaClientMock = (
data: Parameters<typeof createPrismaMock<PrismaClient>>[0] = {},
) => {
const db = createPrismaMock<PrismaClient>(
data,
json.datamodel as unknown as Prisma.DMMF.Datamodel,
)
// Give some more useful spy names
for (const [tableName, table] of Object.entries(db)) {
for (const [methodName, method] of Object.entries(table)) {
if (isMockFunction(method)) {
method.mockName(`db.${tableName}.${methodName}`)
}
}
}
return db
}

export default createPrismaClientMock()

export function initializeDB(
data: Parameters<typeof createPrismaMock<PrismaClient>>[0] = {},
) {
db = createPrismaClientMock(data)

// @ts-ignore This Error class is not loaded properly in the browser, mocking it for now like a regular Error
Prisma.PrismaClientKnownRequestError = class PrismaClientKnownRequestError extends (
Error
) {}
}
Loading