-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8f5a5f
commit 6d9cb21
Showing
8 changed files
with
3,413 additions
and
2,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { ComponentProps } from "react"; | ||
|
||
import { render, screen } from "@testing-library/react"; | ||
import { useRouter } from "next/router"; | ||
|
||
import { CardSubTitle } from "components"; | ||
import { CardType } from "components/CardContent"; | ||
import { AppContextProvider } from "context/AppContextProvider"; | ||
import { useOnScreen } from "hooks"; | ||
import { IUtilsMocks } from "types/mocks"; | ||
import { Language } from "utils"; | ||
|
||
jest.mock("hooks/useOnScreen"); | ||
|
||
const { getAllTranslations } = jest.requireActual<IUtilsMocks>( | ||
"utils/__tests__/__mocks__/mocks.ts" | ||
); | ||
|
||
interface IMocks { | ||
push?: () => void; | ||
useOnScreen?: boolean; | ||
} | ||
|
||
interface ISetupProps { | ||
props: ComponentProps<typeof CardSubTitle>; | ||
mocks?: IMocks; | ||
} | ||
|
||
describe("cardSubTitle", () => { | ||
function setup({ props, mocks }: ISetupProps) { | ||
(useOnScreen as jest.Mock).mockImplementationOnce( | ||
() => mocks?.useOnScreen ?? true | ||
); | ||
const push = jest.fn(); | ||
(useRouter as jest.Mock).mockImplementation(() => ({ | ||
asPath: "/", | ||
push: mocks?.push ?? push, | ||
query: { | ||
country: "US", | ||
}, | ||
})); | ||
|
||
const translations = getAllTranslations(Language.EN); | ||
render( | ||
<AppContextProvider translations={translations}> | ||
<CardSubTitle {...props} /> | ||
</AppContextProvider> | ||
); | ||
} | ||
|
||
it("should receive correct props when type is ALBUM and compilation is in item", () => { | ||
expect.assertions(1); | ||
const item = { | ||
album_type: "compilation", | ||
artists: [ | ||
{ | ||
name: "artist1", | ||
}, | ||
{ | ||
name: "artist2", | ||
}, | ||
], | ||
release_date: "2022-02-04", | ||
} as unknown as ISetupProps["props"]["item"]; | ||
const push = jest.fn(); | ||
setup({ props: { type: CardType.ALBUM, item }, mocks: { push } }); | ||
expect( | ||
screen.getAllByText((_, element) => { | ||
return element?.textContent === "2022 · Compilation · artist1, artist2"; | ||
}) | ||
).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.