Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EB-1200: Implement signals in live preview sdk #111

26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@preact/compat": "^17.1.2",
"@preact/signals": "^1.2.2",
"classnames": "^2.5.1",
"deepsignal": "^1.5.0",
"just-camel-case": "^6.2.0",
"lodash-es": "^4.17.21",
"mustache": "^4.2.0",
Expand Down
51 changes: 31 additions & 20 deletions src/configManager/__test__/configManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
import Config, { updateConfigFromUrl } from "../configManager";
import { getDefaultConfig } from "../config.default";
import { DeepSignal } from "deepsignal";
import { IConfig } from "../../types/types";

describe("Config", () => {
let config: DeepSignal<IConfig>;

beforeEach(() => {
Config.reset();
config = Config.get();
});

afterAll(() => {
Config.reset();
});

test("should return default value", () => {
const defaultConfig = getDefaultConfig();
const receivedConfig = Config.get();
const receivedConfig = config;

//@ts-expect-error
// @ts-expect-error
delete defaultConfig.onChange;
//@ts-expect-error
// @ts-expect-error
delete receivedConfig.onChange;
expect(Config.get()).toStrictEqual(defaultConfig);
expect(config).toStrictEqual(defaultConfig);
});

test("should set and get value", () => {
const defaultConfig = getDefaultConfig();
let receivedConfig = Config.get();
let receivedConfig = config;

// @ts-expect-error
delete defaultConfig.onChange;
Expand All @@ -32,7 +38,7 @@ describe("Config", () => {
expect(receivedConfig).toEqual({ ...defaultConfig, ssr: true });

Config.set("ssr", false);
receivedConfig = Config.get();
receivedConfig = config;

// @ts-expect-error
delete receivedConfig.onChange;
Expand All @@ -48,7 +54,7 @@ describe("Config", () => {

test("should replace config", () => {
const defaultConfig = getDefaultConfig();
let receivedConfig = Config.get();
let receivedConfig = config;

// @ts-expect-error
delete defaultConfig.onChange;
Expand All @@ -66,7 +72,7 @@ describe("Config", () => {
},
});

receivedConfig = Config.get();
receivedConfig = config;

// @ts-expect-error
delete receivedConfig.onChange;
Expand All @@ -85,8 +91,11 @@ describe("Config", () => {
});

describe("update config from url", () => {
let config: DeepSignal<IConfig>;

beforeEach(() => {
Config.reset();
config = Config.get();
});

afterEach(() => {
Expand Down Expand Up @@ -116,26 +125,28 @@ describe("update config from url", () => {
},
});

expect(Config.get().stackDetails.contentTypeUid).toEqual("");
expect(Config.get().stackDetails.entryUid).toEqual("");
expect(Config.get().hash).toEqual("");
const config = Config.get();

expect(config.stackDetails.contentTypeUid).toEqual("");
expect(config.stackDetails.entryUid).toEqual("");
expect(config.hash).toEqual("");

updateConfigFromUrl();

expect(Config.get().stackDetails.contentTypeUid).toEqual("test");
expect(Config.get().stackDetails.entryUid).toEqual("test");
expect(Config.get().hash).toEqual("test");
expect(config.stackDetails.contentTypeUid).toEqual("test");
expect(config.stackDetails.entryUid).toEqual("test");
expect(config.hash).toEqual("test");
});

it("should be default config if url params are not available", () => {
expect(Config.get().stackDetails.contentTypeUid).toEqual("");
expect(Config.get().stackDetails.entryUid).toEqual("");
expect(Config.get().hash).toEqual("");
expect(config.stackDetails.contentTypeUid).toEqual("");
expect(config.stackDetails.entryUid).toEqual("");
expect(config.hash).toEqual("");

updateConfigFromUrl();

expect(Config.get().stackDetails.contentTypeUid).toEqual("");
expect(Config.get().stackDetails.entryUid).toEqual("");
expect(Config.get().hash).toEqual("");
expect(config.stackDetails.contentTypeUid).toEqual("");
expect(config.stackDetails.entryUid).toEqual("");
expect(config.hash).toEqual("");
});
});
Loading