-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scrolling through unmeasured list items is difficult. However, by using the onScrollToIndexFailed callback, it's possible to scroll between measured list items, eventually landing at the target index. Unfortunately it's a bit janky, but it works. To ensure that all lines have been loaded before attempting to scroll to the target line, lines are force reloaded for the current buffer before attempting to scroll. When switching buffers, lines are (re)loaded as normal via changeCurrentBuffer. BufferContainer's componentDidUpdate will block scrolling until a state flag is reset after the lines for the notified buffer are (re)loaded.
- Loading branch information
Showing
11 changed files
with
462 additions
and
598 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,123 @@ | ||
import 'react-native'; | ||
import App from '../../src/usecase/App'; | ||
|
||
import { render } from '../../src/test-utils'; | ||
|
||
it('renders correctly', () => { | ||
const tree = render( | ||
<App | ||
disconnect={() => {}} | ||
fetchBufferInfo={() => {}} | ||
sendMessageToBuffer={() => {}} | ||
clearHotlistForBuffer={() => {}} | ||
/>, | ||
{ | ||
preloadedState: { | ||
buffers: { | ||
'8578d9c00': { | ||
full_name: 'irc.libera.#weechat', | ||
hidden: 0, | ||
id: '8578d9c00', | ||
local_variables: { | ||
channel: '#weechat', | ||
name: 'libera.#weechat', | ||
plugin: 'irc', | ||
type: 'channel' | ||
}, | ||
notify: 3, | ||
number: 2, | ||
pointers: ['8578d9c00'], | ||
short_name: '#weechat', | ||
title: '', | ||
type: 0 | ||
} | ||
import { act, render } from '../../src/test-utils'; | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { reducer } from '../../src/store'; | ||
import { AppState } from '../../src/store/app'; | ||
import { bufferNotificationAction } from '../../src/store/actions'; | ||
|
||
jest.mock('react-native-drawer-layout'); | ||
|
||
describe('App', () => { | ||
describe('on notification', () => { | ||
it('changes the current buffer to the notification buffer', () => { | ||
const bufferId = '86c417600'; | ||
const store = configureStore({ | ||
reducer, | ||
preloadedState: { | ||
buffers: { | ||
[bufferId]: { | ||
full_name: 'irc.libera.#weechat', | ||
hidden: 0, | ||
id: bufferId, | ||
local_variables: { | ||
channel: '#weechat', | ||
name: 'libera.#weechat', | ||
plugin: 'irc', | ||
type: 'channel' | ||
}, | ||
notify: 3, | ||
number: 2, | ||
pointers: [bufferId], | ||
short_name: '#weechat', | ||
title: '', | ||
type: 0 | ||
} | ||
}, | ||
app: { currentBufferId: null } as AppState | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
const clearHotlistForBuffer = jest.fn(); | ||
const fetchBufferInfo = jest.fn(); | ||
|
||
render( | ||
<App | ||
disconnect={() => {}} | ||
fetchBufferInfo={fetchBufferInfo} | ||
sendMessageToBuffer={() => {}} | ||
clearHotlistForBuffer={clearHotlistForBuffer} | ||
/>, | ||
{ store } | ||
); | ||
|
||
act(() => { | ||
store.dispatch( | ||
bufferNotificationAction({ | ||
bufferId, | ||
lineId: '8580dcc40', | ||
identifier: '1fb4fc1d-530b-466f-85be-de27772de0a9' | ||
}) | ||
); | ||
}); | ||
|
||
expect(store.getState().app.currentBufferId).toEqual(bufferId); | ||
expect(clearHotlistForBuffer).toHaveBeenCalledWith(null); | ||
expect(fetchBufferInfo).toHaveBeenCalledWith(bufferId); | ||
}); | ||
|
||
it('fetches buffer info if the notification is for the current buffer', () => { | ||
const bufferId = '86c417600'; | ||
const store = configureStore({ | ||
reducer, | ||
preloadedState: { | ||
buffers: { | ||
[bufferId]: { | ||
full_name: 'irc.libera.#weechat', | ||
hidden: 0, | ||
id: bufferId, | ||
local_variables: { | ||
channel: '#weechat', | ||
name: 'libera.#weechat', | ||
plugin: 'irc', | ||
type: 'channel' | ||
}, | ||
notify: 3, | ||
number: 2, | ||
pointers: [bufferId], | ||
short_name: '#weechat', | ||
title: '', | ||
type: 0 | ||
} | ||
}, | ||
app: { currentBufferId: bufferId } as AppState | ||
} | ||
}); | ||
const fetchBufferInfo = jest.fn(); | ||
const clearHotlistForBuffer = jest.fn(); | ||
|
||
render( | ||
<App | ||
disconnect={() => {}} | ||
fetchBufferInfo={fetchBufferInfo} | ||
sendMessageToBuffer={() => {}} | ||
clearHotlistForBuffer={clearHotlistForBuffer} | ||
/>, | ||
{ store } | ||
); | ||
|
||
act(() => { | ||
store.dispatch( | ||
bufferNotificationAction({ | ||
bufferId, | ||
lineId: '8580dcc40', | ||
identifier: '1fb4fc1d-530b-466f-85be-de27772de0a9' | ||
}) | ||
); | ||
}); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
expect(fetchBufferInfo).toHaveBeenCalledWith(bufferId); | ||
expect(clearHotlistForBuffer).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.