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,
|
||||
detailRevision: cardChannel.data.detailRevision,
|
||||
topicRevision: cardChannel.data.topicRevision,
|
||||
detail: cardChannel.data.detail,
|
||||
summary: cardChannel.data.summary,
|
||||
detail: cardChannel.data.channelDetail,
|
||||
summary: cardChannel.data.channelSummary,
|
||||
};
|
||||
};
|
||||
|
||||
@ -112,7 +112,7 @@ export function useCardContext() {
|
||||
try {
|
||||
const { server, token, guid } = access.current;
|
||||
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 { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
|
||||
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
|
||||
@ -165,7 +165,7 @@ export function useCardContext() {
|
||||
entry.card.detailRevision = item.detailRevision;
|
||||
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 {
|
||||
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = item;
|
||||
const cardRevision = { view: notifiedView, profile: notifiedProfile, article: notifiedArticle, channel: notifiedChannel };
|
||||
@ -230,23 +230,35 @@ export function useCardContext() {
|
||||
for (let channel of delta) {
|
||||
if (channel.data) {
|
||||
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;
|
||||
if (item.detailRevision !== detailRevision) {
|
||||
channelEntry.detail = await getContactChannelDetail(cardServer, cardToken, channel.id);
|
||||
channelEntry.detailRevision = detailRevision;
|
||||
await store.actions.setCardChannelItemDetail(guid, cardId, channel.id, channelEntry.detailRevision, channelEntry.detail);
|
||||
if (channelItem.detailRevision !== detailRevision) {
|
||||
if (channelItem.detail) {
|
||||
channelEntry.detail = channelItem.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) {
|
||||
channelEntry.summary = await getContactChannelSummary(cardServer, cardToken, channel.id);
|
||||
channelEntry.topicRevision = topicRevision;
|
||||
await store.actions.setCardChannelItemSummary(guid, cardId, channel.id, channelEntry.topicRevision, channelEntry.summary);
|
||||
if (channelItem.topicRevision !== topicRevision) {
|
||||
if (channelItem.summary) {
|
||||
channelEntry.summary = channelItem.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;
|
||||
await store.actions.setCardItemNotifiedChannel(guid, cardId, channelRevision.channel);
|
||||
await store.actions.setCardItemNotifiedChannel(guid, cardId, cardRevision.channel);
|
||||
entry.card.notifiedView = cardRevision.view;
|
||||
await store.actions.setCardItemNotifiedView(guid, cardId, channelRevision.view);
|
||||
entry.channel.set(channel.id, channelEntry);
|
||||
await store.actions.setCardItemNotifiedView(guid, cardId, cardRevision.view);
|
||||
entry.channels.set(channel.id, channelEntry);
|
||||
}
|
||||
else {
|
||||
await store.actions.clearCardChannelTopicItems(guid, card.id, channel.id);
|
||||
|
@ -15,6 +15,10 @@ function CardView() {
|
||||
setRenderCount(renderCount + 1);
|
||||
const rendered = [];
|
||||
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>);
|
||||
});
|
||||
setCards(rendered);
|
||||
@ -42,8 +46,12 @@ const realFetchWithCustomTimeout = fetchUtil.fetchWithCustomTimeout;
|
||||
let fetchCards;
|
||||
let fetchDetail;
|
||||
let fetchProfile;
|
||||
let fetchCardChannels;
|
||||
beforeEach(() => {
|
||||
fetchCards = [];
|
||||
fetchDetail = {};
|
||||
fetchProfile = {};
|
||||
fetchCardChannels = [];
|
||||
|
||||
const mockUseContext = jest.fn().mockImplementation((ctx) => {
|
||||
return useTestStoreContext();
|
||||
@ -68,6 +76,11 @@ beforeEach(() => {
|
||||
json: () => Promise.resolve(fetchDetail)
|
||||
});
|
||||
}
|
||||
if (url.startsWith('https://test.org/content/channels?contact')) {
|
||||
return Promise.resolve({
|
||||
json: () => Promise.resolve(fetchCardChannels)
|
||||
});
|
||||
}
|
||||
else {
|
||||
return Promise.resolve({
|
||||
json: () => Promise.resolve([])
|
||||
@ -85,7 +98,7 @@ afterEach(() => {
|
||||
fetchUtil.fetchWithCustomTimeout = realFetchWithCustomTimeout;
|
||||
});
|
||||
|
||||
test('add, update, and remove', async () => {
|
||||
test('add, update, and remove card', async () => {
|
||||
|
||||
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