Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Forbedringer Typescript #100

Merged
merged 15 commits into from
Jan 16, 2022
6 changes: 6 additions & 0 deletions __tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ describe("Home", () => {
});
expect(banner).toBeInTheDocument();
});

it("Hero eksisterer", () => {
const { getByTestId } = render(<Home />);
const MainHero = getByTestId("main-hero");
expect(MainHero).toBeInTheDocument();
});
});
15 changes: 15 additions & 0 deletions __tests__/mobile.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @jest-environment jsdom
*/

import React from "react";
import { render } from "@testing-library/react";
import Home from "../src/pages/index";

describe("Mobile menu", () => {
it("expect HamburgerButton toBeInTheDocument", () => {
const { getByTestId } = render(<Home />);
const HamburgerButton = getByTestId("hamburger");
expect(HamburgerButton).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ coverage:
status:
project:
default:
target: "90%" # the required coverage value
threshold: "10%" # the leniency in hitting the target
target: "70%" # the required coverage value
threshold: "30%" # the leniency in hitting the target
1 change: 1 addition & 0 deletions src/components/Index/Hero.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Hero: NextComponentType = () => {
role="article"
aria-label="Kontainer for animasjoner av introtekst"
id="main-hero"
data-testid="main-hero"
className="flex flex-col justify-center text-lg">
<div className="p-4 mt-6 mb-6 bg-white opacity-75">
<div className="text-black rounded">
Expand Down
48 changes: 37 additions & 11 deletions src/components/Index/IndexContent.component.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,63 @@
//imports
import Link from "next/link";
import PortableText from "react-portable-text";

import type { NextComponentType } from "next";
// types
import { Key, ReactChild, ReactFragment, ReactPortal } from "react";
import { UrlObject } from "url";

// components
import Hero from "./Hero.component";

const IndexContent: NextComponentType = ({ post }: any) => {
// interfaces
interface IContent {
_id: Key | null;
title: string;
text: [object];
}

interface ISerializerCode {
children: boolean | ReactChild | ReactFragment | ReactPortal | null | undefined;
}

interface ISerializerLink {
href: string | UrlObject;
children: boolean | ReactChild | ReactFragment | ReactPortal | null | undefined;
}

type TData = { post: IContent[] };

const IndexContent = ({ post }: TData) => {
return (
<main role="main" aria-label="Her kommer hovedinnholdet" id="maincontent">
<div className="mx-auto mt-16 rounded lg:mt-20 xl:mt-20 bg-graybg shadow-large md:mt-16 sm:mt-64 xs:mt-64">
<Hero />
<div className="container grid gap-4 p-4 mx-auto mt-2 lg:grid-cols-2 sm:grid-cols-1 md:grid-cols-1 xs:grid-cols-1">
{post &&
post.map((content: any) => (
<div
className="mt-4 p-8 text-lg text-black bg-white rounded shadow"
key={content._id}>
<section role="contentinfo" aria-label={content.title}>
post.map((content: IContent) => (
<section
key={content._id}
role="contentinfo"
aria-label={content.title}
data-testid="sanity-section">
<div className="mt-4 p-8 text-lg text-black bg-white rounded shadow">
<h2 className="text-3xl text-center">{content.title}</h2>
<PortableText
className="text-xl"
content={content.text}
serializers={{
code: (props: any) => <p className="mt-6 text-lg">{props.children} </p>,
link: (props: any) => (
code: (props: ISerializerCode) => (
<p className="mt-6 text-lg">{props.children} </p>
),
link: (props: ISerializerLink) => (
<Link href={props.href}>
<a className="underline">{props.children}</a>
</Link>
)
}}
/>
</section>
</div>
</div>
</section>
))}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/Hamburger.component.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextComponentType } from "next";

const Hamburger: NextComponentType = () => {
return <div className="z-50 md:hidden lg:hidden xl:hidden">Hamburger</div>;
return <div data-testid="hamburger" className="z-50 md:hidden lg:hidden xl:hidden">Hamburger</div>;
};

export default Hamburger;
23 changes: 0 additions & 23 deletions stories/Index.stories.tsx

This file was deleted.