mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
* refactor: introduce @bitwarden/serialization * refactor: introduce @bitwarden/guid * refactor: introduce @bitwaren/client-type * refactor: introduce @bitwarden/core-test-utils * refactor: introduce @bitwarden/state and @bitwarden/state-test-utils Creates initial project structure for centralized application state management. Part of modularization effort to extract state code from common. * Added state provider documentation to README. * Changed callouts to Github format. * Fixed linting on file name. * Forced git to accept rename --------- Co-authored-by: Todd Martin <tmartin@bitwarden.com>
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
import { MockProxy } from "jest-mock-extended";
|
|
|
|
import { MigrationHelper } from "../migration-helper";
|
|
import { mockMigrationHelper } from "../migration-helper.spec";
|
|
|
|
import { LOCALE_KEY, PreferredLanguageMigrator } from "./32-move-preferred-language";
|
|
|
|
function exampleJSON() {
|
|
return {
|
|
global: {
|
|
locale: "en",
|
|
otherStuff: "otherStuff1",
|
|
},
|
|
otherStuff: "otherStuff2",
|
|
};
|
|
}
|
|
|
|
function rollbackJSON() {
|
|
return {
|
|
global_translation_locale: "en",
|
|
global: {
|
|
otherStuff: "otherStuff1",
|
|
},
|
|
otherStuff: "otherStuff2",
|
|
};
|
|
}
|
|
|
|
describe("PreferredLanguageMigrator", () => {
|
|
let helper: MockProxy<MigrationHelper>;
|
|
let sut: PreferredLanguageMigrator;
|
|
|
|
describe("migrate", () => {
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(exampleJSON(), 31);
|
|
sut = new PreferredLanguageMigrator(31, 32);
|
|
});
|
|
|
|
it("should remove locale setting from global", async () => {
|
|
await sut.migrate(helper);
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("global", {
|
|
otherStuff: "otherStuff1",
|
|
});
|
|
});
|
|
|
|
it("should set locale for global state provider", async () => {
|
|
await sut.migrate(helper);
|
|
|
|
expect(helper.setToGlobal).toHaveBeenCalledTimes(1);
|
|
expect(helper.setToGlobal).toHaveBeenCalledWith(LOCALE_KEY, "en");
|
|
});
|
|
});
|
|
|
|
describe("rollback", () => {
|
|
beforeEach(() => {
|
|
helper = mockMigrationHelper(rollbackJSON(), 32);
|
|
sut = new PreferredLanguageMigrator(31, 32);
|
|
});
|
|
|
|
it("should null out new values for global", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.setToGlobal).toHaveBeenCalledTimes(1);
|
|
expect(helper.setToGlobal).toHaveBeenCalledWith(LOCALE_KEY, null);
|
|
});
|
|
|
|
it("should add locale back to the old global object", async () => {
|
|
await sut.rollback(helper);
|
|
|
|
expect(helper.set).toHaveBeenCalledTimes(1);
|
|
expect(helper.set).toHaveBeenCalledWith("global", {
|
|
locale: "en",
|
|
otherStuff: "otherStuff1",
|
|
});
|
|
});
|
|
});
|
|
});
|