import { beforeEach, expect, test } from "@odoo/hoot"; import { queryAll } from "@odoo/hoot-dom"; import { setupInteractionWhiteList, startInteractions } from "@web/../tests/public/helpers"; import { onRpc } from "@web/../tests/web_test_helpers"; import { registry } from "@web/core/registry"; import { Interaction } from "@web/public/interaction"; setupInteractionWhiteList([ "website_appointment.appointments", "website_appointment.test_appointment_item", ]); beforeEach(() => { class TestItem extends Interaction { static selector = ".s_test_item"; dynamicContent = { _root: { "t-att-data-started": (el) => `*${el.dataset.testParam}*`, }, }; } registry .category("public.interactions") .add("website_appointment.test_appointment_item", TestItem); }); test("dynamic snippet appointments loads items and displays them through template", async () => { onRpc("/website/snippet/filters", async (args) => { for await (const chunk of args.body) { const json = JSON.parse(new TextDecoder().decode(chunk)); expect(json.params.filter_id).toBe(1); expect(json.params.template_key).toBe( "website_appointment.dynamic_filter_template_appointment_type_card" ); expect(json.params.limit).toBe(4); expect(json.params.search_domain).toEqual([ "&", "&", ["schedule_based_on", "=", "resources"], ["resource_ids", "in", [1, 2]], ["name", "ilike", "tennis"], ]); } return [ `
Some test record
`, `
Another test record
`, ]; }); const { core } = await startInteractions(`
Your Dynamic Snippet will be displayed here... This message is displayed because you did not provide both a filter and a template to use.
`); expect(core.interactions.length).toBe(3); const itemEls = queryAll(".s_test_item"); expect(itemEls[0].dataset.testParam).toBe("test"); expect(itemEls[1].dataset.testParam).toBe("test2"); // Make sure element interactions are started. expect(itemEls[0].dataset.started).toBe("*test*"); expect(itemEls[1].dataset.started).toBe("*test2*"); core.stopInteractions(); // Make sure element interactions are stopped. expect(core.interactions.length).toBe(0); });