notifications: rename alert to pin and unpin

This commit is contained in:
Girish Ramakrishnan
2024-12-11 15:47:41 +01:00
parent ead419003b
commit 746e694d7e
7 changed files with 112 additions and 71 deletions
+62 -31
View File
@@ -85,45 +85,76 @@ describe('Notifications', function () {
expect(error.reason).to.be(BoxError.NOT_FOUND);
});
let alertId;
it('can add alert', async function () {
alertId = await notifications.alert(notifications.TYPE_BOX_UPDATE, 'Cloudron xx is available', 'Awesome changelog', { persist: true });
let pinId;
describe('pin with context', function () {
it('can add pin', async function () {
pinId = await notifications.pin(notifications.TYPE_BOX_UPDATE, 'Cloudron xx is available', 'Awesome changelog', { context: 'xx' });
const result = await notifications.get(alertId);
expect(result.title).to.be('Cloudron xx is available');
expect(result.message).to.be('Awesome changelog');
expect(result.acknowledged).to.be(false);
const result = await notifications.get(pinId);
expect(result.title).to.be('Cloudron xx is available');
expect(result.message).to.be('Awesome changelog');
expect(result.acknowledged).to.be(false);
});
it('updating pin with same message does nothing', async function () {
await notifications.update({ id: pinId }, { acknowledged: true }); // ack the alert
const id = await notifications.pin(notifications.TYPE_BOX_UPDATE, 'Cloudron xx is available', 'Awesome changelog', { context: 'xx' });
expect(id).to.be(pinId);
const result = await notifications.get(pinId);
expect(result.title).to.be('Cloudron xx is available');
expect(result.message).to.be('Awesome changelog');
expect(result.acknowledged).to.be(true); // notification does not resurface
});
it('updating pin with new message resurfaces', async function () {
await notifications.update({ id: pinId }, { acknowledged: true }); // ack the alert
const id = await notifications.pin(notifications.TYPE_BOX_UPDATE, 'Cloudron xy is available', 'Awesome new changelog', { context: 'xx' });
expect(id).to.be(pinId);
const result = await notifications.get(pinId);
expect(result.title).to.be('Cloudron xy is available');
expect(result.message).to.be('Awesome new changelog');
expect(result.acknowledged).to.be(false); // notification resurfaces
});
it('can unpin', async function () {
await notifications.unpin(notifications.TYPE_BOX_UPDATE, { context: 'xx' });
const result = await notifications.get(pinId);
expect(result.acknowledged).to.be(true);
});
});
it('can update the alert (persist)', async function () {
await notifications.update({ id: alertId }, { acknowledged: true }); // ack the alert
describe('pin without context', function () {
it('can add pin', async function () {
pinId = await notifications.pin(notifications.TYPE_REBOOT, 'Reboot required', 'Do it now', {});
const id = await notifications.alert(notifications.TYPE_BOX_UPDATE, 'Cloudron xx is available', 'Awesome new changelog', { persist: true });
expect(id).to.be(alertId);
const result = await notifications.get(pinId);
expect(result.title).to.be('Reboot required');
expect(result.message).to.be('Do it now');
expect(result.acknowledged).to.be(false);
});
const result = await notifications.get(alertId);
expect(result.title).to.be('Cloudron xx is available');
expect(result.message).to.be('Awesome new changelog');
expect(result.acknowledged).to.be(false); // notification resurfaces
});
it('can update the alert', async function () {
await notifications.update({ id: pinId }, { acknowledged: true }); // ack the alert
it('can update the alert (non-persist)', async function () {
await notifications.update({ id: alertId }, { acknowledged: true }); // ack the alert
const id = await notifications.pin(notifications.TYPE_REBOOT, 'Reboot required', 'Do it now', {});
expect(id).to.be(pinId);
const id = await notifications.alert(notifications.TYPE_BOX_UPDATE, 'Cloudron xx is available', 'Awesome new changelog', { persist: false });
expect(id).to.be(alertId);
const result = await notifications.get(pinId);
expect(result.title).to.be('Reboot required');
expect(result.message).to.be('Do it now');
expect(result.acknowledged).to.be(false); // resurfaces
});
const result = await notifications.get(alertId);
expect(result.title).to.be('Cloudron xx is available');
expect(result.message).to.be('Awesome new changelog');
expect(result.acknowledged).to.be(true); // notification does not resurface
});
it('can unpin', async function () {
await notifications.unpin(notifications.TYPE_REBOOT, {});
it('can clear the alert', async function () {
const id = await notifications.clearAlert(notifications.TYPE_BOX_UPDATE);
expect(id).to.be(null);
const result = await notifications.get(alertId);
expect(result).to.be(null);
const result = await notifications.get(pinId);
expect(result.acknowledged).to.be(true);
});
});
});