mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
adding converasation test
This commit is contained in:
parent
f3602d0c68
commit
445f411dc3
@ -7,7 +7,6 @@ import { StoreContext } from 'context/StoreContext';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
import { isUnsealed, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
||||
|
||||
import { decryptTopicSubject } from 'context/sealUtil';
|
||||
import { getProfileByGuid } from 'context/cardUtil';
|
||||
|
||||
@ -19,7 +18,6 @@ export function useConversation(cardId, channelId) {
|
||||
uploadError: false,
|
||||
uploadPercent: 0,
|
||||
topics: [],
|
||||
loading: false,
|
||||
sealed: false,
|
||||
contentKey: null,
|
||||
busy: false,
|
||||
@ -107,9 +105,8 @@ export function useConversation(cardId, channelId) {
|
||||
const { card, channel } = conversationId.current;
|
||||
loading.current = true;
|
||||
conversationId.current = null;
|
||||
updateState({ loading: true, contentKey: null });
|
||||
updateState({ contentKey: null });
|
||||
await conversation.actions.setChannel(card, channel);
|
||||
updateState({ loading: false });
|
||||
loading.current = false;
|
||||
await setChannel();
|
||||
}
|
||||
|
77
net/web/test/Thread.test.js
Normal file
77
net/web/test/Thread.test.js
Normal file
@ -0,0 +1,77 @@
|
||||
import React, { useState, useEffect, useContext } from 'react';
|
||||
import {render, act, screen, waitFor, fireEvent} from '@testing-library/react'
|
||||
import { AppContextProvider } from 'context/AppContext';
|
||||
import { AccountContextProvider } from 'context/AccountContext';
|
||||
import { ProfileContext, ProfileContextProvider } from 'context/ProfileContext';
|
||||
import { StoreContextProvider } from 'context/StoreContext';
|
||||
import { ViewportContextProvider } from 'context/ViewportContext';
|
||||
import { ConversationContextProvider } from 'context/ConversationContext';
|
||||
import { CardContextProvider } from 'context/CardContext';
|
||||
import { UploadContextProvider } from 'context/UploadContext';
|
||||
import { useConversation } from 'session/conversation/useConversation.hook';
|
||||
|
||||
import * as fetchUtil from 'api/fetchUtil';
|
||||
|
||||
function ThreadView() {
|
||||
const { state, actions } = useConversation('card01', 'channel01');
|
||||
const [renderCount, setRenderCount] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const rendered = [];
|
||||
setRenderCount(renderCount + 1);
|
||||
}, [state]);
|
||||
|
||||
return (
|
||||
<div data-testid="thread" count={renderCount}></div>
|
||||
);
|
||||
}
|
||||
|
||||
function ThreadTestApp() {
|
||||
return (
|
||||
<StoreContextProvider>
|
||||
<UploadContextProvider>
|
||||
<CardContextProvider>
|
||||
<ProfileContextProvider>
|
||||
<AccountContextProvider>
|
||||
<ViewportContextProvider>
|
||||
<ConversationContextProvider>
|
||||
<AppContextProvider>
|
||||
<ThreadView />
|
||||
</AppContextProvider>
|
||||
</ConversationContextProvider>
|
||||
</ViewportContextProvider>
|
||||
</AccountContextProvider>
|
||||
</ProfileContextProvider>
|
||||
</CardContextProvider>
|
||||
</UploadContextProvider>
|
||||
</StoreContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
let updated;
|
||||
const realFetchWithTimeout = fetchUtil.fetchWithTimeout;
|
||||
const realFetchWithCustomTimeout = fetchUtil.fetchWithCustomTimeout;
|
||||
beforeEach(() => {
|
||||
let updated = false;
|
||||
const mockFetch = jest.fn().mockImplementation((url, options) => {
|
||||
if (options.method === 'PUT') {
|
||||
updated = true;
|
||||
}
|
||||
return Promise.resolve({
|
||||
json: () => Promise.resolve({ name: updated ? 'tested' : 'tester' })
|
||||
});
|
||||
});
|
||||
fetchUtil.fetchWithTimeout = mockFetch;
|
||||
fetchUtil.fetchWithCustomTimeout = mockFetch;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fetchUtil.fetchWithTimeout = realFetchWithTimeout;
|
||||
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
|
||||
});
|
||||
|
||||
test('add, update, remove topic', async () => {
|
||||
|
||||
render(<ThreadTestApp />);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user