[FIX] Cannot read property 'fetch' of undefined on ThreadMessagesView (#4557)

* [FIX] Cannot read property 'fetch' of undefined on ThreadMessagesView

* added e2e test

* change from _raw to _id

* test thread messages view with a thread created
This commit is contained in:
Reinaldo Neto 2022-12-02 14:06:14 -03:00 committed by GitHub
parent 87a3f85feb
commit cbd9b27cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -142,7 +142,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
), ),
headerRight: () => ( headerRight: () => (
<HeaderButton.Container> <HeaderButton.Container>
<HeaderButton.Item iconName='search' onPress={this.onSearchPress} /> <HeaderButton.Item iconName='search' onPress={this.onSearchPress} testID='thread-messages-view-search-icon' />
</HeaderButton.Container> </HeaderButton.Container>
) )
}; };
@ -242,7 +242,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
const { subscription } = this.state; const { subscription } = this.state;
// if there's no subscription, manage data on this.state.messages // if there's no subscription, manage data on this.state.messages
// note: sync will never be called without subscription // note: sync will never be called without subscription
if (!subscription) { if (!subscription._id) {
this.setState(({ messages }) => ({ messages: [...messages, ...update] })); this.setState(({ messages }) => ({ messages: [...messages, ...update] }));
return; return;
} }

View File

@ -1,5 +1,6 @@
import data from '../../data'; import data from '../../data';
import { navigateToLogin, login, tapBack, sleep } from '../../helpers/app'; import { navigateToLogin, login, tapBack, sleep } from '../../helpers/app';
import { sendMessage } from '../../helpers/data_setup';
const testuser = data.users.regular; const testuser = data.users.regular;
@ -26,6 +27,13 @@ describe('Join room from directory', () => {
}); });
describe('Usage', () => { describe('Usage', () => {
const threadMessage = `thread-${data.random}`;
before(async () => {
const result = await sendMessage(data.users.alternate, data.channels.detoxpublic.name, threadMessage);
const threadId = result.message._id;
await sendMessage(data.users.alternate, result.message.rid, data.random, threadId);
});
it('should tap directory', async () => { it('should tap directory', async () => {
await element(by.id('rooms-list-view-directory')).tap(); await element(by.id('rooms-list-view-directory')).tap();
await waitFor(element(by.id('directory-view'))) await waitFor(element(by.id('directory-view')))
@ -37,6 +45,20 @@ describe('Join room from directory', () => {
await navigateToRoom(data.channels.detoxpublic.name); await navigateToRoom(data.channels.detoxpublic.name);
}); });
it('should navigate to thread messages view and load messages', async () => {
await waitFor(element(by.id('room-view-header-threads')))
.toBeVisible()
.withTimeout(2000);
await element(by.id('room-view-header-threads')).tap();
await waitFor(element(by.id(`thread-messages-view-${threadMessage}`)))
.toBeVisible()
.withTimeout(2000);
await tapBack();
await waitFor(element(by.id('room-view-header-threads')))
.toBeVisible()
.withTimeout(2000);
});
it('should search user and navigate', async () => { it('should search user and navigate', async () => {
await tapBack(); await tapBack();
await element(by.id('rooms-list-view-directory')).tap(); await element(by.id('rooms-list-view-directory')).tap();