mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-24796] Ensure the CipherView prototype is not lost within the cache Signal (#16267)
This commit is contained in:
@@ -2,6 +2,7 @@ import { signal } from "@angular/core";
|
||||
import { TestBed } from "@angular/core/testing";
|
||||
|
||||
import { ViewCacheService } from "@bitwarden/angular/platform/view-cache";
|
||||
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
|
||||
import { CipherFormCacheService } from "./default-cipher-form-cache.service";
|
||||
@@ -36,9 +37,10 @@ describe("CipherFormCacheService", () => {
|
||||
it("updates the signal value", async () => {
|
||||
service = testBed.inject(CipherFormCacheService);
|
||||
|
||||
service.cacheCipherView({ id: "cipher-5" } as CipherView);
|
||||
service.cacheCipherView(new CipherView({ id: "cipher-5" } as Cipher));
|
||||
|
||||
expect(cacheSignal.set).toHaveBeenCalledWith({ id: "cipher-5" });
|
||||
expect(cacheSignal.set).toHaveBeenCalledWith(expect.any(CipherView)); // Ensure we keep the CipherView prototype
|
||||
expect(cacheSignal.set).toHaveBeenCalledWith(expect.objectContaining({ id: "cipher-5" }));
|
||||
});
|
||||
|
||||
describe("initializedWithValue", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { inject, Injectable } from "@angular/core";
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { ViewCacheService } from "@bitwarden/angular/platform/view-cache";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
@@ -32,10 +33,10 @@ export class CipherFormCacheService {
|
||||
* Update the cache with the new CipherView.
|
||||
*/
|
||||
cacheCipherView(cipherView: CipherView): void {
|
||||
// Create a new shallow reference to force the signal to update
|
||||
// Create a new reference to force the signal to update
|
||||
// By default, signals use `Object.is` to determine equality
|
||||
// Docs: https://angular.dev/guide/signals#signal-equality-functions
|
||||
this.cipherCache.set({ ...cipherView } as CipherView);
|
||||
this.cipherCache.set(CipherView.fromJSON(cipherView as Jsonify<CipherView>));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user