-
Notifications
You must be signed in to change notification settings - Fork 1
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
c83a238
commit 050d1c6
Showing
3 changed files
with
52 additions
and
0 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,16 @@ | ||
import React from "react"; | ||
import { useLightningTimeClock } from "../../src/react"; | ||
|
||
export function Clock() { | ||
const { lightningString, formattedNormalTime, colors } = useLightningTimeClock() | ||
const { boltColor, zapColor, sparkColor } = colors | ||
return ( | ||
<div> | ||
<p data-testid="lightning string">{lightningString}</p> | ||
<p data-testid="formatted normal time">{formattedNormalTime}</p> | ||
<p data-testid="bolt color">{boltColor}</p> | ||
<p data-testid="zap color">{zapColor}</p> | ||
<p data-testid="spark color">{sparkColor}</p> | ||
</div> | ||
) | ||
} |
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,35 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import {render, screen} from '@testing-library/react' | ||
import { Clock } from './clock-test-component' | ||
import React from 'react' | ||
import { LightningTime } from '../../src' | ||
import { format } from 'date-fns' | ||
|
||
describe('react clock', () => { | ||
it('renders a react clock', () => { | ||
render(<Clock />) | ||
expect(screen.getByTestId('lightning string')).toBeDefined() | ||
expect(screen.getByTestId('formatted normal time')).toBeDefined() | ||
expect(screen.getByTestId('bolt color')).toBeDefined() | ||
expect(screen.getByTestId('zap color')).toBeDefined() | ||
expect(screen.getByTestId('spark color')).toBeDefined() | ||
}) | ||
it('renders the correct lightning time', () => { | ||
render(<Clock />) | ||
const now = new Date() | ||
const lt = new LightningTime() | ||
const { lightningString, colors } = lt.convertToLightning(now) | ||
const formattedNowString = format(now, 'h:mm a') | ||
|
||
// this will occasionally fail if the test is run right before a new spark | ||
// TODO: find a less flaky way to test this | ||
expect(screen.getByTestId('lightning string').innerHTML).toEqual(lightningString) | ||
expect(screen.getByTestId('formatted normal time').innerHTML).toEqual(formattedNowString) | ||
expect(screen.getByTestId('bolt color').innerHTML).toEqual(colors.boltColor) | ||
expect(screen.getByTestId('zap color').innerHTML).toEqual(colors.zapColor) | ||
expect(screen.getByTestId('spark color').innerHTML).toEqual(colors.sparkColor) | ||
}) | ||
}) |