Merge branch 'develop' of github.com:thecodingmachine/workadventure into feat/follow-woka

This commit is contained in:
David Négrier 2021-12-23 16:04:59 +01:00
commit 368a115b4c
93 changed files with 4017 additions and 2405 deletions

View file

@ -1,7 +1,7 @@
import "jasmine";
import {MapStore} from "../../../src/Stores/Utils/MapStore";
import type {Readable, Writable} from "svelte/store";
import {get, writable} from "svelte/store";
import { MapStore } from "../../../src/Stores/Utils/MapStore";
import type { Readable, Writable } from "svelte/store";
import { get, writable } from "svelte/store";
describe("Main store", () => {
it("Set / delete / clear triggers main store updates", () => {
@ -12,17 +12,17 @@ describe("Main store", () => {
mapStore.subscribe((map) => {
triggered = true;
expect(map).toBe(mapStore);
})
});
expect(triggered).toBeTrue();
triggered = false;
mapStore.set('foo', 'bar');
mapStore.set("foo", "bar");
expect(triggered).toBeTrue();
triggered = false;
mapStore.delete('baz');
mapStore.delete("baz");
expect(triggered).toBe(false);
mapStore.delete('foo');
mapStore.delete("foo");
expect(triggered).toBe(true);
triggered = false;
@ -31,67 +31,68 @@ describe("Main store", () => {
});
it("generates stores for keys with getStore", () => {
const mapStore = new MapStore<string, string>();
let valueReceivedInStoreForFoo: string|undefined;
let valueReceivedInStoreForBar: string|undefined;
let valueReceivedInStoreForFoo: string | undefined;
let valueReceivedInStoreForBar: string | undefined;
mapStore.set('foo', 'someValue');
mapStore.set("foo", "someValue");
mapStore.getStore('foo').subscribe((value) => {
mapStore.getStore("foo").subscribe((value) => {
valueReceivedInStoreForFoo = value;
});
const unsubscribeBar = mapStore.getStore('bar').subscribe((value) => {
const unsubscribeBar = mapStore.getStore("bar").subscribe((value) => {
valueReceivedInStoreForBar = value;
});
expect(valueReceivedInStoreForFoo).toBe('someValue');
expect(valueReceivedInStoreForFoo).toBe("someValue");
expect(valueReceivedInStoreForBar).toBe(undefined);
mapStore.set('foo', 'someOtherValue');
expect(valueReceivedInStoreForFoo).toBe('someOtherValue');
mapStore.delete('foo');
mapStore.set("foo", "someOtherValue");
expect(valueReceivedInStoreForFoo).toBe("someOtherValue");
mapStore.delete("foo");
expect(valueReceivedInStoreForFoo).toBe(undefined);
mapStore.set('bar', 'baz');
expect(valueReceivedInStoreForBar).toBe('baz');
mapStore.set("bar", "baz");
expect(valueReceivedInStoreForBar).toBe("baz");
mapStore.clear();
expect(valueReceivedInStoreForBar).toBe(undefined);
unsubscribeBar();
mapStore.set('bar', 'fiz');
mapStore.set("bar", "fiz");
expect(valueReceivedInStoreForBar).toBe(undefined);
});
it("generates stores with getStoreByAccessor", () => {
const mapStore = new MapStore<string, {
foo: string,
store: Writable<string>
}>();
const mapStore = new MapStore<
string,
{
foo: string;
store: Writable<string>;
}
>();
const fooStore = mapStore.getNestedStore('foo', (value) => {
const fooStore = mapStore.getNestedStore("foo", (value) => {
return value.store;
});
mapStore.set('foo', {
foo: 'bar',
store: writable('init')
mapStore.set("foo", {
foo: "bar",
store: writable("init"),
});
expect(get(fooStore)).toBe('init');
expect(get(fooStore)).toBe("init");
mapStore.get('foo')?.store.set('newVal');
mapStore.get("foo")?.store.set("newVal");
expect(get(fooStore)).toBe('newVal');
expect(get(fooStore)).toBe("newVal");
mapStore.set('foo', {
foo: 'bar',
store: writable('anotherVal')
mapStore.set("foo", {
foo: "bar",
store: writable("anotherVal"),
});
expect(get(fooStore)).toBe('anotherVal');
expect(get(fooStore)).toBe("anotherVal");
mapStore.delete('foo');
mapStore.delete("foo");
expect(get(fooStore)).toBeUndefined();
});
});