2022-02-11 22:32:51 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
/* eslint-disable no-await-in-loop */
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
|
|
|
import type { Group } from '@signalapp/mock-server';
|
|
|
|
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import type { App, Bootstrap } from './fixtures';
|
|
|
|
import { initStorage, debug } from './fixtures';
|
|
|
|
|
|
|
|
describe('storage service', function needsName() {
|
|
|
|
this.timeout(durations.MINUTE);
|
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
let group: Group;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
({ bootstrap, app, group } = await initStorage());
|
|
|
|
});
|
|
|
|
|
2022-07-08 20:46:25 +00:00
|
|
|
afterEach(async function after() {
|
|
|
|
if (!bootstrap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.currentTest?.state !== 'passed') {
|
2022-09-01 16:35:44 +00:00
|
|
|
await bootstrap.saveLogs(app);
|
2022-07-08 20:46:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 22:32:51 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should pin/unpin groups', async () => {
|
|
|
|
const { phone, desktop, contacts } = bootstrap;
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
|
|
|
const leftPane = window.locator('.left-pane-wrapper');
|
|
|
|
const conversationStack = window.locator('.conversation-stack');
|
|
|
|
|
|
|
|
debug('Verifying that the group is pinned on startup');
|
2023-01-13 00:24:59 +00:00
|
|
|
await leftPane.locator(`[data-testid="${group.id}"]`).waitFor();
|
2022-02-11 22:32:51 +00:00
|
|
|
|
|
|
|
debug('Unpinning group via storage service');
|
|
|
|
{
|
|
|
|
const state = await phone.expectStorageState('initial state');
|
|
|
|
|
|
|
|
await phone.setStorageState(state.unpinGroup(group));
|
|
|
|
await phone.sendFetchStorage({
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
});
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
await leftPane.locator(`[data-testid="${group.id}"]`).waitFor();
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug('Pinning group in the app');
|
|
|
|
{
|
|
|
|
const state = await phone.expectStorageState('consistency check');
|
|
|
|
|
2023-01-13 00:24:59 +00:00
|
|
|
const convo = leftPane.locator(`[data-testid="${group.id}"]`);
|
2022-02-11 22:32:51 +00:00
|
|
|
await convo.click();
|
|
|
|
|
|
|
|
const moreButton = conversationStack.locator(
|
|
|
|
'button.module-ConversationHeader__button--more'
|
|
|
|
);
|
|
|
|
await moreButton.click();
|
|
|
|
|
|
|
|
const pinButton = conversationStack.locator(
|
|
|
|
'.react-contextmenu-item >> "Pin Conversation"'
|
|
|
|
);
|
|
|
|
await pinButton.click();
|
|
|
|
|
|
|
|
const newState = await phone.waitForStorageState({
|
|
|
|
after: state,
|
|
|
|
});
|
|
|
|
assert.isTrue(await newState.isGroupPinned(group), 'group not pinned');
|
|
|
|
|
|
|
|
// AccountRecord
|
|
|
|
const { added, removed } = newState.diff(state);
|
|
|
|
assert.strictEqual(added.length, 1, 'only one record must be added');
|
|
|
|
assert.strictEqual(removed.length, 1, 'only one record must be removed');
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('Pinning > 4 conversations');
|
|
|
|
{
|
|
|
|
// We already have one group and first contact pinned so we need three
|
|
|
|
// more.
|
|
|
|
const toPin = contacts.slice(1, 4);
|
|
|
|
|
|
|
|
// To do that we need them to appear in the left pane, though.
|
|
|
|
for (const [i, contact] of toPin.entries()) {
|
|
|
|
const isLast = i === toPin.length - 1;
|
|
|
|
|
|
|
|
debug('sending a message to contact=%d', i);
|
|
|
|
await contact.sendText(desktop, 'Hello!', {
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const state = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
debug('pinning contact=%d', i);
|
|
|
|
const convo = leftPane.locator(
|
2023-01-13 00:24:59 +00:00
|
|
|
`[data-testid="${contact.toContact().uuid}"]`
|
2022-02-11 22:32:51 +00:00
|
|
|
);
|
|
|
|
await convo.click();
|
|
|
|
|
|
|
|
const moreButton = conversationStack.locator(
|
|
|
|
'button.module-ConversationHeader__button--more'
|
|
|
|
);
|
|
|
|
await moreButton.click();
|
|
|
|
|
|
|
|
const pinButton = conversationStack.locator(
|
|
|
|
'.react-contextmenu-item >> "Pin Conversation"'
|
|
|
|
);
|
|
|
|
await pinButton.click();
|
|
|
|
|
|
|
|
if (isLast) {
|
|
|
|
// Storage state shouldn't be updated because we failed to pin
|
|
|
|
await window
|
|
|
|
.locator('.Toast >> "You can only pin up to 4 chats"')
|
|
|
|
.waitFor();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('verifying storage state change contact=%d', i);
|
|
|
|
const newState = await phone.waitForStorageState({
|
|
|
|
after: state,
|
|
|
|
});
|
|
|
|
assert.isTrue(await newState.isPinned(contact), 'contact not pinned');
|
|
|
|
|
|
|
|
// AccountRecord
|
|
|
|
const { added, removed } = newState.diff(state);
|
|
|
|
assert.strictEqual(added.length, 1, 'only one record must be added');
|
|
|
|
assert.strictEqual(
|
|
|
|
removed.length,
|
|
|
|
1,
|
|
|
|
'only one record must be removed'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('Verifying the final manifest version');
|
|
|
|
const finalState = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
assert.strictEqual(finalState.version, 5);
|
|
|
|
});
|
|
|
|
});
|