Skip to content

Commit

Permalink
Fix push queue tests (#2661)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrofbass authored Dec 2, 2024
1 parent e39ebc4 commit 8e74f70
Showing 1 changed file with 55 additions and 86 deletions.
141 changes: 55 additions & 86 deletions src/redux-middleware/__tests__/pushQueue.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,62 @@
// import _ from 'lodash'
// import SimplePath from '../../@types/SimplePath'
// import deleteThought from '../../actions/deleteThought'
// import editThought from '../../actions/editThought'
// import importText from '../../actions/importText'
// import { HOME_PATH, HOME_TOKEN } from '../../constants'
// import db from '../../data-providers/yjs'
// import contextToPath from '../../selectors/contextToPath'
// import store from '../../stores/app'
// import contextToThought from '../../test-helpers/contextToThought'
import createTestApp, { cleanupTestApp } from '../../test-helpers/createTestApp'
import { act } from 'react'
import { importTextActionCreator as importText } from '../../actions/importText'
import getLexemeFromProvider from '../../data-providers/data-helpers/getLexeme'
import db from '../../data-providers/yjs/thoughtspace'
import getLexemeFromState from '../../selectors/getLexeme'
import store from '../../stores/app'
import contextToThought from '../../test-helpers/contextToThought'
import createTestApp, { cleanupTestApp, refreshTestApp } from '../../test-helpers/createTestApp'
import dispatch from '../../test-helpers/dispatch'
import { editThoughtByContextActionCreator as editThought } from '../../test-helpers/editThoughtByContext'

// import testTimer from '../../test-helpers/testTimer'
beforeEach(createTestApp)
afterEach(cleanupTestApp)

// import head from '../../util/head'
// import parentOf from '../../util/parentOf'
// Current functionality is broken in main and won't be fixed soon so this test is skipped.
it.skip('editing a thought should load the lexeme and merge contexts', async () => {
// Related issue: https://github.com/cybersemics/em/issues/1074
await dispatch(
importText({
text: `
- g
- h
- a
- b
- c
- d
- e
- f`,
}),
)

/*
Note: sinon js fake timer is used to overcome some short comming we have with jest's fake timer.
For details: https://github.com/cybersemics/em/issues/919#issuecomment-739135971
*/
await act(vi.runOnlyPendingTimersAsync)

// const fakeTimer = testTimer()
expect((await getLexemeFromProvider(db, 'f'))?.contexts).toHaveLength(1)

beforeEach(createTestApp)
afterEach(cleanupTestApp)
const thoughtH = contextToThought(store.getState(), ['g', 'h'])
const thoughtF = contextToThought(store.getState(), ['a', 'b', 'c', 'd', 'e', 'f'])

// TODO: test stopped working with yjs
// currently all lexemes are loaded in memory
it.skip('editing a thought should load the lexeme and merge contexts', async () => {
// // Related issue: https://github.com/cybersemics/em/issues/1074
//
// fakeTimer.useFakeTimer()
//
// store.dispatch(
// importText({
// text: `
// - g
// - h
// - a
// - b
// - c
// - d
// - e
// - f`,
// }),
// )
//
// await fakeTimer.runAllAsync()
//
// await fakeTimer.useRealTimer()
//
// expect((await getLexemeDb(db, 'f'))?.contexts).toHaveLength(1)
//
// const thoughtH = contextToThought(store.getState(), ['g', 'h'])
// const thoughtF = contextToThought(store.getState(), ['a', 'b', 'c', 'd', 'e', 'f'])
//
// await refreshTestApp()
//
// fakeTimer.useFakeTimer()
//
// // lexeme for 'f' should not be loaded into the state yet.
// expect(getLexemeState(store.getState(), 'f')).toBeFalsy()
//
// const pathGH = contextToPath(store.getState(), ['g', 'h']) as SimplePath
//
// store.dispatch(
// editThought({
// oldValue: 'h',
// newValue: 'f',
// path: pathGH,
// }),
// )
// await fakeTimer.runAllAsync()
//
// fakeTimer.useRealTimer()
//
// // existing Lexemes should be pulled and synced after thought is edited.
//
// // both db and state should have same updated lexeme
// const thoughtContextsState = getLexemeState(store.getState(), 'f')?.contexts
//
// // Note: Thought h has been changed to f but the id remains the same
// // check that state has the correct contexts, ignoring order and ids
// expect(thoughtContextsState).toEqual(expect.arrayContaining([thoughtH?.id, thoughtF?.id]))
// expect(thoughtContextsState).toHaveLength(2)
//
// // check that db has the correct contexts, ignoring order and ids
// const thoughtContextsDb = (await getLexemeDb(db, 'f'))?.contexts
// expect(thoughtContextsDb).toEqual(expect.arrayContaining([thoughtH?.id, thoughtF?.id]))
//
// expect(thoughtContextsState).toHaveLength(2)
await refreshTestApp()
// lexeme for 'f' should not be loaded into the state yet.
expect(getLexemeFromState(store.getState(), 'f')).toBeFalsy()

await dispatch(editThought(['g', 'h'], 'f'))

await act(vi.runAllTimersAsync)

// existing Lexemes should be pulled and synced after thought is edited.

// both db and state should have same updated lexeme
const thoughtContextsState = getLexemeFromState(store.getState(), 'f')?.contexts

// Note: Thought h has been changed to f but the id remains the same
// check that state has the correct contexts, ignoring order and ids
expect(thoughtContextsState).toEqual(expect.arrayContaining([thoughtH?.id, thoughtF?.id]))
expect(thoughtContextsState).toHaveLength(2)

// check that db has the correct contexts, ignoring order and ids
const thoughtContextsDb = (await getLexemeFromProvider(db, 'f'))?.contexts
expect(thoughtContextsDb).toEqual(expect.arrayContaining([thoughtH?.id, thoughtF?.id]))

expect(thoughtContextsState).toHaveLength(2)
})

0 comments on commit 8e74f70

Please sign in to comment.