mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
cleanup conversation test
This commit is contained in:
parent
b6c10078a6
commit
af3cd6d28e
21
net/web/src/context/cardUtil.js
Normal file
21
net/web/src/context/cardUtil.js
Normal file
@ -0,0 +1,21 @@
|
||||
export function getCardByGuid(cards, guid) {
|
||||
let card = null;
|
||||
cards.current.forEach((value, key, map) => {
|
||||
if(value?.data?.cardProfile?.guid === guid) {
|
||||
card = value;
|
||||
}
|
||||
});
|
||||
return card;
|
||||
}
|
||||
|
||||
export getProfileByGuid: (cards, guid) => {
|
||||
const card = getCardByGuid(guid);
|
||||
if (card?.data?.cardProfile) {
|
||||
const { name, handle, imageSet } = card.data.cardProfile;
|
||||
const revision = card.data.profileRevision;
|
||||
const cardId = card.id;
|
||||
return { cardId, revision, name, handle, imageSet, revision }
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -64,6 +64,8 @@ let statusCardChannels;
|
||||
let fetchCardChannels;
|
||||
let statusTopics;
|
||||
let fetchTopics;
|
||||
let statusTopic;
|
||||
let fetchTopic;
|
||||
beforeEach(() => {
|
||||
|
||||
statusCards = 200;
|
||||
@ -74,10 +76,11 @@ beforeEach(() => {
|
||||
fetchCardChannels = [];
|
||||
statusTopics = 200;
|
||||
fetchTopics = [];
|
||||
statusTopic = 200;
|
||||
fetchTopic = {};
|
||||
|
||||
const mockFetch = jest.fn().mockImplementation((url, options) => {
|
||||
const params = url.split('/');
|
||||
console.log(params, options);
|
||||
if (params[2].startsWith('channels?agent')) {
|
||||
return Promise.resolve({
|
||||
url: 'getChannels',
|
||||
@ -99,6 +102,13 @@ beforeEach(() => {
|
||||
json: () => Promise.resolve(fetchCards),
|
||||
});
|
||||
}
|
||||
else if (params[4] === 'topics') {
|
||||
return Promise.resolve({
|
||||
url: 'getTopic',
|
||||
status: statusTopic,
|
||||
json: () => Promise.resolve(fetchTopic),
|
||||
});
|
||||
}
|
||||
else if (params[6]?.split('?')[0] === 'topics' || params[4]?.split('?')[0] === 'topics') {
|
||||
return Promise.resolve({
|
||||
url: 'getTopics',
|
||||
@ -108,11 +118,12 @@ beforeEach(() => {
|
||||
});
|
||||
}
|
||||
else {
|
||||
console.log(params, options);
|
||||
return Promise.resolve({
|
||||
url: 'endpoint',
|
||||
status: 200,
|
||||
headers: new Map(),
|
||||
json: () => Promise.resolve([]),
|
||||
json: () => Promise.resolve({}),
|
||||
});
|
||||
}
|
||||
|
||||
@ -126,7 +137,7 @@ afterEach(() => {
|
||||
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
|
||||
});
|
||||
|
||||
test('conversation', async() => {
|
||||
test('add, update, and remove topic', async() => {
|
||||
|
||||
render(<ConversationTestApp />);
|
||||
|
||||
@ -234,6 +245,92 @@ test('conversation', async() => {
|
||||
expect(screen.getByTestId('data').textContent).toBe('agenttopicdata');
|
||||
});
|
||||
|
||||
fetchChannels = [
|
||||
{ id: '123', revision: 2, data: {
|
||||
detailRevision: 3,
|
||||
topicRevision: 6,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
fetchTopics = [
|
||||
{ id: '888', revision: 5, data: {
|
||||
detailRevision: 3,
|
||||
tagRevision: 0,
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
fetchTopic = { id: '888', revision: 5, data: {
|
||||
detailRevision: 4,
|
||||
tagRevision: 0,
|
||||
topicDetail: {
|
||||
guid: '0123',
|
||||
dataType: 'topictype',
|
||||
data: 'agenttopicdata2',
|
||||
created: 1,
|
||||
updated: 1,
|
||||
status: 'confirmed',
|
||||
transform: 'complete',
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
await act(async () => {
|
||||
channelContext.actions.setRevision(2);
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(screen.getByTestId('topics').children).toHaveLength(1);
|
||||
expect(screen.getByTestId('data').textContent).toBe('agenttopicdata');
|
||||
});
|
||||
|
||||
fetchChannels = [
|
||||
{ id: '123', revision: 2, data: {
|
||||
detailRevision: 3,
|
||||
topicRevision: 7,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
fetchTopics = [
|
||||
{ id: '888', revision: 5, data: {
|
||||
detailRevision: 4,
|
||||
tagRevision: 0,
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
await act(async () => {
|
||||
channelContext.actions.setRevision(3);
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(screen.getByTestId('topics').children).toHaveLength(1);
|
||||
expect(screen.getByTestId('data').textContent).toBe('agenttopicdata2');
|
||||
});
|
||||
|
||||
fetchChannels = [
|
||||
{ id: '123', revision: 2, data: {
|
||||
detailRevision: 3,
|
||||
topicRevision: 8,
|
||||
}
|
||||
},
|
||||
];
|
||||
|
||||
fetchTopics = [
|
||||
{ id: '888', revision: 6 }
|
||||
];
|
||||
|
||||
await act(async () => {
|
||||
channelContext.actions.setRevision(4);
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(screen.getByTestId('topics').children).toHaveLength(0);
|
||||
});
|
||||
|
||||
|
||||
act(() => {
|
||||
cardContext.actions.clearToken();
|
||||
channelContext.actions.clearToken();
|
||||
|
Loading…
Reference in New Issue
Block a user