Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] web: effect: display rainbowman by default
In [1], we rewrote the effect feature in the wowl infrastructure. However, we lost something in the process: the "type" of effect (basically "rainbow_man" as it is the only implemented effect) became a mandatory param, whereas before it simply defaulted to "rainbow_man" when not set. As a consequence, previously defined effects in views could crash. This commit fixes that issue, and reworks a bit the feature by introducing a registry of effects, which easily allows to add new effects from the outside. An effect is a function that may return a Component (and its props) to display. Most of the diff in the tests is about moving files where they should be (the effect feature being in core/, the tests must be in core/ as well, and not depend on the webclient). [1] 0573aca Task 2652927 closes odoo#77109 X-original-commit: 74dc3f6 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
- Loading branch information
Showing
9 changed files
with
215 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
/** @odoo-module **/ | ||
|
||
import { RainbowMan } from "./rainbow_man"; | ||
|
||
const { Component, tags } = owl; | ||
|
||
export class EffectContainer extends Component { | ||
setup() { | ||
this.rainbowProps = {}; | ||
this.effect = null; | ||
this.props.bus.on("UPDATE", this, (effect) => { | ||
this.rainbowProps = effect; | ||
this.effect = effect; | ||
this.render(); | ||
}); | ||
} | ||
closeRainbowMan() { | ||
this.rainbowProps = {}; | ||
removeEffect() { | ||
this.effect = null; | ||
this.render(); | ||
} | ||
} | ||
|
||
EffectContainer.template = tags.xml` | ||
<div class="o_effects_manager"> | ||
<RainbowMan t-if="rainbowProps.id" t-props="rainbowProps" t-key="rainbowProps.id" t-on-close-rainbowman="closeRainbowMan"/> | ||
<t t-if="effect"> | ||
<t t-component="effect.Component" t-props="effect.props" t-key="effect.id" close="() => removeEffect()"/> | ||
</t> | ||
</div>`; | ||
EffectContainer.components = { RainbowMan }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
addons/web/static/tests/core/effects/effect_service_tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/** @odoo-module **/ | ||
|
||
import { notificationService } from "@web/core/notifications/notification_service"; | ||
import { registry } from "@web/core/registry"; | ||
import { effectService } from "@web/core/effects/effect_service"; | ||
import { RainbowMan } from "@web/core/effects/rainbow_man"; | ||
import { userService } from "@web/core/user_service"; | ||
import { session } from "@web/session"; | ||
import { makeTestEnv } from "../../helpers/mock_env"; | ||
import { makeFakeLocalizationService } from "../../helpers/mock_services"; | ||
import { click, getFixture, nextTick, patchWithCleanup } from "../../helpers/utils"; | ||
import { registerCleanup } from "../../helpers/cleanup"; | ||
|
||
const { Component, mount, tags } = owl; | ||
const serviceRegistry = registry.category("services"); | ||
const mainComponentRegistry = registry.category("main_components"); | ||
|
||
class Parent extends Component { | ||
setup() { | ||
this.EffectContainer = mainComponentRegistry.get("EffectContainer"); | ||
this.NotificationContainer = mainComponentRegistry.get("NotificationContainer"); | ||
} | ||
} | ||
Parent.template = tags.xml` | ||
<div> | ||
<t t-component="EffectContainer.Component" t-props="EffectContainer.props" /> | ||
<t t-component="NotificationContainer.Component" t-props="NotificationContainer.props" /> | ||
</div> | ||
`; | ||
|
||
async function makeParent() { | ||
const env = await makeTestEnv({ serviceRegistry }); | ||
const target = getFixture(); | ||
const parent = await mount(Parent, { env, target }); | ||
registerCleanup(() => parent.destroy()); | ||
return parent; | ||
} | ||
|
||
QUnit.module("Effect Service", (hooks) => { | ||
let effectParams; | ||
hooks.beforeEach(() => { | ||
effectParams = { | ||
message: "<div>Congrats!</div>", | ||
messageIsHtml: true, | ||
fadeout: "nextTick", | ||
}; | ||
|
||
patchWithCleanup(session, { show_effect: true }); // enable effects | ||
|
||
serviceRegistry.add("user", userService); | ||
serviceRegistry.add("effect", effectService); | ||
serviceRegistry.add("notification", notificationService); | ||
serviceRegistry.add("localization", makeFakeLocalizationService()); | ||
}); | ||
|
||
QUnit.test("effect service displays a rainbowman by default", async function (assert) { | ||
const parent = await makeParent(); | ||
|
||
parent.env.services.effect.add({ message: "Hello", fadeout: "no" }); | ||
await nextTick(); | ||
|
||
assert.containsOnce(parent.el, ".o_reward"); | ||
assert.strictEqual(parent.el.querySelector(".o_reward").innerText, "Hello"); | ||
}); | ||
|
||
QUnit.test("rainbowman effect with show_effect: false", async function (assert) { | ||
patchWithCleanup(session, { show_effect: false }); | ||
|
||
const parent = await makeParent(); | ||
|
||
parent.env.services.effect.add({ type: "rainbow_man", message: "", fadeout: "no" }); | ||
await nextTick(); | ||
|
||
assert.containsNone(parent.el, ".o_reward"); | ||
assert.containsOnce(parent.el, ".o_notification"); | ||
}); | ||
|
||
QUnit.test("rendering a rainbowman destroy after animation", async function (assert) { | ||
patchWithCleanup(RainbowMan, { | ||
rainbowFadeouts: { nextTick: 0 }, | ||
}); | ||
|
||
const parent = await makeParent(); | ||
parent.env.services.effect.add(effectParams); | ||
await nextTick(); | ||
|
||
assert.containsOnce(parent, ".o_reward"); | ||
assert.containsOnce(parent, ".o_reward_rainbow"); | ||
assert.strictEqual( | ||
parent.el.querySelector(".o_reward_msg_content").innerHTML, | ||
"<div>Congrats!</div>" | ||
); | ||
|
||
const ev = new AnimationEvent("animationend", { animationName: "reward-fading-reverse" }); | ||
parent.el.querySelector(".o_reward").dispatchEvent(ev); | ||
await nextTick(); | ||
assert.containsNone(parent, ".o_reward"); | ||
}); | ||
|
||
QUnit.test("rendering a rainbowman destroy on click", async function (assert) { | ||
const parent = await makeParent(); | ||
|
||
parent.env.services.effect.add({ ...effectParams, fadeout: "no" }); | ||
await nextTick(); | ||
|
||
assert.containsOnce(parent.el, ".o_reward"); | ||
assert.containsOnce(parent.el, ".o_reward_rainbow"); | ||
|
||
await click(parent.el); | ||
assert.containsNone(parent, ".o_reward"); | ||
}); | ||
|
||
QUnit.test("rendering a rainbowman with an escaped message", async function (assert) { | ||
const parent = await makeParent(); | ||
|
||
parent.env.services.effect.add({ ...effectParams, messageIsHtml: false }); | ||
await nextTick(); | ||
|
||
assert.containsOnce(parent.el, ".o_reward"); | ||
assert.containsOnce(parent.el, ".o_reward_rainbow"); | ||
assert.strictEqual( | ||
parent.el.querySelector(".o_reward_msg_content").textContent, | ||
"<div>Congrats!</div>" | ||
); | ||
}); | ||
}); |
Oops, something went wrong.