mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 22:03:36 +00:00
Fix folder tests (#3171)
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import { Arg, Substitute, SubstituteOf } from "@fluffy-spoon/substitute";
|
import { Arg, Substitute, SubstituteOf } from "@fluffy-spoon/substitute";
|
||||||
import { BehaviorSubject, firstValueFrom } from "rxjs";
|
import { BehaviorSubject, firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
||||||
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
|
||||||
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||||
@@ -19,30 +18,25 @@ describe("Folder Service", () => {
|
|||||||
let i18nService: SubstituteOf<I18nService>;
|
let i18nService: SubstituteOf<I18nService>;
|
||||||
let cipherService: SubstituteOf<CipherService>;
|
let cipherService: SubstituteOf<CipherService>;
|
||||||
let stateService: SubstituteOf<StateService>;
|
let stateService: SubstituteOf<StateService>;
|
||||||
let broadcasterService: SubstituteOf<BroadcasterService>;
|
|
||||||
let activeAccount: BehaviorSubject<string>;
|
let activeAccount: BehaviorSubject<string>;
|
||||||
|
let activeAccountUnlocked: BehaviorSubject<boolean>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cryptoService = Substitute.for();
|
cryptoService = Substitute.for();
|
||||||
i18nService = Substitute.for();
|
i18nService = Substitute.for();
|
||||||
cipherService = Substitute.for();
|
cipherService = Substitute.for();
|
||||||
stateService = Substitute.for();
|
stateService = Substitute.for();
|
||||||
broadcasterService = Substitute.for();
|
|
||||||
activeAccount = new BehaviorSubject("123");
|
activeAccount = new BehaviorSubject("123");
|
||||||
|
activeAccountUnlocked = new BehaviorSubject(true);
|
||||||
|
|
||||||
stateService.getEncryptedFolders().resolves({
|
stateService.getEncryptedFolders().resolves({
|
||||||
"1": folderData("1", "test"),
|
"1": folderData("1", "test"),
|
||||||
});
|
});
|
||||||
stateService.activeAccount.returns(activeAccount);
|
stateService.activeAccount.returns(activeAccount);
|
||||||
|
stateService.activeAccountUnlocked.returns(activeAccountUnlocked);
|
||||||
(window as any).bitwardenContainerService = new ContainerService(cryptoService);
|
(window as any).bitwardenContainerService = new ContainerService(cryptoService);
|
||||||
|
|
||||||
folderService = new FolderService(
|
folderService = new FolderService(cryptoService, i18nService, cipherService, stateService);
|
||||||
cryptoService,
|
|
||||||
i18nService,
|
|
||||||
cipherService,
|
|
||||||
stateService,
|
|
||||||
broadcasterService
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("encrypt", async () => {
|
it("encrypt", async () => {
|
||||||
@@ -155,6 +149,15 @@ describe("Folder Service", () => {
|
|||||||
expect((await firstValueFrom(folderService.folderViews$)).length).toBe(0);
|
expect((await firstValueFrom(folderService.folderViews$)).length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("locking should clear", async () => {
|
||||||
|
activeAccountUnlocked.next(false);
|
||||||
|
// Sleep for 100ms to avoid timing issues
|
||||||
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
|
||||||
|
expect((await firstValueFrom(folderService.folders$)).length).toBe(0);
|
||||||
|
expect((await firstValueFrom(folderService.folderViews$)).length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
describe("clear", () => {
|
describe("clear", () => {
|
||||||
it("null userId", async () => {
|
it("null userId", async () => {
|
||||||
await folderService.clear();
|
await folderService.clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user