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