mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[CLEANUP] update prettier to v2.0.4
This commit is contained in:
+13
-13
@@ -9,7 +9,7 @@ import {
|
||||
patchNextFrame,
|
||||
renderToDOM,
|
||||
unpatchNextFrame,
|
||||
nextTick
|
||||
nextTick,
|
||||
} from "./helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -71,7 +71,7 @@ describe("animations", () => {
|
||||
qweb.addTemplate("test", `<span t-transition="chimay">blue</span>`);
|
||||
|
||||
let def = makeDeferred();
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(node.className).toBe("chimay-enter chimay-enter-active");
|
||||
cb();
|
||||
expect(node.className).toBe("chimay-enter-active chimay-enter-to");
|
||||
@@ -91,7 +91,7 @@ describe("animations", () => {
|
||||
qweb.addTemplate("test", `<span t-transition="chimay">blue</span>`);
|
||||
|
||||
let def = makeDeferred();
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(node.className).toBe("chimay-enter chimay-enter-active");
|
||||
cb();
|
||||
expect(node.className).toBe("chimay-enter-active chimay-enter-to");
|
||||
@@ -112,7 +112,7 @@ describe("animations", () => {
|
||||
qweb.addTemplate("test", `<span t-transition="jupiler">blue</span>`);
|
||||
|
||||
let def = makeDeferred();
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(node.className).toBe("jupiler-enter jupiler-enter-active");
|
||||
cb();
|
||||
expect(node.className).toBe("");
|
||||
@@ -139,7 +139,7 @@ describe("animations", () => {
|
||||
// insert widget into the DOM
|
||||
let def = makeDeferred();
|
||||
var spanNode;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(spanNode.className).toBe("chimay-enter chimay-enter-active");
|
||||
cb();
|
||||
expect(spanNode.className).toBe("chimay-enter-active chimay-enter-to");
|
||||
@@ -155,7 +155,7 @@ describe("animations", () => {
|
||||
// remove span from the DOM
|
||||
def = makeDeferred();
|
||||
widget.state.hide = true;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(spanNode.className).toBe("chimay-leave chimay-leave-active");
|
||||
cb();
|
||||
expect(spanNode.className).toBe("chimay-leave-active chimay-leave-to");
|
||||
@@ -182,7 +182,7 @@ describe("animations", () => {
|
||||
// insert widget into the DOM
|
||||
let def = makeDeferred();
|
||||
var spanNode;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(spanNode.className).toBe("chimay-enter chimay-enter-active");
|
||||
cb();
|
||||
expect(spanNode.className).toBe("chimay-enter-active chimay-enter-to");
|
||||
@@ -210,7 +210,7 @@ describe("animations", () => {
|
||||
|
||||
let def = makeDeferred();
|
||||
var spanNode;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><span class="chimay-enter chimay-enter-active">blue</span></div>'
|
||||
);
|
||||
@@ -250,7 +250,7 @@ describe("animations", () => {
|
||||
|
||||
let def = makeDeferred();
|
||||
var spanNode;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><span class="chimay-enter chimay-enter-active">blue</span></div>'
|
||||
);
|
||||
@@ -275,7 +275,7 @@ describe("animations", () => {
|
||||
// remove span from the DOM
|
||||
def = makeDeferred();
|
||||
widget.state.display = false;
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><span class="chimay-leave chimay-leave-active" data-owl-key="__3__">blue</span></div>'
|
||||
);
|
||||
@@ -315,7 +315,7 @@ describe("animations", () => {
|
||||
|
||||
let def = makeDeferred();
|
||||
let phase = "enter";
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
let spans = fixture.querySelectorAll("span");
|
||||
expect(spans.length).toBe(1);
|
||||
expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`);
|
||||
@@ -366,7 +366,7 @@ describe("animations", () => {
|
||||
|
||||
let def = makeDeferred();
|
||||
let phase = "enter";
|
||||
patchNextFrame(cb => {
|
||||
patchNextFrame((cb) => {
|
||||
let spans = fixture.querySelectorAll("span");
|
||||
expect(spans.length).toBe(1);
|
||||
expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`);
|
||||
@@ -413,7 +413,7 @@ describe("animations", () => {
|
||||
state = useState({ flag: false });
|
||||
}
|
||||
|
||||
patchNextFrame(cb => cb());
|
||||
patchNextFrame((cb) => cb());
|
||||
|
||||
const widget = new Parent();
|
||||
await widget.mount(fixture);
|
||||
|
||||
@@ -27,7 +27,7 @@ afterEach(() => {
|
||||
|
||||
function children(w: Component): Component[] {
|
||||
const childrenMap = w.__owl__.children;
|
||||
return Object.keys(childrenMap).map(id => childrenMap[id]);
|
||||
return Object.keys(childrenMap).map((id) => childrenMap[id]);
|
||||
}
|
||||
|
||||
describe("async rendering", () => {
|
||||
@@ -404,7 +404,7 @@ describe("async rendering", () => {
|
||||
}
|
||||
class ChildB extends Component {
|
||||
willStart(): any {
|
||||
return new Promise(function() {});
|
||||
return new Promise(function () {});
|
||||
}
|
||||
}
|
||||
class Parent extends Component {
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
nextMicroTick,
|
||||
nextTick,
|
||||
normalize,
|
||||
editInput
|
||||
editInput,
|
||||
} from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -39,7 +39,7 @@ afterEach(() => {
|
||||
|
||||
function children(w: Component): Component[] {
|
||||
const childrenMap = w.__owl__.children;
|
||||
return Object.keys(childrenMap).map(id => childrenMap[id]);
|
||||
return Object.keys(childrenMap).map((id) => childrenMap[id]);
|
||||
}
|
||||
|
||||
// Test components
|
||||
@@ -133,7 +133,7 @@ describe("basic widget properties", () => {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.counter"/><button t-on-click="state.counter++">Inc</button></div>`;
|
||||
state = useState({
|
||||
counter: 0
|
||||
counter: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ describe("basic widget properties", () => {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.counter"/><button t-on-click="state.counter++">Inc</button></div>`;
|
||||
state = useState({
|
||||
counter: 0
|
||||
counter: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -537,7 +537,7 @@ describe("lifecycle hooks", () => {
|
||||
"child:mounted",
|
||||
"parent:willUnmount",
|
||||
"child:willUnmount",
|
||||
"childchild:willUnmount"
|
||||
"childchild:willUnmount",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -589,7 +589,7 @@ describe("lifecycle hooks", () => {
|
||||
"childchild:willPatch",
|
||||
"childchild:patched",
|
||||
"child:patched",
|
||||
"parent:patched"
|
||||
"parent:patched",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -782,7 +782,7 @@ describe("lifecycle hooks", () => {
|
||||
"c mounted",
|
||||
"p mounted",
|
||||
"p willunmount",
|
||||
"c willunmount"
|
||||
"c willunmount",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -960,7 +960,7 @@ describe("lifecycle hooks", () => {
|
||||
"parent:willPatch",
|
||||
"child:willPatch",
|
||||
"child:patched",
|
||||
"parent:patched"
|
||||
"parent:patched",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1134,7 +1134,7 @@ describe("composition", () => {
|
||||
class App extends Component {
|
||||
static template = xml`<t t-component="myComponent" t-key="state.child"/>`;
|
||||
state = useState({
|
||||
child: "a"
|
||||
child: "a",
|
||||
});
|
||||
get myComponent() {
|
||||
return this.state.child === "a" ? A : B;
|
||||
@@ -1158,7 +1158,7 @@ describe("composition", () => {
|
||||
class App extends Component {
|
||||
static template = xml`<t t-component="myComponent" t-key="state.child"/>`;
|
||||
state = useState({
|
||||
child: "a"
|
||||
child: "a",
|
||||
});
|
||||
get myComponent() {
|
||||
return this.state.child === "a" ? A : B;
|
||||
@@ -1228,7 +1228,7 @@ describe("composition", () => {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.counter"/><button t-on-click="state.counter++">Inc</button></div>`;
|
||||
state = useState({
|
||||
counter: 0
|
||||
counter: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1327,7 +1327,7 @@ describe("composition", () => {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.counter"/><button t-on-click="state.counter++">Inc</button></div>`;
|
||||
state = useState({
|
||||
counter: 0
|
||||
counter: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1350,7 +1350,7 @@ describe("composition", () => {
|
||||
static template = xml`
|
||||
<div><t t-esc="state.counter"/><button t-on-click="state.counter++">Inc</button></div>`;
|
||||
state = useState({
|
||||
counter: 0
|
||||
counter: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1389,7 +1389,7 @@ describe("composition", () => {
|
||||
);
|
||||
class Parent extends Component {
|
||||
state = useState({
|
||||
numbers: [1, 2, 3]
|
||||
numbers: [1, 2, 3],
|
||||
});
|
||||
static components = { ChildWidget };
|
||||
}
|
||||
@@ -1429,7 +1429,7 @@ describe("composition", () => {
|
||||
class Parent extends Component {
|
||||
static template = "parent";
|
||||
state = useState({
|
||||
numbers: [1, 2, 3]
|
||||
numbers: [1, 2, 3],
|
||||
});
|
||||
static components = { ChildWidget };
|
||||
}
|
||||
@@ -1513,8 +1513,8 @@ describe("composition", () => {
|
||||
blips: [
|
||||
{ a: "a", id: 1 },
|
||||
{ b: "b", id: 2 },
|
||||
{ c: "c", id: 4 }
|
||||
]
|
||||
{ c: "c", id: 4 },
|
||||
],
|
||||
});
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -1621,8 +1621,8 @@ describe("composition", () => {
|
||||
records: [
|
||||
{ id: 1, val: 1 },
|
||||
{ id: 2, val: 2 },
|
||||
{ id: 3, val: 3 }
|
||||
]
|
||||
{ id: 3, val: 3 },
|
||||
],
|
||||
});
|
||||
static components = { ChildWidget };
|
||||
}
|
||||
@@ -2003,7 +2003,7 @@ describe("other directives with t-component", () => {
|
||||
}
|
||||
const widget = new ParentWidget();
|
||||
await widget.mount(fixture);
|
||||
(<HTMLElement>fixture).addEventListener("ev", function(e) {
|
||||
(<HTMLElement>fixture).addEventListener("ev", function (e) {
|
||||
steps.push(e.defaultPrevented);
|
||||
});
|
||||
|
||||
@@ -2038,7 +2038,7 @@ describe("other directives with t-component", () => {
|
||||
}
|
||||
const widget = new ParentWidget();
|
||||
await widget.mount(fixture);
|
||||
(<HTMLElement>fixture).addEventListener("ev", function(e) {
|
||||
(<HTMLElement>fixture).addEventListener("ev", function (e) {
|
||||
steps.push(e.defaultPrevented);
|
||||
});
|
||||
|
||||
@@ -2976,7 +2976,7 @@ describe("random stuff/miscellaneous", () => {
|
||||
"D:mounted",
|
||||
"C:mounted",
|
||||
"B:mounted",
|
||||
"A:mounted"
|
||||
"A:mounted",
|
||||
]);
|
||||
|
||||
// update
|
||||
@@ -2999,7 +2999,7 @@ describe("random stuff/miscellaneous", () => {
|
||||
"E:destroy",
|
||||
"F:mounted",
|
||||
"D:patched",
|
||||
"C:patched"
|
||||
"C:patched",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -3410,7 +3410,7 @@ describe("t-model directive", () => {
|
||||
state = useState([
|
||||
{ f: false, id: 1 },
|
||||
{ f: false, id: 2 },
|
||||
{ f: false, id: 3 }
|
||||
{ f: false, id: 3 },
|
||||
]);
|
||||
}
|
||||
const comp = new SomeComponent();
|
||||
@@ -3455,7 +3455,7 @@ describe("environment and plugins", () => {
|
||||
let bus = new EventBus();
|
||||
|
||||
// definition of a plugin
|
||||
const somePlugin = env => {
|
||||
const somePlugin = (env) => {
|
||||
env.someFlag = true;
|
||||
bus.on("some-event", null, () => {
|
||||
env.someFlag = !env.someFlag;
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("props validation", () => {
|
||||
{ type: String, ok: "1", ko: 1 },
|
||||
{ type: Object, ok: {}, ko: "1" },
|
||||
{ type: Date, ok: new Date(), ko: "1" },
|
||||
{ type: Function, ok: () => {}, ko: "1" }
|
||||
{ type: Function, ok: () => {}, ko: "1" },
|
||||
];
|
||||
|
||||
let props;
|
||||
@@ -149,7 +149,7 @@ describe("props validation", () => {
|
||||
{ type: String, ok: "1", ko: 1 },
|
||||
{ type: Object, ok: {}, ko: "1" },
|
||||
{ type: Date, ok: new Date(), ko: "1" },
|
||||
{ type: Function, ok: () => {}, ko: "1" }
|
||||
{ type: Function, ok: () => {}, ko: "1" },
|
||||
];
|
||||
|
||||
let props;
|
||||
@@ -396,7 +396,7 @@ describe("props validation", () => {
|
||||
class TestWidget extends Component {
|
||||
static template = xml`<div>hey</div>`;
|
||||
static props = {
|
||||
p: { type: Object, shape: { id: Number, url: String } }
|
||||
p: { type: Object, shape: { id: Number, url: String } },
|
||||
};
|
||||
}
|
||||
class Parent extends Component {
|
||||
@@ -458,9 +458,9 @@ describe("props validation", () => {
|
||||
type: Object,
|
||||
shape: {
|
||||
id: Number,
|
||||
url: [Boolean, { type: Array, element: Number }]
|
||||
}
|
||||
}
|
||||
url: [Boolean, { type: Array, element: Number }],
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
class Parent extends Component {
|
||||
@@ -510,10 +510,10 @@ describe("props validation", () => {
|
||||
element: {
|
||||
type: Object,
|
||||
shape: {
|
||||
num: { type: Number, optional: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
num: { type: Number, optional: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
let error;
|
||||
@@ -539,8 +539,8 @@ describe("props validation", () => {
|
||||
class TestComponent extends Component {
|
||||
static props = {
|
||||
size: {
|
||||
validate: e => ["small", "medium", "large"].includes(e)
|
||||
}
|
||||
validate: (e) => ["small", "medium", "large"].includes(e),
|
||||
},
|
||||
};
|
||||
}
|
||||
let error;
|
||||
@@ -561,13 +561,13 @@ describe("props validation", () => {
|
||||
});
|
||||
|
||||
test("can validate with a custom validator, and a type", () => {
|
||||
const validator = jest.fn(n => 0 <= n && n <= 10);
|
||||
const validator = jest.fn((n) => 0 <= n && n <= 10);
|
||||
class TestComponent extends Component {
|
||||
static props = {
|
||||
n: {
|
||||
type: Number,
|
||||
validate: validator
|
||||
}
|
||||
validate: validator,
|
||||
},
|
||||
};
|
||||
}
|
||||
let error;
|
||||
|
||||
@@ -28,7 +28,7 @@ afterEach(() => {
|
||||
|
||||
function children(w: Component): Component[] {
|
||||
const childrenMap = w.__owl__.children;
|
||||
return Object.keys(childrenMap).map(id => childrenMap[id]);
|
||||
return Object.keys(childrenMap).map((id) => childrenMap[id]);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -224,8 +224,8 @@ describe("t-slot directive", () => {
|
||||
state = useState({
|
||||
users: [
|
||||
{ id: 1, name: "Aaron" },
|
||||
{ id: 2, name: "David" }
|
||||
]
|
||||
{ id: 2, name: "David" },
|
||||
],
|
||||
});
|
||||
static components = { Link };
|
||||
}
|
||||
@@ -268,8 +268,8 @@ describe("t-slot directive", () => {
|
||||
state = useState({
|
||||
users: [
|
||||
{ id: 1, name: "Aaron" },
|
||||
{ id: 2, name: "David" }
|
||||
]
|
||||
{ id: 2, name: "David" },
|
||||
],
|
||||
});
|
||||
static components = { Link };
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ describe("unmounting and remounting", () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<span t-esc="state.val"/>`;
|
||||
state = useState({
|
||||
val: "C1"
|
||||
val: "C1",
|
||||
});
|
||||
constructor(parent, props) {
|
||||
super(parent, props);
|
||||
|
||||
@@ -14,7 +14,7 @@ describe("event bus behaviour", () => {
|
||||
expect.assertions(1);
|
||||
const bus = new EventBus();
|
||||
const owner = {};
|
||||
bus.on("event", owner, function(this: any) {
|
||||
bus.on("event", owner, function (this: any) {
|
||||
expect(this).toBe(owner);
|
||||
});
|
||||
bus.trigger("event");
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("observer", () => {
|
||||
expect(observer.rev).toBe(2);
|
||||
|
||||
expect(obj2).toEqual({
|
||||
a: 2
|
||||
a: 2,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,7 +47,7 @@ describe("observer", () => {
|
||||
expect(observer.rev).toBe(5);
|
||||
expect(obj).toEqual({
|
||||
a: null,
|
||||
b: undefined
|
||||
b: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+3
-3
@@ -9,7 +9,7 @@ import "../src/component/directive";
|
||||
import { browser } from "../src/browser";
|
||||
|
||||
// modifies scheduler to make it faster to test components
|
||||
scheduler.requestAnimationFrame = function(callback: FrameRequestCallback) {
|
||||
scheduler.requestAnimationFrame = function (callback: FrameRequestCallback) {
|
||||
setTimeout(callback, 1);
|
||||
return 1;
|
||||
};
|
||||
@@ -43,7 +43,7 @@ export function nextMicroTick(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function nextTick(): Promise<void> {
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(() => scheduler.requestAnimationFrame(() => resolve()));
|
||||
});
|
||||
}
|
||||
@@ -77,7 +77,7 @@ export function makeDeferred(): Deferred {
|
||||
export function makeTestEnv(): Env {
|
||||
return {
|
||||
qweb: new QWeb(),
|
||||
browser: browser
|
||||
browser: browser,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -10,7 +10,7 @@ import {
|
||||
onWillStart,
|
||||
onWillUpdateProps,
|
||||
useSubEnv,
|
||||
useExternalListener
|
||||
useExternalListener,
|
||||
} from "../src/hooks";
|
||||
import { xml } from "../src/tags";
|
||||
|
||||
@@ -214,7 +214,7 @@ describe("hooks", () => {
|
||||
"hook:mounted1",
|
||||
"hook:mounted2",
|
||||
"hook:willunmount2",
|
||||
"hook:willunmount1"
|
||||
"hook:willunmount1",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -560,7 +560,7 @@ describe("hooks", () => {
|
||||
test("can use onWillStart, onWillUpdateProps", async () => {
|
||||
const steps: string[] = [];
|
||||
async function slow(): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve("slow");
|
||||
}, 0);
|
||||
@@ -571,7 +571,7 @@ describe("hooks", () => {
|
||||
steps.push(await slow());
|
||||
steps.push("onWillStart");
|
||||
});
|
||||
onWillUpdateProps(async nextProps => {
|
||||
onWillUpdateProps(async (nextProps) => {
|
||||
expect(nextProps).toEqual({ value: 2 });
|
||||
steps.push(await slow());
|
||||
steps.push("onWillUpdateProps");
|
||||
@@ -581,7 +581,7 @@ describe("hooks", () => {
|
||||
onWillStart(() => {
|
||||
steps.push("on2ndStart");
|
||||
});
|
||||
onWillUpdateProps(nextProps => {
|
||||
onWillUpdateProps((nextProps) => {
|
||||
expect(nextProps).toEqual({ value: 2 });
|
||||
steps.push("on2ndUpdate");
|
||||
});
|
||||
@@ -623,7 +623,7 @@ describe("hooks", () => {
|
||||
"onWillStart",
|
||||
"on2ndUpdate",
|
||||
"slow",
|
||||
"onWillUpdateProps"
|
||||
"onWillUpdateProps",
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -486,7 +486,7 @@ describe("Portal: Basic use and DOM placement", () => {
|
||||
"parent:mounted",
|
||||
"parent:willPatch",
|
||||
"child:mounted",
|
||||
"parent:patched"
|
||||
"parent:patched",
|
||||
]);
|
||||
|
||||
parent.state.val = 2;
|
||||
@@ -499,7 +499,7 @@ describe("Portal: Basic use and DOM placement", () => {
|
||||
"parent:willPatch",
|
||||
"child:willPatch",
|
||||
"child:patched",
|
||||
"parent:patched"
|
||||
"parent:patched",
|
||||
]);
|
||||
|
||||
parent.state.hasChild = false;
|
||||
@@ -515,7 +515,7 @@ describe("Portal: Basic use and DOM placement", () => {
|
||||
"parent:patched",
|
||||
"parent:willPatch",
|
||||
"child:willUnmount",
|
||||
"parent:patched"
|
||||
"parent:patched",
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -741,7 +741,7 @@ describe("Portal: Events handling", () => {
|
||||
steps.push(ev.type as string);
|
||||
}
|
||||
}
|
||||
const bodyListener = ev => {
|
||||
const bodyListener = (ev) => {
|
||||
steps.push(`body: ${ev.type}`);
|
||||
};
|
||||
document.body.addEventListener("click", bodyListener);
|
||||
|
||||
+44
-44
@@ -195,7 +195,7 @@ describe("t-esc", () => {
|
||||
v2: undefined,
|
||||
v3: null,
|
||||
v4: 0,
|
||||
v5: ""
|
||||
v5: "",
|
||||
};
|
||||
expect(renderToString(qweb, "test", vals)).toBe(
|
||||
"<div><p>false</p><p></p><p></p><p>0</p><p></p></div>"
|
||||
@@ -486,7 +486,7 @@ describe("t-if", () => {
|
||||
cond3: false,
|
||||
cond4: false,
|
||||
m: 5,
|
||||
n: 2
|
||||
n: 2,
|
||||
};
|
||||
expect(normalize(renderToString(qweb, "test", context))).toBe("<div>andormgtnlt</div>");
|
||||
});
|
||||
@@ -625,7 +625,7 @@ describe("attributes", () => {
|
||||
test("object", () => {
|
||||
qweb.addTemplate("test", `<div t-att="value"/>`);
|
||||
const result = renderToString(qweb, "test", {
|
||||
value: { a: 1, b: 2, c: 3 }
|
||||
value: { a: 1, b: 2, c: 3 },
|
||||
});
|
||||
expect(result).toBe(`<div a="1" b="2" c="3"></div>`);
|
||||
});
|
||||
@@ -684,7 +684,7 @@ describe("attributes", () => {
|
||||
const result = renderToString(qweb, "test", {
|
||||
value1: 0,
|
||||
value2: 1,
|
||||
value3: 2
|
||||
value3: 2,
|
||||
});
|
||||
expect(result).toBe(`<div foo="a 0 is 1 of 2 ]"></div>`);
|
||||
});
|
||||
@@ -703,7 +703,7 @@ describe("attributes", () => {
|
||||
const result = renderToString(qweb, "test", {
|
||||
bar: 0,
|
||||
baz: 1,
|
||||
qux: { qux: "<>" }
|
||||
qux: { qux: "<>" },
|
||||
});
|
||||
const expected = '<div foo="<foo" bar="0" baz="<1>" qux="<>"></div>';
|
||||
expect(result).toBe(expected);
|
||||
@@ -973,7 +973,7 @@ describe("t-call (template calling", () => {
|
||||
`);
|
||||
const root = {
|
||||
val: "a",
|
||||
children: [{ val: "b", children: [{ val: "c", children: [{ val: "d" }] }] }]
|
||||
children: [{ val: "b", children: [{ val: "c", children: [{ val: "d" }] }] }],
|
||||
};
|
||||
const expected =
|
||||
"<div><div><p>a 2</p><div><p>b 3</p><div><p>c 4</p><div><p>d 5</p></div></div></div></div></div>";
|
||||
@@ -1235,7 +1235,7 @@ describe("t-on", () => {
|
||||
{
|
||||
add() {
|
||||
a = 3;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1258,7 +1258,7 @@ describe("t-on", () => {
|
||||
},
|
||||
handleDblClick() {
|
||||
steps.push("dblclick");
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1278,7 +1278,7 @@ describe("t-on", () => {
|
||||
{
|
||||
add(n) {
|
||||
a = a + n;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1295,7 +1295,7 @@ describe("t-on", () => {
|
||||
{
|
||||
add({ val }) {
|
||||
a = a + val;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1312,7 +1312,7 @@ describe("t-on", () => {
|
||||
{
|
||||
doSomething(arg) {
|
||||
expect(arg).toEqual({});
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1328,7 +1328,7 @@ describe("t-on", () => {
|
||||
{
|
||||
doSomething(arg) {
|
||||
expect(arg).toEqual({});
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1350,7 +1350,7 @@ describe("t-on", () => {
|
||||
{
|
||||
activate(action) {
|
||||
expect(action).toBe("someval");
|
||||
}
|
||||
},
|
||||
},
|
||||
{ handlers: [] }
|
||||
);
|
||||
@@ -1363,7 +1363,7 @@ describe("t-on", () => {
|
||||
let owner = {
|
||||
add() {
|
||||
expect(this).toBe(owner);
|
||||
}
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
(<HTMLElement>node).click();
|
||||
@@ -1373,8 +1373,8 @@ describe("t-on", () => {
|
||||
qweb.addTemplate("test", `<button t-on-click="state.counter++">Click</button>`);
|
||||
let owner = {
|
||||
state: {
|
||||
counter: 0
|
||||
}
|
||||
counter: 0,
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
expect(owner.state.counter).toBe(0);
|
||||
@@ -1387,10 +1387,10 @@ describe("t-on", () => {
|
||||
let owner = {
|
||||
state: {
|
||||
counter: 0,
|
||||
incrementCounter: inc => {
|
||||
incrementCounter: (inc) => {
|
||||
owner.state.counter += inc;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
expect(owner.state.counter).toBe(0);
|
||||
@@ -1402,8 +1402,8 @@ describe("t-on", () => {
|
||||
qweb.addTemplate("test", `<button t-on-click="state.flag = !state.flag">Toggle</button>`);
|
||||
let owner = {
|
||||
state: {
|
||||
flag: true
|
||||
}
|
||||
flag: true,
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
expect(owner.state.flag).toBe(true);
|
||||
@@ -1420,8 +1420,8 @@ describe("t-on", () => {
|
||||
return n + 1;
|
||||
},
|
||||
state: {
|
||||
n: 11
|
||||
}
|
||||
n: 11,
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
expect(owner.state.n).toBe(11);
|
||||
@@ -1437,7 +1437,7 @@ describe("t-on", () => {
|
||||
let owner = {
|
||||
update() {
|
||||
expect(this).toBe(owner);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const node = renderToDOM(qweb, "main", owner, { handlers: [] });
|
||||
@@ -1454,7 +1454,7 @@ describe("t-on", () => {
|
||||
expect(this).toBe(owner);
|
||||
expect(val).toBe(444);
|
||||
},
|
||||
value: 444
|
||||
value: 444,
|
||||
};
|
||||
|
||||
const node = renderToDOM(qweb, "main", owner, { handlers: [] });
|
||||
@@ -1483,7 +1483,7 @@ describe("t-on", () => {
|
||||
onClickPreventedAndStopped(e) {
|
||||
expect(e.defaultPrevented).toBe(true);
|
||||
expect(e.cancelBubble).toBe(true);
|
||||
}
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
|
||||
@@ -1509,7 +1509,7 @@ describe("t-on", () => {
|
||||
},
|
||||
onClickSelf(e) {
|
||||
steps.push("onClickSelf");
|
||||
}
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
|
||||
@@ -1533,10 +1533,10 @@ describe("t-on", () => {
|
||||
);
|
||||
let steps: boolean[] = [];
|
||||
let owner = {
|
||||
onClick() {}
|
||||
onClick() {},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
(<HTMLElement>node).addEventListener("click", function(e) {
|
||||
(<HTMLElement>node).addEventListener("click", function (e) {
|
||||
steps.push(e.defaultPrevented);
|
||||
});
|
||||
|
||||
@@ -1558,10 +1558,10 @@ describe("t-on", () => {
|
||||
);
|
||||
let steps: boolean[] = [];
|
||||
let owner = {
|
||||
onClick() {}
|
||||
onClick() {},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
(<HTMLElement>node).addEventListener("click", function(e) {
|
||||
(<HTMLElement>node).addEventListener("click", function (e) {
|
||||
steps.push(e.defaultPrevented);
|
||||
});
|
||||
|
||||
@@ -1589,13 +1589,13 @@ describe("t-on", () => {
|
||||
const owner = {
|
||||
projects: [
|
||||
{ id: 1, name: "Project 1" },
|
||||
{ id: 2, name: "Project 2" }
|
||||
{ id: 2, name: "Project 2" },
|
||||
],
|
||||
|
||||
onEdit(projectId, ev) {
|
||||
expect(ev.defaultPrevented).toBe(true);
|
||||
steps.push(projectId);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
@@ -1620,7 +1620,7 @@ describe("t-on", () => {
|
||||
);
|
||||
const node = renderToDOM(qweb, "test", {}, { handlers: [] });
|
||||
|
||||
node.addEventListener("click", e => {
|
||||
node.addEventListener("click", (e) => {
|
||||
expect(e.defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
@@ -1636,7 +1636,7 @@ describe("t-on", () => {
|
||||
text: "Click here",
|
||||
onClick() {
|
||||
steps.push("onClick");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
@@ -1655,7 +1655,7 @@ describe("t-on", () => {
|
||||
html: "Click <b>here</b>",
|
||||
onClick() {
|
||||
steps.push("onClick");
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
@@ -1682,7 +1682,7 @@ describe("t-on", () => {
|
||||
},
|
||||
doSomething() {
|
||||
steps.push("normal");
|
||||
}
|
||||
},
|
||||
};
|
||||
const node = renderToDOM(qweb, "test", owner, { handlers: [] });
|
||||
|
||||
@@ -1846,7 +1846,7 @@ describe("t-key", () => {
|
||||
);
|
||||
expect(
|
||||
renderToString(qweb, "test", {
|
||||
beers: [{ id: 12, name: "Chimay Rouge" }]
|
||||
beers: [{ id: 12, name: "Chimay Rouge" }],
|
||||
})
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
@@ -1959,9 +1959,9 @@ describe("properly support svg", () => {
|
||||
describe("translation support", () => {
|
||||
test("can translate node content", () => {
|
||||
const translations = {
|
||||
word: "mot"
|
||||
word: "mot",
|
||||
};
|
||||
const translateFn = expr => translations[expr] || expr;
|
||||
const translateFn = (expr) => translations[expr] || expr;
|
||||
const qweb = new QWeb({ translateFn });
|
||||
qweb.addTemplate("test", "<div>word</div>");
|
||||
expect(renderToString(qweb, "test")).toBe("<div>mot</div>");
|
||||
@@ -1969,9 +1969,9 @@ describe("translation support", () => {
|
||||
|
||||
test("does not translate node content if disabled", () => {
|
||||
const translations = {
|
||||
word: "mot"
|
||||
word: "mot",
|
||||
};
|
||||
const translateFn = expr => translations[expr] || expr;
|
||||
const translateFn = (expr) => translations[expr] || expr;
|
||||
const qweb = new QWeb({ translateFn });
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
@@ -1986,9 +1986,9 @@ describe("translation support", () => {
|
||||
|
||||
test("some attributes are translated", () => {
|
||||
const translations = {
|
||||
word: "mot"
|
||||
word: "mot",
|
||||
};
|
||||
const translateFn = expr => translations[expr] || expr;
|
||||
const translateFn = (expr) => translations[expr] || expr;
|
||||
const qweb = new QWeb({ translateFn });
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
|
||||
@@ -6,12 +6,12 @@ describe("tokenizer", () => {
|
||||
|
||||
expect(tokenize("{}")).toEqual([
|
||||
{ type: "LEFT_BRACE", value: "{" },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
{ type: "RIGHT_BRACE", value: "}" },
|
||||
]);
|
||||
expect(tokenize("{ }}")).toEqual([
|
||||
{ type: "LEFT_BRACE", value: "{" },
|
||||
{ type: "RIGHT_BRACE", value: "}" },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
{ type: "RIGHT_BRACE", value: "}" },
|
||||
]);
|
||||
expect(tokenize("a")).toEqual([{ type: "SYMBOL", value: "a" }]);
|
||||
expect(tokenize("true")).toEqual([{ type: "SYMBOL", value: "true" }]);
|
||||
@@ -25,15 +25,15 @@ describe("tokenizer", () => {
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
{ type: "COLON", value: ":" },
|
||||
{ type: "VALUE", value: "2" },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
{ type: "RIGHT_BRACE", value: "}" },
|
||||
]);
|
||||
expect(tokenize("a,")).toEqual([
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
{ type: "COMMA", value: "," }
|
||||
{ type: "COMMA", value: "," },
|
||||
]);
|
||||
expect(tokenize("][")).toEqual([
|
||||
{ type: "RIGHT_BRACKET", value: "]" },
|
||||
{ type: "LEFT_BRACKET", value: "[" }
|
||||
{ type: "LEFT_BRACKET", value: "[" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -44,23 +44,23 @@ describe("tokenizer", () => {
|
||||
{ type: "OPERATOR", value: "<" },
|
||||
{ type: "OPERATOR", value: ">" },
|
||||
{ type: "OPERATOR", value: "!==" },
|
||||
{ type: "OPERATOR", value: "!=" }
|
||||
{ type: "OPERATOR", value: "!=" },
|
||||
]);
|
||||
expect(tokenize("typeof a")).toEqual([
|
||||
{ type: "OPERATOR", value: "typeof " },
|
||||
{ type: "SYMBOL", value: "a" }
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
]);
|
||||
|
||||
expect(tokenize("a...1")).toEqual([
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
{ type: "OPERATOR", value: "..." },
|
||||
{ type: "VALUE", value: "1" }
|
||||
{ type: "VALUE", value: "1" },
|
||||
]);
|
||||
|
||||
expect(tokenize("a in b")).toEqual([
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
{ type: "OPERATOR", value: "in " },
|
||||
{ type: "SYMBOL", value: "b" }
|
||||
{ type: "SYMBOL", value: "b" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -76,7 +76,7 @@ describe("tokenizer", () => {
|
||||
expect(tokenize('"hello ged"')).toEqual([{ type: "VALUE", value: '"hello ged"' }]);
|
||||
expect(tokenize('"hello ged"}')).toEqual([
|
||||
{ type: "VALUE", value: '"hello ged"' },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
{ type: "RIGHT_BRACE", value: "}" },
|
||||
]);
|
||||
expect(tokenize('"hello \\"ged\\""')).toEqual([{ type: "VALUE", value: '"hello \\"ged\\""' }]);
|
||||
});
|
||||
|
||||
@@ -37,7 +37,7 @@ describe("Link component", () => {
|
||||
|
||||
const routes = [
|
||||
{ name: "about", path: "/about" },
|
||||
{ name: "users", path: "/users" }
|
||||
{ name: "users", path: "/users" },
|
||||
];
|
||||
|
||||
router = new TestRouter(env, routes, { mode: "history" });
|
||||
@@ -71,7 +71,7 @@ describe("Link component", () => {
|
||||
|
||||
const routes = [
|
||||
{ name: "about", path: "/about" },
|
||||
{ name: "users", path: "/users" }
|
||||
{ name: "users", path: "/users" },
|
||||
];
|
||||
|
||||
router = new TestRouter(env, routes, { mode: "history" });
|
||||
@@ -81,7 +81,7 @@ describe("Link component", () => {
|
||||
|
||||
expect(window.location.pathname).toBe("/users");
|
||||
var evt = new MouseEvent("click", {
|
||||
button: 1
|
||||
button: 1,
|
||||
});
|
||||
|
||||
fixture.querySelector("a")!.dispatchEvent(evt);
|
||||
|
||||
@@ -41,7 +41,7 @@ describe("RouteComponent", () => {
|
||||
|
||||
const routes = [
|
||||
{ name: "about", path: "/about", component: About },
|
||||
{ name: "users", path: "/users", component: Users }
|
||||
{ name: "users", path: "/users", component: Users },
|
||||
];
|
||||
|
||||
router = new TestRouter(env, routes, { mode: "history" });
|
||||
|
||||
+10
-10
@@ -21,7 +21,7 @@ describe("router miscellaneous", () => {
|
||||
test("validate routes shape", () => {
|
||||
expect(() => {
|
||||
router = new TestRouter(env, [
|
||||
{ name: "someroute", path: "/some/path", redirect: { abc: "hey" } as Destination }
|
||||
{ name: "someroute", path: "/some/path", redirect: { abc: "hey" } as Destination },
|
||||
]);
|
||||
}).toThrow(`Invalid destination: {"abc":"hey"}`);
|
||||
});
|
||||
@@ -133,7 +133,7 @@ describe("getRouteParams", () => {
|
||||
test("match some parameterized routes", () => {
|
||||
router = new TestRouter(env, []);
|
||||
expect(router["getRouteParams"]({ path: "/invoices/{{id}}" } as Route, "/invoices/3")).toEqual({
|
||||
id: "3"
|
||||
id: "3",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -141,7 +141,7 @@ describe("getRouteParams", () => {
|
||||
router = new TestRouter(env, [], { mode: "hash" });
|
||||
expect(router["getRouteParams"]({ path: "/invoices/{{id}}" } as Route, "#/invoices/3")).toEqual(
|
||||
{
|
||||
id: "3"
|
||||
id: "3",
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -151,7 +151,7 @@ describe("getRouteParams", () => {
|
||||
expect(
|
||||
router["getRouteParams"]({ path: "/invoices/{{id.number}}" } as Route, "/invoices/3")
|
||||
).toEqual({
|
||||
id: 3
|
||||
id: 3,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -160,7 +160,7 @@ describe("getRouteParams", () => {
|
||||
expect(
|
||||
router["getRouteParams"]({ path: "/invoices/{{id.number}}" } as Route, "#/invoices/3")
|
||||
).toEqual({
|
||||
id: 3
|
||||
id: 3,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -169,7 +169,7 @@ describe("redirect", () => {
|
||||
test("can redirect to other route", async () => {
|
||||
router = new TestRouter(env, [
|
||||
{ name: "routea", path: "/some/path" },
|
||||
{ name: "routeb", path: "/some/other/path", redirect: { to: "routea" } }
|
||||
{ name: "routeb", path: "/some/other/path", redirect: { to: "routea" } },
|
||||
]);
|
||||
|
||||
await router.start();
|
||||
@@ -182,7 +182,7 @@ describe("redirect", () => {
|
||||
test("can redirect to other path", async () => {
|
||||
router = new TestRouter(env, [
|
||||
{ name: "routea", path: "/some/path" },
|
||||
{ name: "routeb", path: "/some/other/path", redirect: { path: "/some/path" } }
|
||||
{ name: "routeb", path: "/some/other/path", redirect: { path: "/some/path" } },
|
||||
]);
|
||||
router.navigate = jest.fn(router.navigate);
|
||||
|
||||
@@ -214,7 +214,7 @@ describe("beforeRouteEnter", () => {
|
||||
const guard = jest.fn(() => false);
|
||||
router = new TestRouter(env, [
|
||||
{ name: "routea", path: "/some/patha" },
|
||||
{ name: "routeb", path: "/some/pathb", beforeRouteEnter: guard }
|
||||
{ name: "routeb", path: "/some/pathb", beforeRouteEnter: guard },
|
||||
]);
|
||||
|
||||
await router.start();
|
||||
@@ -235,7 +235,7 @@ describe("beforeRouteEnter", () => {
|
||||
router = new TestRouter(env, [
|
||||
{ name: "routea", path: "/some/patha" },
|
||||
{ name: "routeb", path: "/some/pathb", beforeRouteEnter: guard },
|
||||
{ name: "routec", path: "/some/pathc" }
|
||||
{ name: "routec", path: "/some/pathc" },
|
||||
]);
|
||||
|
||||
await router.start();
|
||||
@@ -255,7 +255,7 @@ describe("beforeRouteEnter", () => {
|
||||
});
|
||||
router = new TestRouter(env, [
|
||||
{ name: "landing", path: "/", beforeRouteEnter: guard },
|
||||
{ name: "otherroute", path: "/some/other/route" }
|
||||
{ name: "otherroute", path: "/some/other/route" },
|
||||
]);
|
||||
|
||||
expect(window.location.pathname).toBe("/");
|
||||
|
||||
+28
-28
@@ -8,7 +8,7 @@ describe("basic use", () => {
|
||||
const actions = {
|
||||
inc({ state }, delta) {
|
||||
state.n += delta;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -25,7 +25,7 @@ describe("basic use", () => {
|
||||
state.n1 += delta1;
|
||||
state.n2 += delta2;
|
||||
state.n3 += delta3;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -47,7 +47,7 @@ describe("basic use", () => {
|
||||
},
|
||||
inc100({ dispatch }) {
|
||||
dispatch("inc", 100);
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("basic use", () => {
|
||||
const actions = {
|
||||
inc({ state }) {
|
||||
return ++state.n;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -87,7 +87,7 @@ describe("basic use", () => {
|
||||
async setTo10({ dispatch }) {
|
||||
await Promise.resolve();
|
||||
dispatch("setN", 10);
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -115,7 +115,7 @@ describe("basic use", () => {
|
||||
await Promise.resolve();
|
||||
dispatch("setN", 10);
|
||||
return 5;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -132,7 +132,7 @@ describe("basic use", () => {
|
||||
const actions = {
|
||||
someaction({ env }) {
|
||||
expect(env).toBe(someEnv);
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state: {}, actions, env: someEnv });
|
||||
|
||||
@@ -145,15 +145,15 @@ describe("basic use", () => {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "bertinchamps",
|
||||
tasterID: 1
|
||||
}
|
||||
tasterID: 1,
|
||||
},
|
||||
},
|
||||
tasters: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "aaron"
|
||||
}
|
||||
}
|
||||
name: "aaron",
|
||||
},
|
||||
},
|
||||
};
|
||||
const getters: { [key: string]: Getter } = {
|
||||
beerTasterName({ state }, beerID) {
|
||||
@@ -161,7 +161,7 @@ describe("basic use", () => {
|
||||
},
|
||||
bestBeerName({ state }) {
|
||||
return state.beers[1].name;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions: {}, getters });
|
||||
expect(store.getters).toBeDefined();
|
||||
@@ -176,15 +176,15 @@ describe("basic use", () => {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "bertinchamps",
|
||||
tasterID: 1
|
||||
}
|
||||
tasterID: 1,
|
||||
},
|
||||
},
|
||||
tasters: {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "aaron"
|
||||
}
|
||||
}
|
||||
name: "aaron",
|
||||
},
|
||||
},
|
||||
};
|
||||
const getters = {
|
||||
beerTasterName({ state }, beerID) {
|
||||
@@ -192,14 +192,14 @@ describe("basic use", () => {
|
||||
},
|
||||
bestBeerName({ state }) {
|
||||
return state.beers[1].name;
|
||||
}
|
||||
},
|
||||
};
|
||||
const actions = {
|
||||
action({ getters }) {
|
||||
expect(getters).toBeDefined();
|
||||
expect(getters.bestBeerName()).toBe("bertinchamps");
|
||||
expect(getters.beerTasterName(1)).toBe("aaron");
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions, getters });
|
||||
store.dispatch("action");
|
||||
@@ -215,7 +215,7 @@ describe("basic use", () => {
|
||||
},
|
||||
c({}, i) {
|
||||
return `c${i}`;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ getters, state: {}, actions: {} });
|
||||
|
||||
@@ -226,7 +226,7 @@ describe("basic use", () => {
|
||||
describe("advanced state properties", () => {
|
||||
test("state in the store is reference equal after mutation", async () => {
|
||||
const actions = {
|
||||
donothing() {}
|
||||
donothing() {},
|
||||
};
|
||||
const store = new Store({ state: {}, actions });
|
||||
const state = store.state;
|
||||
@@ -242,7 +242,7 @@ describe("advanced state properties", () => {
|
||||
expect(state.a.length).toBe(3);
|
||||
const l = state.a.push(53);
|
||||
expect(l).toBe(4);
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
store.dispatch("m");
|
||||
@@ -253,11 +253,11 @@ describe("advanced state properties", () => {
|
||||
const actions = {
|
||||
dosomething({ state }) {
|
||||
Object.assign(state.westmalle, { a: 3, b: 4 });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({
|
||||
state: { westmalle: { a: 1, b: 2 } },
|
||||
actions
|
||||
actions,
|
||||
});
|
||||
store.dispatch("dosomething");
|
||||
expect(store.state.westmalle).toEqual({ a: 3, b: 4 });
|
||||
@@ -267,7 +267,7 @@ describe("advanced state properties", () => {
|
||||
const actions = {
|
||||
inc({ state }) {
|
||||
state.counter++;
|
||||
}
|
||||
},
|
||||
};
|
||||
const state = { counter: 0 };
|
||||
const store = new Store({ state, actions });
|
||||
@@ -284,7 +284,7 @@ describe("updates triggered by the store", () => {
|
||||
const actions = {
|
||||
inc({ state }, delta) {
|
||||
state.n += delta;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
store.on("update", null, () => updateCounter++);
|
||||
@@ -308,7 +308,7 @@ describe("updates triggered by the store", () => {
|
||||
noop2({ state }) {
|
||||
const val = state.n;
|
||||
state.n = val;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
store.on("update", null, () => updateCounter++);
|
||||
|
||||
+90
-90
@@ -25,7 +25,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
addTodo({ state }, msg) {
|
||||
state.todos.push({ msg, id: nextId++ });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -34,7 +34,7 @@ describe("connecting a component to store", () => {
|
||||
<div>
|
||||
<span t-foreach="todos" t-key="todo.id" t-as="todo"><t t-esc="todo.msg"/></span>
|
||||
</div>`;
|
||||
todos = useStore(state => state.todos);
|
||||
todos = useStore((state) => state.todos);
|
||||
}
|
||||
|
||||
(<any>env).store = store;
|
||||
@@ -56,7 +56,7 @@ describe("connecting a component to store", () => {
|
||||
},
|
||||
setNotNull({ state }) {
|
||||
state.nullValue = "ok";
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -70,15 +70,15 @@ describe("connecting a component to store", () => {
|
||||
nullValue: string;
|
||||
constructor() {
|
||||
super();
|
||||
this.isBoolean = useStore(state => state.isBoolean, {
|
||||
onUpdate: isBoolean => {
|
||||
this.isBoolean = useStore((state) => state.isBoolean, {
|
||||
onUpdate: (isBoolean) => {
|
||||
this.isBoolean = isBoolean;
|
||||
}
|
||||
},
|
||||
});
|
||||
this.nullValue = useStore(state => state.nullValue, {
|
||||
onUpdate: nullValue => {
|
||||
this.nullValue = useStore((state) => state.nullValue, {
|
||||
onUpdate: (nullValue) => {
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -105,15 +105,15 @@ describe("connecting a component to store", () => {
|
||||
class App extends Component {
|
||||
static template = xml`<div t-esc="mapAdd"/>`;
|
||||
storeProps = {
|
||||
array: useStore(state => {
|
||||
array: useStore((state) => {
|
||||
if (state.useSmallArray) {
|
||||
return state.smallerArray;
|
||||
}
|
||||
return state.biggerArray;
|
||||
})
|
||||
}),
|
||||
};
|
||||
get mapAdd() {
|
||||
return this.storeProps.array.map(a => {
|
||||
return this.storeProps.array.map((a) => {
|
||||
return a + 1;
|
||||
});
|
||||
}
|
||||
@@ -133,7 +133,7 @@ describe("connecting a component to store", () => {
|
||||
test("throw error if no store is found", async () => {
|
||||
class App extends Component {
|
||||
static template = xml`<div></div>`;
|
||||
todos = useStore(state => state.todos);
|
||||
todos = useStore((state) => state.todos);
|
||||
}
|
||||
|
||||
let error;
|
||||
@@ -153,7 +153,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
class App extends Component {
|
||||
static template = xml`<div/>`;
|
||||
storeState = useStore(state => state.a);
|
||||
storeState = useStore((state) => state.a);
|
||||
}
|
||||
|
||||
(<any>env).store = store;
|
||||
@@ -170,7 +170,7 @@ describe("connecting a component to store", () => {
|
||||
doSomething({ state }) {
|
||||
state.a = 2;
|
||||
state.b = 3;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -180,8 +180,8 @@ describe("connecting a component to store", () => {
|
||||
<span t-esc="a.value"/>
|
||||
<span t-esc="b.value"/>
|
||||
</div>`;
|
||||
a = useStore(state => ({ value: state.a }));
|
||||
b = useStore(state => ({ value: state.b }));
|
||||
a = useStore((state) => ({ value: state.a }));
|
||||
b = useStore((state) => ({ value: state.b }));
|
||||
}
|
||||
App.prototype.__render = jest.fn(App.prototype.__render);
|
||||
|
||||
@@ -204,7 +204,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
addTodo({ state }, msg) {
|
||||
state.todos.push({ msg, id: nextId++ });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -213,7 +213,7 @@ describe("connecting a component to store", () => {
|
||||
<div>
|
||||
<span t-foreach="todos" t-key="todo.id" t-as="todo"><t t-esc="todo.msg"/></span>
|
||||
</div>`;
|
||||
todos = useStore(state => state.todos);
|
||||
todos = useStore((state) => state.todos);
|
||||
}
|
||||
App.prototype.__render = jest.fn(App.prototype.__render);
|
||||
|
||||
@@ -241,13 +241,13 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
addTodo({ state }, msg) {
|
||||
state.todos.push({ msg, id: nextId++ });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="nbrTodos.value"/></div>`;
|
||||
nbrTodos = useStore(state => ({ value: state.todos.length }));
|
||||
nbrTodos = useStore((state) => ({ value: state.todos.length }));
|
||||
}
|
||||
|
||||
(<any>env).store = store;
|
||||
@@ -270,12 +270,12 @@ describe("connecting a component to store", () => {
|
||||
},
|
||||
incrementA({ state }) {
|
||||
state.a++;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="nbrTodos.value"/></div>`;
|
||||
nbrTodos = useStore(state => ({ value: state.todos.length }), { isEqual: shallowEqual });
|
||||
nbrTodos = useStore((state) => ({ value: state.todos.length }), { isEqual: shallowEqual });
|
||||
}
|
||||
App.prototype.__render = jest.fn(App.prototype.__render);
|
||||
|
||||
@@ -303,7 +303,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
addTodo({ state }, msg) {
|
||||
state.todos.push({ msg, id: nextId++ });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
@@ -312,7 +312,7 @@ describe("connecting a component to store", () => {
|
||||
<div>
|
||||
<span t-foreach="todos" t-key="todo.id" t-as="todo"><t t-esc="todo.msg"/></span>
|
||||
</div>`;
|
||||
todos = useStore(state => state.todos, { store });
|
||||
todos = useStore((state) => state.todos, { store });
|
||||
}
|
||||
|
||||
const app = new App();
|
||||
@@ -331,8 +331,8 @@ describe("connecting a component to store", () => {
|
||||
actions: {
|
||||
inc({ state }) {
|
||||
state.value++;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
(<any>env).store = store;
|
||||
|
||||
@@ -342,7 +342,7 @@ describe("connecting a component to store", () => {
|
||||
<button t-on-click="dispatch('inc')">Inc</button>
|
||||
<span><t t-esc="storeState.value"/></span>
|
||||
</div>`;
|
||||
storeState = useStore(state => state);
|
||||
storeState = useStore((state) => state);
|
||||
dispatch = useDispatch();
|
||||
}
|
||||
const app = new App();
|
||||
@@ -360,15 +360,15 @@ describe("connecting a component to store", () => {
|
||||
const state = {
|
||||
todos: [
|
||||
{ id: 1, text: "jupiler" },
|
||||
{ id: 2, text: "chimay" }
|
||||
]
|
||||
{ id: 2, text: "chimay" },
|
||||
],
|
||||
};
|
||||
const store = new Store({ state, actions: {} });
|
||||
|
||||
class TodoItem extends Component {
|
||||
static template = xml`<span><t t-esc="todo.text"/></span>`;
|
||||
todo = useStore((state, props) => {
|
||||
return state.todos.find(t => t.id === props.todoId);
|
||||
return state.todos.find((t) => t.id === props.todoId);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -395,14 +395,14 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
addTodo({ state }, text) {
|
||||
state.todos.push({ text, id: nextId++ });
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
|
||||
class TodoItem extends Component {
|
||||
static template = xml`<span><t t-esc="todo.text"/></span>`;
|
||||
todo = useStore((state, props) => {
|
||||
return state.todos.find(t => t.id === props.id);
|
||||
return state.todos.find((t) => t.id === props.id);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -412,7 +412,7 @@ describe("connecting a component to store", () => {
|
||||
<TodoItem t-foreach="todos" t-as="todo" id="todo.id" t-key="todo.id"/>
|
||||
</div>`;
|
||||
static components = { TodoItem };
|
||||
todos = useStore(state => state.todos);
|
||||
todos = useStore((state) => state.todos);
|
||||
}
|
||||
|
||||
(<any>env).store = store;
|
||||
@@ -431,16 +431,16 @@ describe("connecting a component to store", () => {
|
||||
importantID: 1,
|
||||
todos: [
|
||||
{ id: 1, text: "jupiler" },
|
||||
{ id: 2, text: "bertinchamps" }
|
||||
]
|
||||
{ id: 2, text: "bertinchamps" },
|
||||
],
|
||||
};
|
||||
const getters = {
|
||||
importantTodoText({ state }) {
|
||||
return state.todos.find(todo => todo.id === state.importantID).text;
|
||||
return state.todos.find((todo) => todo.id === state.importantID).text;
|
||||
},
|
||||
text({ state }, id) {
|
||||
return state.todos.find(todo => todo.id === id).text;
|
||||
}
|
||||
return state.todos.find((todo) => todo.id === id).text;
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, getters });
|
||||
|
||||
@@ -452,10 +452,10 @@ describe("connecting a component to store", () => {
|
||||
</div>`;
|
||||
getters = useGetters();
|
||||
storeProps = useStore((state, props) => {
|
||||
const todo = state.todos.find(t => t.id === props.id);
|
||||
const todo = state.todos.find((t) => t.id === props.id);
|
||||
return {
|
||||
activeTodoText: this.getters.text(todo.id),
|
||||
importantTodoText: this.getters.importantTodoText()
|
||||
importantTodoText: this.getters.importantTodoText(),
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -468,7 +468,7 @@ describe("connecting a component to store", () => {
|
||||
<TodoItem id="todo.id" t-key="todo.id"/>
|
||||
</t>
|
||||
</div>`;
|
||||
todos = useStore(state => state.todos);
|
||||
todos = useStore((state) => state.todos);
|
||||
}
|
||||
|
||||
(<any>env).store = store;
|
||||
@@ -513,13 +513,13 @@ describe("connecting a component to store", () => {
|
||||
</div>`;
|
||||
|
||||
// we have here a new object
|
||||
data = useStore(state => ({ beers: state.beers, otherKey: 1 }));
|
||||
data = useStore((state) => ({ beers: state.beers, otherKey: 1 }));
|
||||
}
|
||||
|
||||
const actions = {
|
||||
addBeer({ state }, name) {
|
||||
state.beers.push({ name });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const state = { beers: [{ name: "jupiler" }] };
|
||||
@@ -542,9 +542,9 @@ describe("connecting a component to store", () => {
|
||||
class Beer extends Component {
|
||||
static template = xml`<span><t t-esc="beer.name"/></span>`;
|
||||
beer = useStore((state, props) => state.beers[props.id], {
|
||||
onUpdate: result => {
|
||||
onUpdate: (result) => {
|
||||
++counter;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
renameBeer({ state }, { id, name }) {
|
||||
state.beers[id].name = name;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
(<any>env).store = store;
|
||||
@@ -609,7 +609,7 @@ describe("connecting a component to store", () => {
|
||||
data = useStore((state, props) => ({
|
||||
selected: state.beers[props.id],
|
||||
consumed: state.beers[state.consumedID] || null,
|
||||
taster: state.taster
|
||||
taster: state.taster,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -622,14 +622,14 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
consume({ state }, beerId) {
|
||||
state.consumedID = beerId;
|
||||
}
|
||||
},
|
||||
};
|
||||
const state = {
|
||||
beers: {
|
||||
1: { name: "jupiler" }
|
||||
1: { name: "jupiler" },
|
||||
},
|
||||
consumedID: null,
|
||||
taster: "aaron"
|
||||
taster: "aaron",
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
(<any>env).store = store;
|
||||
@@ -665,11 +665,11 @@ describe("connecting a component to store", () => {
|
||||
<span t-if="info.selected">selected:<t t-esc="info.selected.name"/></span>
|
||||
<span t-if="info.consumed">consumed:<t t-esc="info.consumed.name"/></span>
|
||||
</div>`;
|
||||
info = useStore(function(state, props) {
|
||||
info = useStore(function (state, props) {
|
||||
return {
|
||||
selected: state.beers[props.id],
|
||||
consumed: state.beers[state.consumedID] || null,
|
||||
taster: state.taster
|
||||
taster: state.taster,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -689,14 +689,14 @@ describe("connecting a component to store", () => {
|
||||
},
|
||||
renameBeer({ state }, { beerId, name }) {
|
||||
state.beers[beerId].name = name;
|
||||
}
|
||||
},
|
||||
};
|
||||
const state = {
|
||||
beers: {
|
||||
1: { name: "jupiler" }
|
||||
1: { name: "jupiler" },
|
||||
},
|
||||
consumedID: null,
|
||||
taster: "aaron"
|
||||
taster: "aaron",
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
(<any>env).store = store;
|
||||
@@ -747,11 +747,11 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
setValue({ state }, val) {
|
||||
state.x.val = val;
|
||||
}
|
||||
},
|
||||
};
|
||||
class Parent extends Component {
|
||||
static template = xml`<div><t t-esc="x.val"/></div>`;
|
||||
x = useStore(state => {
|
||||
x = useStore((state) => {
|
||||
return Object.assign({}, state.x);
|
||||
});
|
||||
dispatch = useDispatch();
|
||||
@@ -782,11 +782,11 @@ describe("connecting a component to store", () => {
|
||||
static template = xml`<div><Child key="state.current"/></div>`;
|
||||
static components = { Child };
|
||||
|
||||
state = useStore(state => {
|
||||
state = useStore((state) => {
|
||||
steps.push("parent");
|
||||
return {
|
||||
current: state.current,
|
||||
isvisible: state.isvisible
|
||||
isvisible: state.isvisible,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -795,7 +795,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
setCurrent({ state }, c) {
|
||||
state.current = c;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const store = new Store({ state, actions });
|
||||
@@ -831,7 +831,7 @@ describe("connecting a component to store", () => {
|
||||
<Child t-if="state.flag" someId="state.someId"/>
|
||||
</div>`;
|
||||
static components = { Child };
|
||||
state = useStore(s => {
|
||||
state = useStore((s) => {
|
||||
steps.push("parent");
|
||||
return { flag: s.flag, someId: s.someId };
|
||||
});
|
||||
@@ -846,7 +846,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
setFlagToFalse({ state }) {
|
||||
state.flag = false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const store = new Store({ state, actions });
|
||||
@@ -874,15 +874,15 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
editTodo({ state }) {
|
||||
state.todos[1].title = "abc";
|
||||
}
|
||||
},
|
||||
};
|
||||
const todos = { 1: { id: 1, title: "kikoou" } };
|
||||
const state = {
|
||||
todos
|
||||
todos,
|
||||
};
|
||||
const store = new Store({
|
||||
state,
|
||||
actions
|
||||
actions,
|
||||
});
|
||||
|
||||
class TodoItem extends Component<{}, EnvWithStore> {
|
||||
@@ -894,7 +894,7 @@ describe("connecting a component to store", () => {
|
||||
state = useStore((state, props) => {
|
||||
steps.push("item:usestore");
|
||||
return {
|
||||
todo: state.todos[props.id]
|
||||
todo: state.todos[props.id],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -914,7 +914,7 @@ describe("connecting a component to store", () => {
|
||||
</t>
|
||||
</div>`;
|
||||
static components = { TodoItem };
|
||||
state = useStore(state => {
|
||||
state = useStore((state) => {
|
||||
steps.push("app:usestore");
|
||||
return { todos: state.todos };
|
||||
});
|
||||
@@ -947,15 +947,15 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
removeTodo({ state }) {
|
||||
delete state.todos[1];
|
||||
}
|
||||
},
|
||||
};
|
||||
const todos = { 1: { id: 1, title: "kikoou" } };
|
||||
const state = {
|
||||
todos
|
||||
todos,
|
||||
};
|
||||
const store = new Store({
|
||||
state,
|
||||
actions
|
||||
actions,
|
||||
});
|
||||
|
||||
class TodoItem extends Component<{}, EnvWithStore> {
|
||||
@@ -967,7 +967,7 @@ describe("connecting a component to store", () => {
|
||||
state = useStore((state, props) => {
|
||||
steps.push("item:usestore");
|
||||
return {
|
||||
todo: state.todos[props.id]
|
||||
todo: state.todos[props.id],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -988,7 +988,7 @@ describe("connecting a component to store", () => {
|
||||
</t>
|
||||
</div>`;
|
||||
static components = { TodoItem };
|
||||
state = useStore(state => {
|
||||
state = useStore((state) => {
|
||||
steps.push("app:usestore");
|
||||
return { todos: state.todos };
|
||||
});
|
||||
@@ -1016,7 +1016,7 @@ describe("connecting a component to store", () => {
|
||||
"item:usestore",
|
||||
"item:render",
|
||||
"app:usestore",
|
||||
"app:render"
|
||||
"app:render",
|
||||
]);
|
||||
expect(fixture.innerHTML).toBe('<div class="todoapp"></div>');
|
||||
});
|
||||
@@ -1026,7 +1026,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="store.msg"/></div>`;
|
||||
store = useStore(s => ({ msg: s.msg }));
|
||||
store = useStore((s) => ({ msg: s.msg }));
|
||||
|
||||
willPatch() {
|
||||
steps.push("willpatch");
|
||||
@@ -1040,7 +1040,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
setMsg({ state }, c) {
|
||||
state.msg = c;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const store = new Store({ state, actions });
|
||||
@@ -1061,7 +1061,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
class Child extends Component {
|
||||
static template = xml`<div><t t-esc="store.val"/></div>`;
|
||||
store = useStore(s => s);
|
||||
store = useStore((s) => s);
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
@@ -1099,7 +1099,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
class Child extends Component {
|
||||
static template = xml`<div><t t-esc="store.val"/></div>`;
|
||||
store = useStore(s => {
|
||||
store = useStore((s) => {
|
||||
steps.push("child selector");
|
||||
return s;
|
||||
});
|
||||
@@ -1107,7 +1107,7 @@ describe("connecting a component to store", () => {
|
||||
class Parent extends Component {
|
||||
static template = xml`<div><Child t-if="store.child" /></div>`;
|
||||
static components = { Child };
|
||||
store = useStore(s => {
|
||||
store = useStore((s) => {
|
||||
steps.push("parent selector");
|
||||
return s;
|
||||
});
|
||||
@@ -1118,7 +1118,7 @@ describe("connecting a component to store", () => {
|
||||
const actions = {
|
||||
toggleChild({ state }) {
|
||||
state.child = !state.child;
|
||||
}
|
||||
},
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
(<any>env).store = store;
|
||||
@@ -1137,18 +1137,18 @@ describe("connecting a component to store", () => {
|
||||
test("dispatch an action", async () => {
|
||||
class App extends Component {
|
||||
static template = xml`<div><t t-esc="store.counter"/></div>`;
|
||||
store = useStore(state => state);
|
||||
store = useStore((state) => state);
|
||||
dispatch = useDispatch();
|
||||
}
|
||||
|
||||
const state = {
|
||||
counter: 0
|
||||
counter: 0,
|
||||
};
|
||||
|
||||
const actions = {
|
||||
inc({ state }) {
|
||||
return ++state.counter;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const store = new Store({ state, actions });
|
||||
@@ -1185,21 +1185,21 @@ describe("various scenarios", () => {
|
||||
await Promise.resolve();
|
||||
delete state.attachments[100];
|
||||
state.messages[10].attachmentIds = [];
|
||||
}
|
||||
},
|
||||
};
|
||||
const state = {
|
||||
attachments: {
|
||||
100: {
|
||||
id: 100,
|
||||
name: "text.txt"
|
||||
}
|
||||
name: "text.txt",
|
||||
},
|
||||
},
|
||||
messages: {
|
||||
10: {
|
||||
attachmentIds: [100],
|
||||
id: 10
|
||||
}
|
||||
}
|
||||
id: 10,
|
||||
},
|
||||
},
|
||||
};
|
||||
const store = new Store({ actions, state });
|
||||
|
||||
@@ -1220,7 +1220,7 @@ describe("various scenarios", () => {
|
||||
<Attachment t-foreach="store.attachmentIds" t-key="attachmentId" t-as="attachmentId" id="attachmentId"/>
|
||||
</div>`;
|
||||
|
||||
store = useStore(state => ({ attachmentIds: state.messages[10].attachmentIds }));
|
||||
store = useStore((state) => ({ attachmentIds: state.messages[10].attachmentIds }));
|
||||
static components = { Attachment };
|
||||
state = { isAttachmentDeleted: false };
|
||||
dispatch = useDispatch();
|
||||
|
||||
@@ -20,7 +20,7 @@ debugOwl(owl, {});
|
||||
test("can log full lifecycle", async () => {
|
||||
const steps: string[] = [];
|
||||
const log = console.log;
|
||||
console.log = arg => steps.push(arg);
|
||||
console.log = (arg) => steps.push(arg);
|
||||
|
||||
class Child extends Component {
|
||||
static template = xml`<div>child</div>`;
|
||||
@@ -51,7 +51,7 @@ test("can log full lifecycle", async () => {
|
||||
"[OWL_DEBUG] Child<id=2> rendering template",
|
||||
"[OWL_DEBUG] Parent<id=1> willPatch",
|
||||
"[OWL_DEBUG] Child<id=2> mounted",
|
||||
"[OWL_DEBUG] Parent<id=1> patched"
|
||||
"[OWL_DEBUG] Parent<id=1> patched",
|
||||
]);
|
||||
console.log = log;
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true });
|
||||
test("can log scheduler start and stop", async () => {
|
||||
const steps: string[] = [];
|
||||
const log = console.log;
|
||||
console.log = arg => steps.push(arg);
|
||||
console.log = (arg) => steps.push(arg);
|
||||
|
||||
class Child extends Component {
|
||||
static template = xml`<div>child</div>`;
|
||||
@@ -44,7 +44,7 @@ test("can log scheduler start and stop", async () => {
|
||||
"[OWL_DEBUG] Child<id=2> rendering template",
|
||||
"[OWL_DEBUG] Child<id=2> mounted",
|
||||
"[OWL_DEBUG] Parent<id=1> mounted",
|
||||
"[OWL_DEBUG] scheduler: stop running tasks queue"
|
||||
"[OWL_DEBUG] scheduler: stop running tasks queue",
|
||||
]);
|
||||
console.log = log;
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true });
|
||||
test("log a specific message for render method calls if component is not mounted", async () => {
|
||||
const steps: string[] = [];
|
||||
const log = console.log;
|
||||
console.log = arg => steps.push(arg);
|
||||
console.log = (arg) => steps.push(arg);
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`<div><t t-esc="state.value"/></div>`;
|
||||
@@ -40,7 +40,7 @@ test("log a specific message for render method calls if component is not mounted
|
||||
"[OWL_DEBUG] Parent<id=1> mounted",
|
||||
"[OWL_DEBUG] scheduler: stop running tasks queue",
|
||||
"[OWL_DEBUG] Parent<id=1> willUnmount",
|
||||
"[OWL_DEBUG] Parent<id=1> render (warning: component is not mounted, this render has no effect)"
|
||||
"[OWL_DEBUG] Parent<id=1> render (warning: component is not mounted, this render has no effect)",
|
||||
]);
|
||||
console.log = log;
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ debugOwl(owl, { logScheduler: true });
|
||||
test("log a sub component with non stringifiable props", async () => {
|
||||
const steps: string[] = [];
|
||||
const log = console.log;
|
||||
console.log = arg => steps.push(arg);
|
||||
console.log = (arg) => steps.push(arg);
|
||||
|
||||
class Child extends Component {
|
||||
static template = xml`<span><t t-esc="props.obj.val"/></span>`;
|
||||
@@ -51,7 +51,7 @@ test("log a sub component with non stringifiable props", async () => {
|
||||
"[OWL_DEBUG] Parent<id=1> mounted",
|
||||
"[OWL_DEBUG] scheduler: stop running tasks queue",
|
||||
"[OWL_DEBUG] Parent<id=1> willUnmount",
|
||||
"[OWL_DEBUG] Child<id=2> willUnmount"
|
||||
"[OWL_DEBUG] Child<id=2> willUnmount",
|
||||
]);
|
||||
console.log = log;
|
||||
});
|
||||
|
||||
@@ -60,14 +60,14 @@ function getFiles(path: string[] = []): FileData[] {
|
||||
if (path.length === 0) {
|
||||
const baseFiles: FileData[] = [
|
||||
{ name: "README.md", path: [], links: [], sections: [], fullName: "README.md" },
|
||||
{ name: "roadmap.md", path: [], links: [], sections: [], fullName: "roadmap.md" }
|
||||
{ name: "roadmap.md", path: [], links: [], sections: [], fullName: "roadmap.md" },
|
||||
];
|
||||
const rest = getFiles(["doc"]);
|
||||
const result = baseFiles.concat(rest);
|
||||
result.forEach(addMardownData);
|
||||
return result;
|
||||
}
|
||||
const files = fs.readdirSync(path.join("/"), { withFileTypes: true }).map(f => {
|
||||
const files = fs.readdirSync(path.join("/"), { withFileTypes: true }).map((f) => {
|
||||
if (f.isDirectory()) {
|
||||
return getFiles(path.concat(f.name));
|
||||
}
|
||||
@@ -78,8 +78,8 @@ function getFiles(path: string[] = []): FileData[] {
|
||||
path,
|
||||
links: [],
|
||||
sections: [],
|
||||
fullName
|
||||
}
|
||||
fullName,
|
||||
},
|
||||
];
|
||||
});
|
||||
return Array.prototype.concat(...files);
|
||||
@@ -127,7 +127,7 @@ export function isLinkValid(link: MarkDownLink, current: FileData, files: FileDa
|
||||
}
|
||||
|
||||
// Step 4: check if there is a matching file
|
||||
let target: FileData | undefined = files.find(f => f.fullName === linkFullName);
|
||||
let target: FileData | undefined = files.find((f) => f.fullName === linkFullName);
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ export function isLinkValid(link: MarkDownLink, current: FileData, files: FileDa
|
||||
// Step 5: if necessary, check if there is a corresponding link inside the target
|
||||
// link name
|
||||
if (hash) {
|
||||
if (!target.sections.find(s => s.slug === hash)) {
|
||||
if (!target.sections.find((s) => s.slug === hash)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ function slugify(str) {
|
||||
.toLowerCase()
|
||||
.replace(/\//g, "") // remove /
|
||||
.replace(/\s+/g, "-") // Replace spaces with -
|
||||
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
|
||||
.replace(p, (c) => b.charAt(a.indexOf(c))) // Replace special characters
|
||||
.replace(/&/g, "-and-") // Replace & with ‘and’
|
||||
.replace(/[^\w\-]+/g, "") // Remove all non-word characters
|
||||
.replace(/\-\-+/g, "-") // Replace multiple - with single -
|
||||
|
||||
+192
-192
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user