mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
extending card context webapp test
This commit is contained in:
parent
6c4fc82202
commit
5ab3e9ee7a
@ -63,7 +63,10 @@ export function useCardContext() {
|
||||
try {
|
||||
const token = access.current;
|
||||
const card = cards.current.get(card.id);
|
||||
await syncCard(token, card);
|
||||
if (card.data.cardDetail.status === 'connected') {
|
||||
await syncCard(token, card);
|
||||
}
|
||||
card.offsync = false;
|
||||
cards.current.set(card.id, card);
|
||||
}
|
||||
catch(err) {
|
||||
|
@ -46,15 +46,23 @@ const realFetchWithTimeout = fetchUtil.fetchWithTimeout;
|
||||
const realFetchWithCustomTimeout = fetchUtil.fetchWithCustomTimeout;
|
||||
|
||||
let statusCards;
|
||||
let fetchCards;
|
||||
let statusMessage;
|
||||
let statusDetail;
|
||||
let statusProfile;
|
||||
let fetchCards;
|
||||
let fetchMessage;
|
||||
let fetchDetail;
|
||||
let fetchProfile;
|
||||
beforeEach(() => {
|
||||
|
||||
statusMessage = 200;
|
||||
fetchMessage =
|
||||
statusCards = 200;
|
||||
fetchCards =[];
|
||||
fetchCards = [];
|
||||
statusDetail = 200;
|
||||
fetchDetail = {};
|
||||
statusProfile = 200;
|
||||
fetchProfile = {};
|
||||
const mockFetch = jest.fn().mockImplementation((url, options) => {
|
||||
|
||||
const params = url.split('/');
|
||||
@ -65,6 +73,20 @@ beforeEach(() => {
|
||||
json: () => Promise.resolve(fetchMessage),
|
||||
});
|
||||
}
|
||||
else if (params[4]?.split('?')[0] === 'detail') {
|
||||
return Promise.resolve({
|
||||
url: 'getDetail',
|
||||
status: statusDetail,
|
||||
json: () => Promise.resolve(fetchDetail),
|
||||
});
|
||||
}
|
||||
else if (params[4]?.split('?')[0] === 'profile') {
|
||||
return Promise.resolve({
|
||||
url: 'getProfile',
|
||||
status: statusProfile,
|
||||
json: () => Promise.resolve(fetchProfile),
|
||||
});
|
||||
}
|
||||
else if (params[2]?.split('?')[0] === 'cards') {
|
||||
return Promise.resolve({
|
||||
url: 'getCards',
|
||||
@ -130,6 +152,50 @@ test('add, update, remove card', async () => {
|
||||
expect(screen.getByTestId('token').textContent).toBe('01ab');
|
||||
});
|
||||
|
||||
fetchCards = [{
|
||||
id: '000a',
|
||||
revision: 2,
|
||||
data: {
|
||||
detailRevision: 3,
|
||||
profileRevision: 4,
|
||||
notifiedProfile: 3,
|
||||
notifiedArticle: 5,
|
||||
notifiedChannel: 6,
|
||||
notifiedView: 7,
|
||||
},
|
||||
}];
|
||||
|
||||
fetchProfile = {
|
||||
guid: '01ab23',
|
||||
name: 'tested',
|
||||
};
|
||||
|
||||
fetchDetail = {
|
||||
status: 'confirmed',
|
||||
};
|
||||
|
||||
await act( async () => {
|
||||
cardContext.actions.setRevision(2);
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(screen.getByTestId('name').textContent).toBe('tested');
|
||||
expect(screen.getByTestId('status').textContent).toBe('confirmed');
|
||||
});
|
||||
|
||||
fetchCards = [{
|
||||
id: '000a',
|
||||
revision: 3,
|
||||
}];
|
||||
|
||||
await act( async () => {
|
||||
cardContext.actions.setRevision(3);
|
||||
});
|
||||
|
||||
await waitFor(async () => {
|
||||
expect(screen.getByTestId('cards').children).toHaveLength(0);
|
||||
});
|
||||
|
||||
act(() => {
|
||||
cardContext.actions.clearToken();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user