mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 04:59:16 +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 { CardContext } from 'context/CardContext';
|
||||||
import { ProfileContext } from 'context/ProfileContext';
|
import { ProfileContext } from 'context/ProfileContext';
|
||||||
import { isUnsealed, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
import { isUnsealed, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
||||||
|
|
||||||
import { decryptTopicSubject } from 'context/sealUtil';
|
import { decryptTopicSubject } from 'context/sealUtil';
|
||||||
import { getProfileByGuid } from 'context/cardUtil';
|
import { getProfileByGuid } from 'context/cardUtil';
|
||||||
|
|
||||||
@ -19,7 +18,6 @@ export function useConversation(cardId, channelId) {
|
|||||||
uploadError: false,
|
uploadError: false,
|
||||||
uploadPercent: 0,
|
uploadPercent: 0,
|
||||||
topics: [],
|
topics: [],
|
||||||
loading: false,
|
|
||||||
sealed: false,
|
sealed: false,
|
||||||
contentKey: null,
|
contentKey: null,
|
||||||
busy: false,
|
busy: false,
|
||||||
@ -107,9 +105,8 @@ export function useConversation(cardId, channelId) {
|
|||||||
const { card, channel } = conversationId.current;
|
const { card, channel } = conversationId.current;
|
||||||
loading.current = true;
|
loading.current = true;
|
||||||
conversationId.current = null;
|
conversationId.current = null;
|
||||||
updateState({ loading: true, contentKey: null });
|
updateState({ contentKey: null });
|
||||||
await conversation.actions.setChannel(card, channel);
|
await conversation.actions.setChannel(card, channel);
|
||||||
updateState({ loading: false });
|
|
||||||
loading.current = false;
|
loading.current = false;
|
||||||
await setChannel();
|
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