Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Signals working well with lit
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Apr 24, 2024
1 parent 3e1fd0e commit a1942e2
Show file tree
Hide file tree
Showing 11 changed files with 380 additions and 549 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ members = ["zomes/coordinator/*", "zomes/integrity/*"]
resolver = "2"

[workspace.dependencies]
holochain = { version = "0.3.0-beta-dev.45", default-features = false, features = [
holochain = { version = "=0.3.0-beta-dev.45", default-features = false, features = [
"test_utils",
] }
hdi = "0.4.0-beta-dev.34"
hdk = "0.3.0-beta-dev.38"
serde = "1"
hdi = "=0.4.0-beta-dev.34"
hdk = "=0.3.0-beta-dev.38"
serde = "1.0.193"

268 changes: 133 additions & 135 deletions tests/src/notification-lifecycle.test.ts
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);
});
});
Loading

0 comments on commit a1942e2

Please sign in to comment.