This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e1fd0e
commit a1942e2
Showing
11 changed files
with
380 additions
and
549 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,143 @@ | ||
|
||
import { assert, test } from "vitest"; | ||
|
||
import { runScenario, dhtSync } from '@holochain/tryorama'; | ||
import { EntryRecord } from '@holochain-open-dev/utils'; | ||
import { dhtSync, runScenario } from '@holochain/tryorama'; | ||
import { assert, test } from 'vitest'; | ||
|
||
import { Notification } from '../../ui/src/types.js'; | ||
import { sampleNotification } from '../../ui/src/mocks.js'; | ||
import { toPromise } from '../../ui/src/signals.js'; | ||
import { Notification } from '../../ui/src/types.js'; | ||
import { setup } from './setup.js'; | ||
import { toPromise } from "../../ui/src/signals.js"; | ||
|
||
test('create notifications, read it, and dismiss it', async () => { | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync( | ||
[alice.player, bob.player], | ||
alice.player.cells[0].cell_id[0] | ||
); | ||
|
||
let unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
console.log('heyyy0') | ||
let readNotifications = await toPromise(bob.store.readNotifications); | ||
console.log('heyyy0.1') | ||
assert.equal(readNotifications.size, 0); | ||
let dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
console.log('heyyy0.2') | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
console.log('heyyy1') | ||
|
||
// Alice creates a Notification | ||
const notification1: EntryRecord<Notification> = await alice.store.client.createNotification(await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey] | ||
})); | ||
assert.ok(notification1); | ||
const notification2: EntryRecord<Notification> = await alice.store.client.createNotification(await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey] | ||
})); | ||
assert.ok(notification2); | ||
console.log('heyyy2') | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync( | ||
[alice.player, bob.player], | ||
alice.player.cells[0].cell_id[0] | ||
); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 2); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.markNotificationsAsRead([notification1.actionHash]); | ||
console.log('heyyy3') | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 1); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 1); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.markNotificationsAsRead([notification2.actionHash]); | ||
|
||
console.log('heyyy4') | ||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 2); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
console.log('heyyy5') | ||
// Bob deletes the Notification | ||
await bob.store.client.dismissNotifications([notification2.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 1); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 1); | ||
|
||
// Bob deletes the Notification | ||
await bob.store.client.dismissNotifications([notification1.actionHash]); | ||
console.log('heyyy6') | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 2); | ||
}); | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]); | ||
|
||
let unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
let readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
let dismissedNotifications = await toPromise( | ||
bob.store.dismissedNotifications, | ||
); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
// Alice creates a Notification | ||
const notification1: EntryRecord<Notification> = | ||
await alice.store.client.createNotification( | ||
await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey], | ||
}), | ||
); | ||
assert.ok(notification1); | ||
const notification2: EntryRecord<Notification> = | ||
await alice.store.client.createNotification( | ||
await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey], | ||
}), | ||
); | ||
assert.ok(notification2); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 2); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.markNotificationsAsRead([notification1.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 1); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 1); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.markNotificationsAsRead([notification2.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 2); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
// Bob deletes the Notification | ||
await bob.store.client.dismissNotifications([notification2.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 1); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 1); | ||
|
||
// Bob deletes the Notification | ||
await bob.store.client.dismissNotifications([notification1.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 2); | ||
}); | ||
}); | ||
|
||
test('create notifications and dismiss it directly', async () => { | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
let unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
let readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
let dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
// Alice creates a Notification | ||
const notification1: EntryRecord<Notification> = await alice.store.client.createNotification(await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey] | ||
})); | ||
assert.ok(notification1); | ||
const notification2: EntryRecord<Notification> = await alice.store.client.createNotification(await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey] | ||
})); | ||
assert.ok(notification2); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync( | ||
[alice.player, bob.player], | ||
alice.player.cells[0].cell_id[0] | ||
); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 2); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.dismissNotifications([notification1.actionHash, notification2.actionHash]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 2); | ||
}); | ||
await runScenario(async scenario => { | ||
const { alice, bob } = await setup(scenario); | ||
|
||
let unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
let readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
let dismissedNotifications = await toPromise( | ||
bob.store.dismissedNotifications, | ||
); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
// Alice creates a Notification | ||
const notification1: EntryRecord<Notification> = | ||
await alice.store.client.createNotification( | ||
await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey], | ||
}), | ||
); | ||
assert.ok(notification1); | ||
const notification2: EntryRecord<Notification> = | ||
await alice.store.client.createNotification( | ||
await sampleNotification(alice.store.client, { | ||
recipients: [bob.player.agentPubKey], | ||
}), | ||
); | ||
assert.ok(notification2); | ||
|
||
// Wait for the created entry to be propagated to the other node. | ||
await dhtSync([alice.player, bob.player], alice.player.cells[0].cell_id[0]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 2); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 0); | ||
|
||
await bob.store.client.dismissNotifications([ | ||
notification1.actionHash, | ||
notification2.actionHash, | ||
]); | ||
|
||
unreadNotifications = await toPromise(bob.store.unreadNotifications); | ||
assert.equal(unreadNotifications.size, 0); | ||
readNotifications = await toPromise(bob.store.readNotifications); | ||
assert.equal(readNotifications.size, 0); | ||
dismissedNotifications = await toPromise(bob.store.dismissedNotifications); | ||
assert.equal(dismissedNotifications.size, 2); | ||
}); | ||
}); |
Oops, something went wrong.