-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement past-days function * Implement DailyWord component * Add DailyWord to index page and fix free spaces * Move DailyWord component to src/components folder * Change daily word header type to h1 * Change margin of containers in pages/index.tsx * Remove web3GlossaryHeading from pages/index.xts * Change styles of daily-word component
- Loading branch information
1 parent
3c4b149
commit 849c318
Showing
7 changed files
with
112 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import {render, screen} from '@testing-library/react'; | ||
import DailyWord from '../../../src/components/daily-word/daily-word'; | ||
|
||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ t: (key) => key }), | ||
})); | ||
|
||
const words = ["eip", "ethereum", "whale", "web3", "web2"]; | ||
|
||
it('it shows a word of words in a link', () => { | ||
render(<DailyWord words={words}/>); | ||
|
||
const wordLink = screen.getByRole('link'); | ||
|
||
expect(wordLink).toBeInTheDocument(); | ||
expect(words.includes(wordLink.text)).toBe(true); | ||
}) | ||
|
||
it('it links the word to the correct page', () => { | ||
render(<DailyWord words={words}/>); | ||
|
||
const wordLink = screen.getByRole('link'); | ||
const pattern = `search\\?term=${wordLink.text}`; | ||
const regex = new RegExp(pattern); | ||
|
||
expect(wordLink).toBeInTheDocument(); | ||
expect(wordLink.href).toMatch(regex); | ||
}) | ||
|
||
it('it shows a unique word in each day that matches with it\'s link', () => { | ||
const shownWords = new Set(); | ||
const element = render(<DailyWord words={words}/>); | ||
|
||
for(let i=0;i<words.length;i++){ | ||
const singleDay = 24 * 60 * 60 * 1000; | ||
const date = new Date((new Date).getTime() + singleDay * i); | ||
jest.useFakeTimers().setSystemTime(date); | ||
element.rerender(<DailyWord words={words}/>); | ||
|
||
const wordLink = screen.getByRole('link'); | ||
const word = wordLink.text; | ||
const pattern = `search\\?term=${word}`; | ||
const regex = new RegExp(pattern); | ||
|
||
expect(wordLink).toBeInTheDocument(); | ||
expect(wordLink.href).toMatch(regex); | ||
|
||
expect(shownWords.has(word)).toBe(false); | ||
shownWords.add(word); | ||
jest.useRealTimers(); | ||
} | ||
}); | ||
|
||
it('it shows the title correctly', () => { | ||
render(<DailyWord words={words}/>); | ||
|
||
const title = screen.getByText("wordOfTheDay"); | ||
|
||
expect(title).toBeInTheDocument(); | ||
}) |
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,18 @@ | ||
import pastDays from '../../../src/components/daily-word/past-days'; | ||
|
||
it("it returns past days of 1970", () => { | ||
const singleDay = 24 * 60 * 60 * 1000; | ||
|
||
const timeInJan1970 = singleDay * 5 + 30 * 60 * 1000; | ||
const dateInJan1970 = new Date(timeInJan1970); | ||
|
||
const timeIn1970 = singleDay * 98 + 154 * 60 * 1000; | ||
const dateIn1970 = new Date(timeIn1970); | ||
|
||
const timeAfter1970 = singleDay * 42195 + 23 * 60 * 60 * 1000 + 30 * 60 * 1000; | ||
const date = new Date(timeAfter1970); | ||
|
||
expect(pastDays(dateInJan1970)).toBe(5); | ||
expect(pastDays(dateIn1970)).toBe(98); | ||
expect(pastDays(date)).toBe(42195); | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { Text, Link, VStack, Heading } from '@chakra-ui/react'; | ||
import pastDays from "./past-days"; | ||
import { useTranslation } from "next-i18next"; | ||
|
||
const DailyWord = ({words}:{words:any[]}): JSX.Element => { | ||
const { t } = useTranslation(); | ||
|
||
const indexOfWords = pastDays(new Date()) % words.length; | ||
return ( | ||
<VStack fontSize={{ base: "lg", md: "xl" }}> | ||
<Heading as="h1" color="white" textAlign="center">{t("wordOfTheDay")}</Heading> | ||
<Link color="white" href={`/search?term=${words[indexOfWords]}`}> | ||
<Text casing="capitalize">{words[indexOfWords]}</Text> | ||
</Link> | ||
</VStack> | ||
) | ||
} | ||
|
||
export default DailyWord; |
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,6 @@ | ||
const pastDays = (date: Date): number => { | ||
const day = 24 * 60 * 60 * 1000; | ||
return Math.floor(date.getTime()/day); | ||
} | ||
|
||
export default pastDays; |
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
849c318
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
glosseta – ./
glosseta-glosseta.vercel.app
glosseta.vercel.app
www.glosseta.com
glosseta.com
glosseta-git-main-glosseta.vercel.app