Skip to content
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

Fix replication in tests #2614

Merged
merged 26 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/components/__tests__/Bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('render', () => {
}),
])

await act(async () => vi.runOnlyPendingTimersAsync())
mstrofbass marked this conversation as resolved.
Show resolved Hide resolved

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

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

// =bullet is hidden so only a is shown
// a should not have a bullet
const bullets = document.querySelectorAll('[aria-label="bullet"]')
Expand All @@ -61,6 +65,8 @@ describe('render', () => {
}),
])

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

// =bullet is hidden so only a, b, c are shown
// only a should have a bullet
const bullets = document.querySelectorAll('[aria-label="bullet"]')
Expand All @@ -82,6 +88,8 @@ describe('render', () => {
toggleHiddenThoughts(),
])

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

const bulletOfThoughtA = getBulletByContext(['a'])

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

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

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

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

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

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

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

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

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

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

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

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

const exported = exportContext(store.getState(), [HOME_TOKEN], 'text/plain')
expect(exported).toEqual(`- __ROOT__
- a
Expand Down
5 changes: 5 additions & 0 deletions src/components/__tests__/ColorPicker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import { newThoughtActionCreator as newThought } from '../../actions/newThought'
import { HOME_TOKEN } from '../../constants'
Expand All @@ -17,6 +18,8 @@ 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())

const state = store.getState()

const exported = exportContext(state, [HOME_TOKEN], 'text/plain')
Expand Down Expand Up @@ -44,6 +47,8 @@ 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())

const exported = exportContext(store.getState(), [HOME_TOKEN], 'text/plain')
expect(exported).toEqual(`- __ROOT__
- a
Expand Down
5 changes: 5 additions & 0 deletions src/components/__tests__/Content.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import createTestApp, { cleanupTestApp } from '../../test-helpers/createTestApp'
import dispatch from '../../test-helpers/dispatch'
Expand All @@ -20,6 +21,8 @@ it('do not render EmptyThoughtspace when there are thoughts in the root context'
}),
)

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

expect(document.querySelector('[aria-label="empty-thoughtspace"]')).toBeNull()
})

Expand All @@ -32,5 +35,7 @@ it('render EmptyThoughtspace when there are only invisible thoughts in the root
}),
)

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

expect(document.querySelector('[aria-label="empty-thoughtspace"]')).toBeTruthy()
})
5 changes: 5 additions & 0 deletions src/components/__tests__/ContextView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { findAllByLabelText, findByLabelText, queryByLabelText, queryByText, screen } from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import { toggleContextViewActionCreator as toggleContextView } from '../../actions/toggleContextView'
import store from '../../stores/app'
Expand Down Expand Up @@ -37,6 +38,8 @@ it('Clicking a context moves the cursor to that context', async () => {
toggleContextView(),
])

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

// select each context in the context view
const contextBreadcrumbs = document.querySelectorAll('[aria-label="context-breadcrumbs"]')

Expand All @@ -53,6 +56,8 @@ 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())

// cursor should exist
const cursor = store.getState().cursor!
expect(cursor).toBeTruthy()
Expand Down
9 changes: 9 additions & 0 deletions src/components/__tests__/LetterCasePicker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { act } from 'react'
import { newThoughtActionCreator as newThought } from '../../actions/newThought'
import { HOME_TOKEN } from '../../constants'
import exportContext from '../../selectors/exportContext'
Expand All @@ -14,6 +15,8 @@ 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())

const state = store.getState()

const exported = exportContext(state, [HOME_TOKEN], 'text/plain')
Expand All @@ -26,6 +29,8 @@ 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())

const state = store.getState()

const exported = exportContext(state, [HOME_TOKEN], 'text/plain')
Expand All @@ -38,6 +43,8 @@ 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())

const state = store.getState()

const exported = exportContext(state, [HOME_TOKEN], 'text/plain')
Expand All @@ -50,6 +57,8 @@ 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())

const state = store.getState()

const exported = exportContext(state, [HOME_TOKEN], 'text/plain')
Expand Down
3 changes: 3 additions & 0 deletions src/components/__tests__/NavBar.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import createTestApp, { cleanupTestApp } from '../../test-helpers/createTestApp'
import dispatch from '../../test-helpers/dispatch'
Expand All @@ -14,6 +15,8 @@ it('Strip formatting from thought values in ContextBreadcrumbs', async () => {
}),
])

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

const contextBreadcrumbs = document.querySelector('[aria-label="context-breadcrumbs"]')!
expect(contextBreadcrumbs.textContent).toBe('test')
})
9 changes: 9 additions & 0 deletions src/components/__tests__/Note.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { screen } from '@testing-library/dom'
import { act } from 'react'
import SimplePath from '../../@types/SimplePath'
import { editThoughtActionCreator as editThought } from '../../actions/editThought'
import { importTextActionCreator as importText } from '../../actions/importText'
Expand All @@ -21,6 +22,8 @@ it('basic note', async () => {
setCursor(null),
])

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

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

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

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

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

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

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

const element = screen.getByText('foo')
expect(element)
})
15 changes: 15 additions & 0 deletions src/components/__tests__/Superscript.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { screen } from '@testing-library/dom'
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import { toggleHiddenThoughtsActionCreator } from '../../actions/toggleHiddenThoughts'
import createTestApp, { cleanupTestApp } from '../../test-helpers/createTestApp'
Expand All @@ -23,6 +24,8 @@ it('Superscript should count all the contexts in which it is defined.', async ()
}),
])

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

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

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

expect(() => screen.getByText('1')).toThrow('Unable to find an element')
})

Expand All @@ -53,6 +58,8 @@ it('Superscript should not render on empty thoughts', async () => {
}),
])

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

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})

Expand All @@ -65,6 +72,8 @@ it('Superscript should not render on thoughts that match EM descendants', async
}),
])

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

expect(() => screen.getByRole('superscript')).toThrow('Unable to find an accessible element')
})

Expand Down Expand Up @@ -99,6 +108,8 @@ it('Superscript should not render on punctuation-only thoughts', async () => {
}),
])

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

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

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

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})

Expand All @@ -132,5 +145,7 @@ it('Superscript should not count for hashed version of metaprogramming attribute
toggleHiddenThoughtsActionCreator(),
])

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

expect(() => screen.getByText('2')).toThrow('Unable to find an element')
})
Loading