Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Sanity #396

Merged
merged 3 commits into from
Oct 5, 2024
Merged
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: 2 additions & 2 deletions __tests__/ErrorBoundary/ErrorFallback.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("ErrorFallback", () => {
render(<ErrorFallback error={mockError} />);

expect(
screen.getByText("Har du funnet en feil i Matrix?")
screen.getByText("Har du funnet en feil i Matrix?"),
).toBeInTheDocument();
expect(screen.getByText("Test error message")).toBeInTheDocument();
expect(screen.getByText("Returner til Matrix")).toBeInTheDocument();
Expand All @@ -36,7 +36,7 @@ describe("ErrorFallback", () => {
render(<ErrorFallback error={errorWithoutMessage} />);

expect(
screen.getByText("En uventet feil har oppstått.")
screen.getByText("En uventet feil har oppstått."),
).toBeInTheDocument();
});
});
54 changes: 32 additions & 22 deletions __tests__/Index/Section.test.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,78 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import Section from '../../src/components/Index/Section.component';
import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import "@testing-library/jest-dom";
import Section from "../../src/components/Index/Section.component";
import { PortableText } from "@portabletext/react";

// Mock the BounceInScroll component
jest.mock('../../src/components/Animations/BounceInScroll.component', () => {
jest.mock("../../src/components/Animations/BounceInScroll.component", () => {
return ({ children }: { children: React.ReactNode }) => <div>{children}</div>;
});

// Mock the PortableText component
jest.mock('@portabletext/react', () => ({
jest.mock("@portabletext/react", () => ({
PortableText: jest.fn(() => null),
}));

describe('Section Component', () => {
describe("Section Component", () => {
const mockProps = {
title: 'Test Title',
text: [{ _key: '1', _type: 'block', children: [{ _key: '2', _type: 'span', text: 'Test content' }] }],
title: "Test Title",
text: [
{
_key: "1",
_type: "block",
children: [{ _key: "2", _type: "span", text: "Test content" }],
},
],
};

beforeEach(() => {
jest.clearAllMocks();
});

it('renders with valid props', () => {
it("renders with valid props", () => {
render(<Section {...mockProps} />);
expect(screen.getByText('Test Title')).toBeInTheDocument();
expect(screen.getByText("Test Title")).toBeInTheDocument();
expect(PortableText).toHaveBeenCalledWith(
expect.objectContaining({
value: mockProps.text,
}),
expect.anything()
expect.anything(),
);
});

it('returns null with invalid props', () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
it("returns null with invalid props", () => {
const consoleErrorSpy = jest
.spyOn(console, "error")
.mockImplementation(() => {});
const { container } = render(<Section title="" text={[]} />);
expect(container.firstChild).toBeNull();
expect(consoleErrorSpy).toHaveBeenCalled();
consoleErrorSpy.mockRestore();
});

it('triggers error in development mode', () => {
it("triggers error in development mode", () => {
const originalEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'development';
process.env.NODE_ENV = "development";

render(<Section {...mockProps} />);
const errorButton = screen.getByText('Utløs Testfeil');
const errorButton = screen.getByText("Utløs Testfeil");
expect(errorButton).toBeInTheDocument();

expect(() => fireEvent.click(errorButton)).toThrow('En uventet feil har oppstått');
expect(() => fireEvent.click(errorButton)).toThrow(
"En uventet feil har oppstått",
);

process.env.NODE_ENV = originalEnv;
});

it('does not show error button in production mode', () => {
it("does not show error button in production mode", () => {
const originalEnv = process.env.NODE_ENV;
process.env.NODE_ENV = 'production';
process.env.NODE_ENV = "production";

render(<Section {...mockProps} />);
expect(screen.queryByText('Utløs Testfeil')).not.toBeInTheDocument();
expect(screen.queryByText("Utløs Testfeil")).not.toBeInTheDocument();

process.env.NODE_ENV = originalEnv;
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"react-hook-form": "^7.53.0",
"react-icons": "^5.3.0",
"react-use": "^17.5.1",
"sanity": "^3.59.0",
"sanity": "^3.59.1",
"sitemap": "^8.0.0",
"ts-node": "^10.9.2",
"zod": "^3.23.8"
Expand Down
2,676 changes: 1,328 additions & 1,348 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/ErrorBoundary/ErrorFallback.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ const ErrorFallback: React.FC<ErrorFallbackProps> = ({ error }) => {
);
};

export default ErrorFallback;
export default ErrorFallback;
2 changes: 1 addition & 1 deletion src/components/Index/Section.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Section = ({ text, title }: IContent) => {

if (!title || !text) {
console.error(
`Ugyldig seksjon data: tittel=${title}, tekst=${JSON.stringify(text)}`
`Ugyldig seksjon data: tittel=${title}, tekst=${JSON.stringify(text)}`,
);
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/Layout/DesktopNavigation.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ interface DesktopNavigationProps {
* @param {NavigationLink[]} props.navigationLinks - Array of navigation links to be rendered
* @returns {JSX.Element} The rendered DesktopNavigation component
*/
const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ navigationLinks }) => {
const DesktopNavigation: React.FC<DesktopNavigationProps> = ({
navigationLinks,
}) => {
const { isLinkActive } = useNavigation(navigationLinks);

return (
Expand Down Expand Up @@ -61,4 +63,4 @@ const DesktopNavigation: React.FC<DesktopNavigationProps> = ({ navigationLinks }
);
};

export default DesktopNavigation;
export default DesktopNavigation;
2 changes: 1 addition & 1 deletion src/components/Layout/MobileMenu.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const MobileMenu = ({ links }: IMobileMenuProps) => {
</Link>
)}
</motion.li>
)
),
)}
</motion.ul>
</nav>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Layout/NavigationLink.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ interface NavigationLinkProps {
* @param {boolean} props.isActive - Whether the link is currently active
* @returns {JSX.Element} The rendered NavigationLink component
*/
const NavigationLink: React.FC<NavigationLinkProps> = ({ name, href, isActive }) => (
const NavigationLink: React.FC<NavigationLinkProps> = ({
name,
href,
isActive,
}) => (
<MotionDiv className="relative" whileHover="hover">
<Link
prefetch={true}
Expand Down Expand Up @@ -45,4 +49,4 @@ const NavigationLink: React.FC<NavigationLinkProps> = ({ name, href, isActive })
</MotionDiv>
);

export default NavigationLink;
export default NavigationLink;
2 changes: 1 addition & 1 deletion src/utils/portableTextComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const myPortableTextComponents = {
</Link>
),
},
};
};