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

Fixed contact query issue #1271

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/containers/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const Chat: React.SFC<ChatProps> = ({ contactId, collectionId, savedSearc
</Typography>
</div>
</Link>
<Link to="/chat/saved-searches">
<Link to="/chat/saved-searches/">
<div className={styles.Title}>
<div className={styles.IconBackground}>
<img
Expand Down
56 changes: 55 additions & 1 deletion src/containers/Chat/ChatMessages/ChatMessages.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, within } from '@testing-library/react';
import { render, within, screen } from '@testing-library/react';
import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client';
import { ChatMessages } from './ChatMessages';
import { fireEvent, waitFor } from '@testing-library/dom';
Expand All @@ -17,6 +17,15 @@ class ResizeObserver {
disconnect() {}
}

const defineUrl = (url: string) => {
Object.defineProperty(window, 'location', {
value: {
href: url,
},
writable: true,
});
};

window.ResizeObserver = ResizeObserver;

const body = {
Expand Down Expand Up @@ -362,6 +371,51 @@ test('Load more messages', async () => {
});
});

test('Should render for multi-search', async () => {
defineUrl('http://localhost:3000/chat/2?search=8');

const { getByTestId } = render(chatMessages);

await waitFor(() => {
const container: any = document.querySelector('.messageContainer');
fireEvent.scroll(container, { target: { scrollY: 0 } });
fireEvent.click(getByTestId('loadMoreMessages'));
});
});

test('If search query gives error', async () => {
const searchQuery = {
query: SEARCH_QUERY,
variables: {
filter: {},
contactOpts: { limit: DEFAULT_CONTACT_LIMIT },
messageOpts: { limit: DEFAULT_MESSAGE_LIMIT },
},
result: {
errors: [new Error('An error occurred')],
},
data: null,
};

cache.writeQuery(searchQuery);
const client = new ApolloClient({
cache: cache,
assumeImmutableResults: true,
});

const chatMessages = (
<ApolloProvider client={client}>
<ChatMessages contactId="2" />
</ApolloProvider>
);

render(chatMessages);

await waitFor(() => {
screen.getAllByText('Effie Cormier');
});
});

test('send message to contact', async () => {
const spy = jest.spyOn(ChatInput, 'ChatInput');

Expand Down
2 changes: 1 addition & 1 deletion src/route/AuthenticatedRoute/AuthenticatedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const routeAdmin = (
<Route path="/webhook-logs" exact component={WebhookLogsList} />
<Route path="/notifications" exact component={NotificationList} />
<Route exact path="/chat/collection" component={() => <Chat collectionId={-1} />} />
<Route exact path="/chat/saved-searches" component={() => <Chat savedSearches />} />
<Route exact path="/chat/saved-searches/" component={() => <Chat savedSearches />} />
<Route
exact
path="/chat/saved-searches/:contactId"
Expand Down