extending conversation test

This commit is contained in:
Roland Osborne 2023-01-10 15:35:57 -08:00
parent 6d3735e434
commit b6c10078a6
3 changed files with 66 additions and 7 deletions

View File

@ -179,13 +179,13 @@ export function useChannelContext() {
await setChannelTopicSubject(access.current, channelId, topicId, type, subject);
await resync();
},
getChannelTopicAssetUrl: (channelId, topicId, assetId) => {
getTopicAssetUrl: (channelId, topicId, assetId) => {
return getChannelTopicAssetUrl(access.current, channelId, topicId, assetId);
},
getChannelTopics: async (channelId, revision, count, begin, end) => {
getTopics: async (channelId, revision, count, begin, end) => {
return await getChannelTopics(access.current, channelId, revision, count, begin, end);
},
getChannelTopic: async (channelId, topicId) => {
getTopic: async (channelId, topicId) => {
return await getChannelTopic(access.current, channelId, topicId);
},
resync: async () => {

View File

@ -245,6 +245,7 @@ export function useConversationContext() {
topics.current.set(topic.id, cur);
}
}
setTopicRevision.current = topicRevision;
updateState({ offsync: false, topics: topics.current });
}

View File

@ -27,14 +27,12 @@ function ConversationView() {
entries.forEach(entry => {
rendered.push(
<div key={entry.id} data-testid="topic">
<span data-testid="name">{ entry.data.cardProfile.name }</span>
<span data-testid="status">{ entry.data.cardDetail.status }</span>
<span data-testid="token">{ entry.data.cardDetail.token }</span>
<span data-testid="data">{entry.data.topicDetail.data}</span>
</div>);
});
setTopics(rendered);
setRenderCount(renderCount + 1);
}, [card.state])
}, [conversation.state])
return (
<div data-testid="topics" count={renderCount} offsync={card.state.offsync.toString()}>
@ -64,6 +62,8 @@ let statusChannels;
let fetchChannels;
let statusCardChannels;
let fetchCardChannels;
let statusTopics;
let fetchTopics;
beforeEach(() => {
statusCards = 200;
@ -72,6 +72,8 @@ beforeEach(() => {
fetchChannels = [];
statusCardChannels = 200;
fetchCardChannels = [];
statusTopics = 200;
fetchTopics = [];
const mockFetch = jest.fn().mockImplementation((url, options) => {
const params = url.split('/');
@ -97,6 +99,14 @@ beforeEach(() => {
json: () => Promise.resolve(fetchCards),
});
}
else if (params[6]?.split('?')[0] === 'topics' || params[4]?.split('?')[0] === 'topics') {
return Promise.resolve({
url: 'getTopics',
status: statusTopics,
headers: new Map(),
json: () => Promise.resolve(fetchTopics),
});
}
else {
return Promise.resolve({
url: 'endpoint',
@ -172,10 +182,58 @@ test('conversation', async() => {
channelContext.actions.setRevision(1);
});
fetchTopics = [
{ id: '888', revision: 5, data: {
detailRevision: 3,
tagRevision: 0,
topicDetail: {
guid: '0123',
dataType: 'topictype',
data: 'contacttopicdata',
created: 1,
updated: 1,
status: 'confirmed',
transform: 'complete',
},
}
}
];
await act(async () => {
conversationContext.actions.setChannel('000a', 'aabb');
});
await waitFor(async () => {
expect(screen.getByTestId('topics').children).toHaveLength(1);
expect(screen.getByTestId('data').textContent).toBe('contacttopicdata');
});
fetchTopics = [
{ id: '888', revision: 5, data: {
detailRevision: 3,
tagRevision: 0,
topicDetail: {
guid: '0123',
dataType: 'topictype',
data: 'agenttopicdata',
created: 1,
updated: 1,
status: 'confirmed',
transform: 'complete',
},
}
}
];
await act(async () => {
conversationContext.actions.setChannel(null, '123');
});
await waitFor(async () => {
expect(screen.getByTestId('topics').children).toHaveLength(1);
expect(screen.getByTestId('data').textContent).toBe('agenttopicdata');
});
act(() => {
cardContext.actions.clearToken();
channelContext.actions.clearToken();