-
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.
Merge pull request #54 from evmos/sandoche/other-fixes
Sandoche/other fixes
- Loading branch information
Showing
9 changed files
with
94 additions
and
4 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
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,54 @@ | ||
// Copyright Tharsis Labs Ltd.(Evmos) | ||
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/burn-auction-dapp/blob/main/LICENSE) | ||
|
||
import { render, act, screen } from '@testing-library/react'; | ||
import { expect, describe, it, beforeEach, afterEach, vi } from 'vitest'; | ||
|
||
import { Countdown, DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO } from '../Countdown'; | ||
import * as reloadDataModule from '../../_actions/reloadData'; | ||
|
||
const ONE_SECOND = 1000; | ||
const ONE_HOUR_ONE_MINUTE_AND_TEN_SECONDS = 3670000; | ||
|
||
// Mock the entire module | ||
vi.mock('../../_actions/reloadData'); | ||
|
||
describe('Countdown Component', () => { | ||
beforeEach(() => { | ||
vi.useFakeTimers(); | ||
// Create a mock function for reloadData | ||
vi.spyOn(reloadDataModule, 'default').mockImplementation(vi.fn()); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllTimers(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('renders correctly', () => { | ||
const targetDate: Date = new Date(Date.now() + ONE_HOUR_ONE_MINUTE_AND_TEN_SECONDS); | ||
render(<Countdown date={targetDate} />); | ||
expect(screen.getByText(/0d/)).toBeDefined(); | ||
expect(screen.getByText(/1h/)).toBeDefined(); | ||
expect(screen.getByText(/1m/)).toBeDefined(); | ||
expect(screen.getByText(/10s/)).toBeDefined(); | ||
}); | ||
|
||
it('reloads when reaching 0', () => { | ||
const targetDate = new Date(Date.now() + ONE_SECOND); // Set to 1 second in the future | ||
render(<Countdown date={targetDate} />); | ||
|
||
// Fast-forward time to just after the countdown should reach zero | ||
act(() => { | ||
vi.advanceTimersByTime(ONE_SECOND + 1); | ||
}); | ||
|
||
// Fast-forward time to trigger the delayed reload | ||
act(() => { | ||
vi.advanceTimersByTime(DELAY_BEFORE_RELOAD_AFTER_COUNTDOWN_GOES_TO_ZERO); | ||
}); | ||
|
||
// Check if reloadData was called | ||
expect(reloadDataModule.default).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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,24 @@ | ||
// Copyright Tharsis Labs Ltd.(Evmos) | ||
// SPDX-License-Identifier:ENCL-1.0(https://github.com/evmos/burn-auction-dapp/blob/main/LICENSE) | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import { expect, describe, it } from 'vitest'; | ||
|
||
import { DiscountChip } from '../DiscountChip'; | ||
|
||
describe('DiscountChip Component', () => { | ||
it('displays the correct message when highestBidUsd is 0', () => { | ||
render(<DiscountChip currentValueUsd={1000} highestBidUsd={0} />); | ||
expect(screen.getByText('🤯 Be the first to bid')).toBeDefined(); | ||
}); | ||
|
||
it('displays the correct discount message when highestBidUsd is less than currentValueUsd', () => { | ||
render(<DiscountChip currentValueUsd={1000} highestBidUsd={500} />); | ||
expect(screen.getByText('🔥 2x cheaper than market value')).toBeDefined(); | ||
}); | ||
|
||
it('does not render anything when highestBidUsd is greater than currentValueUsd', () => { | ||
const { container } = render(<DiscountChip currentValueUsd={1000} highestBidUsd={1500} />); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
}); |
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
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