|
| 1 | +import { describe, expect, test } from "@odoo/hoot"; |
| 2 | +import { waitFor, waitForNone, click } from "@odoo/hoot-dom"; |
| 3 | +import { defineWebsiteModels } from "./website_helpers"; |
| 4 | +import { setupEditor } from "@html_editor/../tests/_helpers/editor"; |
| 5 | +import { setContent } from "@html_editor/../tests/_helpers/selection"; |
| 6 | +import { patchWithCleanup, mockService } from "@web/../tests/web_test_helpers"; |
| 7 | +import { MAIN_PLUGINS } from "@html_editor/plugin_sets"; |
| 8 | +import { MenuDataPlugin } from "@html_builder/website_builder/plugins/menu_data_plugin"; |
| 9 | +import { MenuDialog } from "@website/components/dialog/edit_menu"; |
| 10 | + |
| 11 | +defineWebsiteModels(); |
| 12 | + |
| 13 | +describe("Top Menu should open a NavbarLinkPopover", () => { |
| 14 | + test("should open a navbar popover when the selection is inside a top menu link and close outside of a top menu link", async () => { |
| 15 | + const { el } = await setupEditor( |
| 16 | + `<ul class="top_menu"> |
| 17 | + <li> |
| 18 | + <a class="nav-link" href="exists"> |
| 19 | + <span>Top Menu Item</span> |
| 20 | + </a> |
| 21 | + </li> |
| 22 | + </ul> |
| 23 | + <p>Outside</p>`, |
| 24 | + { |
| 25 | + config: { Plugins: [...MAIN_PLUGINS, MenuDataPlugin] }, |
| 26 | + } |
| 27 | + ); |
| 28 | + expect(".o-we-linkpopover").toHaveCount(0); |
| 29 | + // selection inside a top menu link |
| 30 | + setContent( |
| 31 | + el, |
| 32 | + `<ul class="top_menu"> |
| 33 | + <li> |
| 34 | + <a class="nav-link" href="exists"> |
| 35 | + <span>Top Me[]nu Item</span> |
| 36 | + </a> |
| 37 | + </li> |
| 38 | + </ul> |
| 39 | + <p>Outside</p>` |
| 40 | + ); |
| 41 | + await waitFor(".o-we-linkpopover"); |
| 42 | + // remove link button replaced with sitemap button |
| 43 | + expect(".o-we-linkpopover:has(i.fa-chain-broken)").toHaveCount(0); |
| 44 | + expect(".o-we-linkpopover:has(i.fa-sitemap)").toHaveCount(1); |
| 45 | + // selection outside a top menu link |
| 46 | + setContent( |
| 47 | + el, |
| 48 | + `<ul class="top_menu"> |
| 49 | + <li> |
| 50 | + <a class="nav-link" href="exists"> |
| 51 | + <span>Top Menu Item</span> |
| 52 | + </a> |
| 53 | + </li> |
| 54 | + </ul> |
| 55 | + <p>Out[]side</p>` |
| 56 | + ); |
| 57 | + await waitForNone(".o-we-linkpopover", { timeout: 1500 }); |
| 58 | + expect(".o-we-linkpopover").toHaveCount(0); |
| 59 | + }); |
| 60 | + |
| 61 | + test("should open a navbar popover when the selection is inside a top menu link and stay open if selection move in the same link", async () => { |
| 62 | + const { el } = await setupEditor( |
| 63 | + `<ul class="top_menu"> |
| 64 | + <li> |
| 65 | + <a class="nav-link" href="exists"> |
| 66 | + <span>Top Me[]nu Item</span> |
| 67 | + </a> |
| 68 | + </li> |
| 69 | + </ul>`, |
| 70 | + { |
| 71 | + config: { Plugins: [...MAIN_PLUGINS, MenuDataPlugin] }, |
| 72 | + } |
| 73 | + ); |
| 74 | + await waitFor(".o-we-linkpopover"); |
| 75 | + expect(".o-we-linkpopover:has(i.fa-sitemap)").toHaveCount(1); |
| 76 | + //selection in the same link |
| 77 | + setContent( |
| 78 | + el, |
| 79 | + `<ul class="top_menu"> |
| 80 | + <li> |
| 81 | + <a class="nav-link" href="exists"> |
| 82 | + <span>Top Menu It[]em</span> |
| 83 | + </a> |
| 84 | + </li> |
| 85 | + </ul>` |
| 86 | + ); |
| 87 | + await waitFor(".o-we-linkpopover", { timeout: 1500 }); |
| 88 | + expect(".o-we-linkpopover:has(i.fa-sitemap)").toHaveCount(1); |
| 89 | + }); |
| 90 | + |
| 91 | + test("should open a navbar popover when the selection is inside a top menu dropdown link", async () => { |
| 92 | + await setupEditor( |
| 93 | + `<ul class="top_menu"> |
| 94 | + <li> |
| 95 | + <a class="nav-link" href="exists"> |
| 96 | + <span>Top Menu Item</span> |
| 97 | + </a> |
| 98 | + </li> |
| 99 | + <div class="dropdown"> |
| 100 | + <a class="dropdown-toggle" data-bs-toggle="dropdown"></a> |
| 101 | + <div class="dropdown-menu"> |
| 102 | + <li> |
| 103 | + <a class="dropdown-item" href="exists"> |
| 104 | + <span>Dropdown Me[]nu Item</span> |
| 105 | + </a> |
| 106 | + </li> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </ul>`, |
| 110 | + { |
| 111 | + config: { Plugins: [...MAIN_PLUGINS, MenuDataPlugin] }, |
| 112 | + } |
| 113 | + ); |
| 114 | + await waitFor(".o-we-linkpopover"); |
| 115 | + expect(".o-we-linkpopover:has(i.fa-sitemap)").toHaveCount(1); |
| 116 | + }); |
| 117 | +}); |
| 118 | + |
| 119 | +describe("should open dialogs when editing link or menu", () => { |
| 120 | + test("after clicking on edit link button, a MenuDialog should appear", async () => { |
| 121 | + const { el } = await setupEditor( |
| 122 | + `<ul class="top_menu"> |
| 123 | + <li> |
| 124 | + <a class="nav-link" href="exists"> |
| 125 | + <span data-oe-id="5">Top Me[]nu Item</span> |
| 126 | + </a> |
| 127 | + </li> |
| 128 | + </ul>`, |
| 129 | + { |
| 130 | + config: { Plugins: [...MAIN_PLUGINS, MenuDataPlugin] }, |
| 131 | + } |
| 132 | + ); |
| 133 | + patchWithCleanup(MenuDialog.prototype, { |
| 134 | + setup() { |
| 135 | + super.setup(); |
| 136 | + this.website.pageDocument = el.ownerDocument; |
| 137 | + }, |
| 138 | + }); |
| 139 | + await waitFor(".o-we-linkpopover"); |
| 140 | + await click(".o_we_edit_link"); |
| 141 | + await waitFor(".o_website_dialog"); |
| 142 | + expect("input.form-control:not(#url_input)").toHaveValue("Top Menu Item"); |
| 143 | + expect("#url_input").toHaveValue("exists"); |
| 144 | + }); |
| 145 | + |
| 146 | + test("after clicking on edit menu button, a EditMenuDialog should appear", async () => { |
| 147 | + await setupEditor( |
| 148 | + `<ul class="top_menu"> |
| 149 | + <li> |
| 150 | + <a class="nav-link" href="exists"> |
| 151 | + <span>Top Me[]nu Item</span> |
| 152 | + </a> |
| 153 | + </li> |
| 154 | + </ul>`, |
| 155 | + { |
| 156 | + config: { Plugins: [...MAIN_PLUGINS, MenuDataPlugin] }, |
| 157 | + } |
| 158 | + ); |
| 159 | + mockService("website", { |
| 160 | + get currentWebsite() { |
| 161 | + return { |
| 162 | + id: 1, |
| 163 | + metadata: { |
| 164 | + lang: "en_EN", |
| 165 | + }, |
| 166 | + }; |
| 167 | + }, |
| 168 | + }); |
| 169 | + const fakeORMService = { |
| 170 | + call: (model, method, args, kwargs) => { |
| 171 | + expect(model).toBe("website.menu"); |
| 172 | + expect(method).toBe("get_tree"); |
| 173 | + expect(args[0]).toBe(1); |
| 174 | + return { |
| 175 | + fields: { |
| 176 | + id: 4, |
| 177 | + name: "Top Menu", |
| 178 | + url: "#", |
| 179 | + new_window: false, |
| 180 | + is_mega_menu: false, |
| 181 | + sequence: 0, |
| 182 | + parent_id: false, |
| 183 | + }, |
| 184 | + children: [ |
| 185 | + { |
| 186 | + fields: { |
| 187 | + id: 5, |
| 188 | + name: "Top Menu Item", |
| 189 | + url: "exists", |
| 190 | + new_window: false, |
| 191 | + is_mega_menu: false, |
| 192 | + sequence: 10, |
| 193 | + parent_id: 4, |
| 194 | + }, |
| 195 | + children: [], |
| 196 | + is_homepage: true, |
| 197 | + }, |
| 198 | + ], |
| 199 | + is_homepage: false, |
| 200 | + }; |
| 201 | + }, |
| 202 | + }; |
| 203 | + mockService("orm", fakeORMService); |
| 204 | + await waitFor(".o-we-linkpopover"); |
| 205 | + await click(".js_edit_menu"); |
| 206 | + await waitFor(".o_website_dialog"); |
| 207 | + expect(".oe_menu_editor").toHaveCount(1); |
| 208 | + }); |
| 209 | +}); |
0 commit comments