2022-02-11 22:32:51 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
|
|
|
|
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);
|
2023-09-19 17:02:37 +00:00
|
|
|
this.retries(4);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
({ bootstrap, app } = await initStorage());
|
|
|
|
});
|
|
|
|
|
2022-07-08 20:46:25 +00:00
|
|
|
afterEach(async function after() {
|
|
|
|
if (!bootstrap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2022-02-11 22:32:51 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should archive/unarchive contacts', async () => {
|
|
|
|
const { phone, contacts } = bootstrap;
|
|
|
|
const [firstContact] = contacts;
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = window.locator('#LeftPane');
|
|
|
|
const conversationStack = window.locator('.Inbox__conversation-stack');
|
2022-02-11 22:32:51 +00:00
|
|
|
|
|
|
|
debug('archiving contact');
|
|
|
|
{
|
|
|
|
const state = await phone.expectStorageState('consistency check');
|
2023-02-08 17:19:13 +00:00
|
|
|
const newState = state
|
|
|
|
.updateContact(firstContact, { archived: true })
|
|
|
|
.unpin(firstContact);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-02-08 17:19:13 +00:00
|
|
|
await phone.setStorageState(newState);
|
2022-02-11 22:32:51 +00:00
|
|
|
await phone.sendFetchStorage({
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
});
|
|
|
|
|
|
|
|
await leftPane
|
2023-08-16 20:54:39 +00:00
|
|
|
.locator(`[data-testid="${firstContact.toContact().aci}"]`)
|
2022-02-11 22:32:51 +00:00
|
|
|
.waitFor({ state: 'hidden' });
|
|
|
|
|
|
|
|
await leftPane
|
|
|
|
.locator('button.module-conversation-list__item--archive-button')
|
|
|
|
.waitFor();
|
2023-02-08 17:19:13 +00:00
|
|
|
|
|
|
|
await app.waitForManifestVersion(newState.version);
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug('unarchiving pinned contact');
|
|
|
|
{
|
|
|
|
const state = await phone.expectStorageState('consistency check');
|
2023-02-08 17:19:13 +00:00
|
|
|
const newState = state
|
|
|
|
.updateContact(firstContact, {
|
|
|
|
archived: false,
|
|
|
|
})
|
|
|
|
.pin(firstContact);
|
2022-02-11 22:32:51 +00:00
|
|
|
|
2023-02-08 17:19:13 +00:00
|
|
|
await phone.setStorageState(newState);
|
2022-02-11 22:32:51 +00:00
|
|
|
await phone.sendFetchStorage({
|
|
|
|
timestamp: bootstrap.getTimestamp(),
|
|
|
|
});
|
|
|
|
|
|
|
|
await leftPane
|
2023-08-16 20:54:39 +00:00
|
|
|
.locator(`[data-testid="${firstContact.toContact().aci}"]`)
|
2022-02-11 22:32:51 +00:00
|
|
|
.waitFor();
|
|
|
|
|
|
|
|
await leftPane
|
|
|
|
.locator('button.module-conversation-list__item--archive-button')
|
|
|
|
.waitFor({ state: 'hidden' });
|
2023-02-08 17:19:13 +00:00
|
|
|
|
|
|
|
await app.waitForManifestVersion(newState.version);
|
2022-02-11 22:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug('archive pinned contact in the app');
|
|
|
|
{
|
|
|
|
const state = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
await leftPane
|
2023-08-16 20:54:39 +00:00
|
|
|
.locator(`[data-testid="${firstContact.toContact().aci}"]`)
|
2022-02-11 22:32:51 +00:00
|
|
|
.click();
|
|
|
|
|
|
|
|
const moreButton = conversationStack.locator(
|
|
|
|
'button.module-ConversationHeader__button--more'
|
|
|
|
);
|
|
|
|
await moreButton.click();
|
|
|
|
|
2023-10-06 15:45:43 +00:00
|
|
|
const archiveButton = window.locator(
|
2022-02-11 22:32:51 +00:00
|
|
|
'.react-contextmenu-item >> "Archive"'
|
|
|
|
);
|
|
|
|
await archiveButton.click();
|
|
|
|
|
|
|
|
const newState = await phone.waitForStorageState({
|
|
|
|
after: state,
|
|
|
|
});
|
|
|
|
assert.ok(!(await newState.isPinned(firstContact)), 'contact not pinned');
|
|
|
|
const record = await newState.getContact(firstContact);
|
|
|
|
assert.ok(record, 'contact record not found');
|
|
|
|
assert.ok(record?.archived, 'contact archived');
|
|
|
|
|
|
|
|
// AccountRecord + ContactRecord
|
|
|
|
const { added, removed } = newState.diff(state);
|
|
|
|
assert.strictEqual(added.length, 2, 'only two records must be added');
|
|
|
|
assert.strictEqual(removed.length, 2, 'only two records must be removed');
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('Verifying the final manifest version');
|
|
|
|
const finalState = await phone.expectStorageState('consistency check');
|
|
|
|
|
|
|
|
assert.strictEqual(finalState.version, 4);
|
|
|
|
});
|
|
|
|
});
|