mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
more card context testing
This commit is contained in:
parent
130e9f276c
commit
232e957433
@ -78,8 +78,8 @@ export function useCardContext() {
|
|||||||
revision: cardChannel.revision,
|
revision: cardChannel.revision,
|
||||||
detailRevision: cardChannel.data.detailRevision,
|
detailRevision: cardChannel.data.detailRevision,
|
||||||
topicRevision: cardChannel.data.topicRevision,
|
topicRevision: cardChannel.data.topicRevision,
|
||||||
detail: cardChannel.data.detail,
|
detail: cardChannel.data.channelDetail,
|
||||||
summary: cardChannel.data.summary,
|
summary: cardChannel.data.channelSummary,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export function useCardContext() {
|
|||||||
try {
|
try {
|
||||||
const { server, token, guid } = access.current;
|
const { server, token, guid } = access.current;
|
||||||
const entry = cards.current.get(cardId);
|
const entry = cards.current.get(cardId);
|
||||||
if (entry?.card?.detail === 'connected') {
|
if (entry?.card?.detail.status === 'connected') {
|
||||||
const card = await getCard(server, token, cardId);
|
const card = await getCard(server, token, cardId);
|
||||||
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
|
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
|
||||||
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
|
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
|
||||||
@ -165,7 +165,7 @@ export function useCardContext() {
|
|||||||
entry.card.detailRevision = item.detailRevision;
|
entry.card.detailRevision = item.detailRevision;
|
||||||
await store.actions.setCardItemDetail(guid, card.id, entry.card.detailRevision, entry.card.detail);
|
await store.actions.setCardItemDetail(guid, card.id, entry.card.detailRevision, entry.card.detail);
|
||||||
}
|
}
|
||||||
if (entry.card.detail?.state === 'connected' && !entry.card.offsync) {
|
if (entry.card.detail?.status === 'connected' && !entry.card.offsync) {
|
||||||
try {
|
try {
|
||||||
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = item;
|
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = item;
|
||||||
const cardRevision = { view: notifiedView, profile: notifiedProfile, article: notifiedArticle, channel: notifiedChannel };
|
const cardRevision = { view: notifiedView, profile: notifiedProfile, article: notifiedArticle, channel: notifiedChannel };
|
||||||
@ -230,23 +230,35 @@ export function useCardContext() {
|
|||||||
for (let channel of delta) {
|
for (let channel of delta) {
|
||||||
if (channel.data) {
|
if (channel.data) {
|
||||||
const channelItem = setCardChannelItem(channel);
|
const channelItem = setCardChannelItem(channel);
|
||||||
const channelEntry = entry.channels.get(channel.id) || {};
|
const channelEntry = entry.channels.get(channel.id) || { channelId: channel.id };
|
||||||
const { detailRevision, topicRevision } = channelEntry;
|
const { detailRevision, topicRevision } = channelEntry;
|
||||||
if (item.detailRevision !== detailRevision) {
|
if (channelItem.detailRevision !== detailRevision) {
|
||||||
channelEntry.detail = await getContactChannelDetail(cardServer, cardToken, channel.id);
|
if (channelItem.detail) {
|
||||||
channelEntry.detailRevision = detailRevision;
|
channelEntry.detail = channelItem.detail;
|
||||||
await store.actions.setCardChannelItemDetail(guid, cardId, channel.id, channelEntry.detailRevision, channelEntry.detail);
|
}
|
||||||
|
else {
|
||||||
|
channelEntry.detail = await getContactChannelDetail(cardServer, cardToken, channel.id);
|
||||||
|
}
|
||||||
|
channelEntry.unsealedDetail = null;
|
||||||
|
channelEntry.detailRevision = channelItem.detailRevision;
|
||||||
|
await store.actions.setCardChannelItemDetail(guid, cardId, channel.id, channelItem.detailRevision, channelEntry.detail);
|
||||||
}
|
}
|
||||||
if (item.topicRevision !== topicRevision) {
|
if (channelItem.topicRevision !== topicRevision) {
|
||||||
channelEntry.summary = await getContactChannelSummary(cardServer, cardToken, channel.id);
|
if (channelItem.summary) {
|
||||||
channelEntry.topicRevision = topicRevision;
|
channelEntry.summary = channelItem.summary;
|
||||||
await store.actions.setCardChannelItemSummary(guid, cardId, channel.id, channelEntry.topicRevision, channelEntry.summary);
|
}
|
||||||
|
else {
|
||||||
|
channelEntry.summary = await getContactChannelSummary(cardServer, cardToken, channel.id);
|
||||||
|
}
|
||||||
|
channelEntry.unsealedSummary = null;
|
||||||
|
channelEntry.topicRevision = channelItem.topicRevision;
|
||||||
|
await store.actions.setCardChannelItemSummary(guid, cardId, channel.id, channelItem.topicRevision, channelEntry.summary);
|
||||||
}
|
}
|
||||||
entry.card.notifiedChannel = cardRevision.channel;
|
entry.card.notifiedChannel = cardRevision.channel;
|
||||||
await store.actions.setCardItemNotifiedChannel(guid, cardId, channelRevision.channel);
|
await store.actions.setCardItemNotifiedChannel(guid, cardId, cardRevision.channel);
|
||||||
entry.card.notifiedView = cardRevision.view;
|
entry.card.notifiedView = cardRevision.view;
|
||||||
await store.actions.setCardItemNotifiedView(guid, cardId, channelRevision.view);
|
await store.actions.setCardItemNotifiedView(guid, cardId, cardRevision.view);
|
||||||
entry.channel.set(channel.id, channelEntry);
|
entry.channels.set(channel.id, channelEntry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await store.actions.clearCardChannelTopicItems(guid, card.id, channel.id);
|
await store.actions.clearCardChannelTopicItems(guid, card.id, channel.id);
|
||||||
|
@ -15,6 +15,10 @@ function CardView() {
|
|||||||
setRenderCount(renderCount + 1);
|
setRenderCount(renderCount + 1);
|
||||||
const rendered = [];
|
const rendered = [];
|
||||||
card.state.cards.forEach((value) => {
|
card.state.cards.forEach((value) => {
|
||||||
|
const chanels = [];
|
||||||
|
value.channels.forEach((value) => {
|
||||||
|
console.log(value);
|
||||||
|
});
|
||||||
rendered.push(<Text key={value.card.cardId} testID={value.card.cardId}>{ value.card.profile.handle }</Text>);
|
rendered.push(<Text key={value.card.cardId} testID={value.card.cardId}>{ value.card.profile.handle }</Text>);
|
||||||
});
|
});
|
||||||
setCards(rendered);
|
setCards(rendered);
|
||||||
@ -42,8 +46,12 @@ const realFetchWithCustomTimeout = fetchUtil.fetchWithCustomTimeout;
|
|||||||
let fetchCards;
|
let fetchCards;
|
||||||
let fetchDetail;
|
let fetchDetail;
|
||||||
let fetchProfile;
|
let fetchProfile;
|
||||||
|
let fetchCardChannels;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fetchCards = [];
|
fetchCards = [];
|
||||||
|
fetchDetail = {};
|
||||||
|
fetchProfile = {};
|
||||||
|
fetchCardChannels = [];
|
||||||
|
|
||||||
const mockUseContext = jest.fn().mockImplementation((ctx) => {
|
const mockUseContext = jest.fn().mockImplementation((ctx) => {
|
||||||
return useTestStoreContext();
|
return useTestStoreContext();
|
||||||
@ -68,6 +76,11 @@ beforeEach(() => {
|
|||||||
json: () => Promise.resolve(fetchDetail)
|
json: () => Promise.resolve(fetchDetail)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (url.startsWith('https://test.org/content/channels?contact')) {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => Promise.resolve(fetchCardChannels)
|
||||||
|
});
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
json: () => Promise.resolve([])
|
json: () => Promise.resolve([])
|
||||||
@ -85,7 +98,7 @@ afterEach(() => {
|
|||||||
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
|
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add, update, and remove', async () => {
|
test('add, update, and remove card', async () => {
|
||||||
|
|
||||||
render(<CardTestApp />)
|
render(<CardTestApp />)
|
||||||
|
|
||||||
@ -182,5 +195,70 @@ test('add, update, and remove', async () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('add, update, and remove channel', async () => {
|
||||||
|
|
||||||
|
render(<CardTestApp />)
|
||||||
|
|
||||||
|
fetchCards = [{
|
||||||
|
id: '000a',
|
||||||
|
revision: 1,
|
||||||
|
data: {
|
||||||
|
detailRevision: 2,
|
||||||
|
profileRevision: 3,
|
||||||
|
notifiedProfile: 3,
|
||||||
|
notifiedArticle: 5,
|
||||||
|
notifiedChannel: 6,
|
||||||
|
notifiedView: 7,
|
||||||
|
cardDetail: { status: 'connected', statusUpdate: 136, token: '01ab', },
|
||||||
|
cardProfile: { guid: '01ab23', handle: 'test1', name: 'tester', imageSet: false,
|
||||||
|
seal: 'abc', version: '1.1.1', node: 'test.org' },
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const card = screen.getByTestId('card').props.card;
|
||||||
|
await card.actions.setSession({ guid: 'abc', server: 'test.org', token: '123' });
|
||||||
|
await card.actions.setRevision(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(async () => {
|
||||||
|
expect(screen.getByTestId('card').props.children).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
fetchCardChannels = [{
|
||||||
|
id: '01',
|
||||||
|
revision: 1,
|
||||||
|
data: {
|
||||||
|
detailRevision: 1,
|
||||||
|
topicRevision: 1,
|
||||||
|
channelDetail: {
|
||||||
|
dataType: 'superbasic',
|
||||||
|
data: 'testchannel',
|
||||||
|
},
|
||||||
|
channelSummary: {
|
||||||
|
dataType: 'superbasictopic',
|
||||||
|
data: 'testtopic',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
const card = screen.getByTestId('card').props.card;
|
||||||
|
await card.actions.setRevision(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
fetchCards = [{
|
||||||
|
id: '000a',
|
||||||
|
revision: 1,
|
||||||
|
data: {
|
||||||
|
detailRevision: 2,
|
||||||
|
profileRevision: 3,
|
||||||
|
notifiedProfile: 3,
|
||||||
|
notifiedArticle: 5,
|
||||||
|
notifiedChannel: 7,
|
||||||
|
notifiedView: 7,
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user