Repository navigation
Rest timer: tap the clock for a full-screen view #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
priami93
wants to merge
4
commits into
DuarteSantos8:main
Choose a base branch
from
priami93:rest-timer-full-screen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+254
−10
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f9656f9
Rest timer: tap the clock for a full-screen view
priami93 03c3a20
Rest timer full screen: name the minus and plus 15 s buttons for scre…
priami93 57d7dc6
pt-BR: override the two new rest timer strings so the inherited finge…
priami93 b136f13
Merge main into rest-timer-full-screen
priami93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,116 @@ | ||
| // @vitest-environment happy-dom | ||
| import React, { act } from 'react' | ||
| import { createRoot } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import RestTimer from './RestTimer.jsx' | ||
| import { useUI } from '../store/useUI.js' | ||
| import { useStore } from '../store/useStore.js' | ||
|
|
||
| globalThis.IS_REACT_ACT_ENVIRONMENT = true | ||
|
|
||
| vi.mock('../lib/sound.js', () => ({ beep: vi.fn(), chime: vi.fn(), vibrate: vi.fn(), alertBuzz: vi.fn() })) | ||
|
|
||
| let host, root, sheetEl, sheetRoot, originalS | ||
|
|
||
| beforeEach(() => { | ||
| vi.useFakeTimers() | ||
| originalS = useStore.getState().S | ||
| useStore.setState({ S: { ...originalS, sound: false } }) | ||
| useUI.setState({ timer: null, work: null, timerFlashId: 0, sheets: [] }) | ||
| host = document.createElement('div') | ||
| document.body.appendChild(host) | ||
| root = createRoot(host) | ||
| sheetEl = document.createElement('div') | ||
| document.body.appendChild(sheetEl) | ||
| sheetRoot = createRoot(sheetEl) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => { root.render(null); sheetRoot.render(null) }) | ||
| useUI.getState().stopRest() | ||
| useUI.getState().stopWork() | ||
| useUI.setState({ sheets: [] }) | ||
| useStore.setState({ S: originalS }) | ||
| host.remove(); sheetEl.remove() | ||
| vi.useRealTimers() | ||
| }) | ||
|
|
||
| // The open sheets, rendered the way Modals.jsx renders them, so a sheet that closes itself leaves. | ||
| function Sheets() { | ||
| const sheets = useUI(s => s.sheets) | ||
| return sheets.map(s => <div key={s.id} data-kind={s.kind}>{s.render(() => useUI.getState().closeSheet(s.id))}</div>) | ||
| } | ||
| const mount = () => act(() => { root.render(<RestTimer />); sheetRoot.render(<Sheets />) }) | ||
| const full = () => sheetEl.querySelector('.restfull') | ||
| const tapClock = () => act(() => host.querySelector('#timer .tclock').click()) | ||
|
|
||
| describe('the rest, full screen', () => { | ||
| it('opens from the bar\'s clock as a viewer, and counts down with the bar', () => { | ||
| act(() => useUI.getState().startRest(90, 0)) | ||
| mount() | ||
| tapClock() | ||
| expect(useUI.getState().sheets.map(s => s.kind)).toEqual(['viewer']) | ||
| expect(full().querySelector('.restfull-clock .t').textContent).toBe('1:30') | ||
| expect(full().querySelector('.restfull-clock').getAttribute('aria-label')).toBe('1:30. Change the time left') | ||
| act(() => vi.advanceTimersByTime(10_000)) | ||
| expect(full().querySelector('.restfull-clock .t').textContent).toBe('1:20') | ||
| expect(host.querySelector('#timer .t').textContent).toBe('1:20') | ||
| }) | ||
|
|
||
| it('its buttons work the rest: −15, pause, +15', () => { | ||
| act(() => useUI.getState().startRest(90, 0)) | ||
| mount() | ||
| tapClock() | ||
| const btn = sel => full().querySelector(sel) | ||
| act(() => btn('.adj').click()) | ||
| expect(useUI.getState().timer.left).toBe(75) | ||
| act(() => btn('.pause').click()) | ||
| expect(useUI.getState().timer.paused).toBe(true) | ||
| expect(full().classList.contains('paused')).toBe(true) | ||
| act(() => btn('.pause').click()) | ||
| expect(useUI.getState().timer.paused).toBeFalsy() | ||
| act(() => full().querySelectorAll('.adj')[1].click()) | ||
| expect(useUI.getState().timer.left).toBe(90) | ||
| }) | ||
|
|
||
| it('the big clock opens the wheel on top of it', () => { | ||
| act(() => useUI.getState().startRest(90, 0)) | ||
| mount() | ||
| tapClock() | ||
| act(() => full().querySelector('.restfull-clock').click()) | ||
| expect(useUI.getState().sheets.map(s => s.kind)).toEqual(['viewer', 'sheet']) | ||
| expect(sheetEl.querySelector('[data-kind="sheet"] h3').textContent).toBe('Time left') | ||
| }) | ||
|
|
||
| it('Skip ends the rest and closes the view', () => { | ||
| act(() => useUI.getState().startRest(90, 0)) | ||
| mount() | ||
| tapClock() | ||
| act(() => full().querySelector('.restfull-skip .btn').click()) | ||
| expect(useUI.getState().timer).toBeNull() | ||
| expect(useUI.getState().sheets).toEqual([]) | ||
| expect(full()).toBeNull() | ||
| }) | ||
|
|
||
| it('stays open at Ready, with Dismiss and no pause', () => { | ||
| act(() => useUI.getState().startRest(2, 0)) | ||
| mount() | ||
| tapClock() | ||
| act(() => vi.advanceTimersByTime(2000)) | ||
| expect(useUI.getState().timer.ready).toBe(true) | ||
| expect(full().classList.contains('ready')).toBe(true) | ||
| expect(full().querySelector('.restfull-clock .t').textContent).toBe('Ready') | ||
| expect(full().querySelector('.pause')).toBeNull() | ||
| expect(full().querySelector('.restfull-skip .btn').textContent).toBe('Dismiss') | ||
| }) | ||
|
|
||
| it('Minimize goes back to the bar, the rest still running', () => { | ||
| act(() => useUI.getState().startRest(90, 0)) | ||
| mount() | ||
| tapClock() | ||
| act(() => full().querySelector('.restfull-bar .iconbtn').click()) | ||
| expect(useUI.getState().sheets).toEqual([]) | ||
| expect(useUI.getState().timer.left).toBe(90) | ||
| expect(host.querySelector('#timer.rest')).not.toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.