Skip to content

Commit

Permalink
Simplify act-wrapped vi.runOnlyPendingTimersAsync to point-free style.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Nov 23, 2024
1 parent 60de38c commit 64a8f4b
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 66 deletions.
34 changes: 17 additions & 17 deletions src/components/__tests__/Bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('render', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bullets = document.querySelectorAll('[aria-label="bullet"]')
expect(bullets.length).toBe(3)
Expand All @@ -43,7 +43,7 @@ describe('render', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// =bullet is hidden so only a is shown
// a should not have a bullet
Expand All @@ -65,7 +65,7 @@ describe('render', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// =bullet is hidden so only a, b, c are shown
// only a should have a bullet
Expand All @@ -88,7 +88,7 @@ describe('render', () => {
toggleHiddenThoughts(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// =children should not have a bullet since =bullet/None is applied
const bullets = document.querySelectorAll('[aria-label="bullet"]')
Expand All @@ -112,7 +112,7 @@ describe('render', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// only a and b should have bullets
const bullets = document.querySelectorAll('[aria-label="bullet"]')
Expand All @@ -133,7 +133,7 @@ describe('render', () => {
toggleHiddenThoughts(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bullets = document.querySelectorAll('[aria-label="bullet"]')
expect(bullets.length).toBe(4)
Expand All @@ -150,7 +150,7 @@ describe('render', () => {
toggleHiddenThoughts(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bullets = document.querySelectorAll('[data-bullet="parent"]')
expect(bullets.length).toBe(1)
Expand All @@ -171,14 +171,14 @@ describe('expansion', () => {
setCursor(['a', 'b']),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bulletOfThoughtB = getBulletByContext(['a', 'b'])

const user = userEvent.setup({ delay: null })
await user.click(bulletOfThoughtB)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thoughtCursor = await findCursor()
expect(thoughtCursor).toHaveTextContent('a')
Expand All @@ -198,14 +198,14 @@ describe('expansion', () => {
setCursor(['x', 'a', 'b', 'c']),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bulletOfThoughtA = getBulletByContext(['x', 'a'])

const user = userEvent.setup({ delay: null })
await user.click(bulletOfThoughtA)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thoughtCursor = await findCursor()
expect(thoughtCursor).toHaveTextContent('x')
Expand All @@ -224,14 +224,14 @@ describe('expansion', () => {
setCursor(['a', 'b', 'c']),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bulletOfThoughtA = getBulletByContext(['a'])

const user = userEvent.setup({ delay: null })
await user.click(bulletOfThoughtA)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thoughtCursor = await findCursor()
expect(thoughtCursor).toBeNull()
Expand All @@ -249,14 +249,14 @@ describe('expansion', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bulletOfThoughtB = getBulletByContext(['a', 'b'])

const user = userEvent.setup({ delay: null })
await user.click(bulletOfThoughtB)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thoughtCursor = await findCursor()
expect(thoughtCursor).toHaveTextContent('b')
Expand All @@ -277,14 +277,14 @@ describe('expansion', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const bulletOfThoughtB = getBulletByContext(['a', 'b'])

const user = userEvent.setup({ delay: null })
await user.click(bulletOfThoughtB)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const exported = exportContext(store.getState(), [HOME_TOKEN], 'text/plain')
expect(exported).toEqual(`- __ROOT__
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/ColorPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ it('Set the bullet color using the ColorPicker', async () => {
await click('[data-testid="toolbar-icon"][aria-label="Text Color"]')
await click('[aria-label="text color swatches"] [aria-label="blue"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const state = store.getState()

Expand Down Expand Up @@ -47,7 +47,7 @@ it('Set the bullet color from another color using the ColorPicker', async () =>
await click('[data-testid="toolbar-icon"][aria-label="Text Color"]')
await click('[aria-label="text color swatches"] [aria-label="red"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const exported = exportContext(store.getState(), [HOME_TOKEN], 'text/plain')
expect(exported).toEqual(`- __ROOT__
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/Content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ it('do not render EmptyThoughtspace when there are thoughts in the root context'
}),
)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(document.querySelector('[aria-label="empty-thoughtspace"]')).toBeNull()
})
Expand All @@ -35,7 +35,7 @@ it('render EmptyThoughtspace when there are only invisible thoughts in the root
}),
)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(document.querySelector('[aria-label="empty-thoughtspace"]')).toBeTruthy()
})
4 changes: 2 additions & 2 deletions src/components/__tests__/ContextView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ it('Clicking a context moves the cursor to that context', async () => {
toggleContextView(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// select each context in the context view
const contextBreadcrumbs = document.querySelectorAll('[aria-label="context-breadcrumbs"]')
Expand All @@ -56,7 +56,7 @@ it('Clicking a context moves the cursor to that context', async () => {
const user = userEvent.setup({ delay: null })
await user.click(contextLink)

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// cursor should exist
const cursor = store.getState().cursor!
Expand Down
8 changes: 4 additions & 4 deletions src/components/__tests__/LetterCasePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('Set Lower Case to the current thought', async () => {
await click('[data-testid="toolbar-icon"][aria-label="LetterCase"]')
await click('[aria-label="letter case swatches"] [aria-label="LowerCase"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const state = store.getState()

Expand All @@ -29,7 +29,7 @@ it('Set Upper Case to the current thought', async () => {
await click('[data-testid="toolbar-icon"][aria-label="LetterCase"]')
await click('[aria-label="letter case swatches"] [aria-label="UpperCase"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const state = store.getState()

Expand All @@ -43,7 +43,7 @@ it('Set Sentence Case to the current thought', async () => {
await click('[data-testid="toolbar-icon"][aria-label="LetterCase"]')
await click('[aria-label="letter case swatches"] [aria-label="SentenceCase"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const state = store.getState()

Expand All @@ -57,7 +57,7 @@ it('Set Title Case to the current thought', async () => {
await click('[data-testid="toolbar-icon"][aria-label="LetterCase"]')
await click('[aria-label="letter case swatches"] [aria-label="TitleCase"]')

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const state = store.getState()

Expand Down
2 changes: 1 addition & 1 deletion src/components/__tests__/NavBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('Strip formatting from thought values in ContextBreadcrumbs', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const contextBreadcrumbs = document.querySelector('[aria-label="context-breadcrumbs"]')!
expect(contextBreadcrumbs.textContent).toBe('test')
Expand Down
8 changes: 4 additions & 4 deletions src/components/__tests__/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ it('basic note', async () => {
setCursor(null),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const element = screen.getByText('foo')
expect(element)
Expand All @@ -49,7 +49,7 @@ it('re-render note when =note subthought value changes', async () => {
setCursor(null),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const element = screen.getByText('bar')
expect(element)
Expand All @@ -76,7 +76,7 @@ it('render note when subthought is edited from non-attribute', async () => {
setCursor(null),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const element = screen.getByText('foo')
expect(element)
Expand All @@ -103,7 +103,7 @@ it('render note when subthought is edited from non-note attribute', async () =>
setCursor(null),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const element = screen.getByText('foo')
expect(element)
Expand Down
14 changes: 7 additions & 7 deletions src/components/__tests__/Superscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it('Superscript should count all the contexts in which it is defined.', async ()
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const element = screen.getByText('3')
expect(element.nodeName).toBe('SUP')
Expand All @@ -41,7 +41,7 @@ it('Superscript should not render on thoughts in a single context', async () =>
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByText('1')).toThrow('Unable to find an element')
})
Expand All @@ -58,7 +58,7 @@ it('Superscript should not render on empty thoughts', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})
Expand All @@ -72,7 +72,7 @@ it('Superscript should not render on thoughts that match EM descendants', async
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByRole('superscript')).toThrow('Unable to find an accessible element')
})
Expand Down Expand Up @@ -108,7 +108,7 @@ it('Superscript should not render on punctuation-only thoughts', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
expect(() => screen.getByText('3')).toThrow('Unable to find an element')
Expand All @@ -128,7 +128,7 @@ it('Superscript should not render on punctuation-only thoughts with HTML', async
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})
Expand All @@ -145,7 +145,7 @@ it('Superscript should not count for hashed version of metaprogramming attribute
toggleHiddenThoughtsActionCreator(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})
4 changes: 2 additions & 2 deletions src/components/__tests__/headings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ it('headings should set font weight', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// normal text should not be bold
const thought0 = await findThoughtByText('Normal Text')
Expand All @@ -52,7 +52,7 @@ it('headings should set font weight', async () => {
// child should not be bold
store.dispatch(setCursor(['My Heading 1', '=heading1']))

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thought1Child = await findThoughtByText('=heading1')
expect(thought1Child).not.toHaveStyle({ fontWeight: 700 })
Expand Down
8 changes: 4 additions & 4 deletions src/components/__tests__/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ it('apply =style attribute to a thought', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

const thoughtRazzle = (await findThoughtByText('Razzle'))?.closest('[aria-label="child"]')
expect(thoughtRazzle).toHaveStyle({ color: 'rgba(255, 192, 203, 1)' })
Expand All @@ -48,7 +48,7 @@ it('apply =children/=style to all children', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// do not apply to thought itself
expect(await findThoughtByText('a')).not.toHaveStyle({ color: 'rgba(255, 192, 203, 1)' })
Expand Down Expand Up @@ -100,7 +100,7 @@ it('apply =grandchildren/=style to all grandchildren', async () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

// do not apply to thought itself
expect(await findThoughtByText('a')).not.toHaveStyle({ color: 'rgba(255, 192, 203, 1)' })
Expand Down Expand Up @@ -131,7 +131,7 @@ it('as an exception, do not apply =grandchildren/=style to =grandchildren itself
toggleHiddenThoughts(),
])

await act(async () => vi.runOnlyPendingTimersAsync())
await act(vi.runOnlyPendingTimersAsync)

expect(await findThoughtByText('=grandchildren')).not.toHaveStyle({ color: 'rgba(255, 192, 203, 1)' })
})
Loading

0 comments on commit 64a8f4b

Please sign in to comment.