| 1 |
/** @odoo-module **/ |
| 2 |
import { |
| 3 |
clickOnEditAndWaitEditMode, |
| 4 |
clickOnSave, |
| 5 |
registerWebsitePreviewTour, |
| 6 |
} from '@website/js/tours/tour_utils'; |
| 7 |
import { stepUtils } from "@web_tour/tour_utils"; |
| 8 |
|
| 9 |
/** |
| 10 |
* The purpose of these tours is to check the systray visibility: |
| 11 |
* |
| 12 |
* - as an administrator |
| 13 |
* - as a restricted editor with "tester" right |
| 14 |
* - as a restricted editor without "tester" right |
| 15 |
* - as a "tester" who is not a restricted editor |
| 16 |
* - as an unrelated user (neither "tester" nor restricted editor) |
| 17 |
*/ |
| 18 |
|
| 19 |
const canPublish = () => [{ |
| 20 |
content: "Publish", |
| 21 |
trigger: '.o_menu_systray .o_menu_systray_item:contains("Unpublished")', |
| 22 |
run: "click", |
| 23 |
}, { |
| 24 |
content: "Wait for Publish", |
| 25 |
trigger: '.o_menu_systray .o_menu_systray_item:contains("Published"):not([data-processing])', |
| 26 |
}, { |
| 27 |
content: "Unpublish", |
| 28 |
trigger: '.o_menu_systray .o_menu_systray_item:contains("Published")', |
| 29 |
run: "click", |
| 30 |
}, { |
| 31 |
content: "Wait for Unpublish", |
| 32 |
trigger: '.o_menu_systray .o_menu_systray_item:contains("Unpublished"):not([data-processing])', |
| 33 |
}]; |
| 34 |
|
| 35 |
const cannotPublish = () => [{ |
| 36 |
content: "Check has no Publish/Unpublish", |
| 37 |
trigger: '.o_menu_systray:not(:has(.o_menu_systray_item:contains("ublished")))', |
| 38 |
}]; |
| 39 |
|
| 40 |
const canToggleMobilePreview = () => [{ |
| 41 |
content: "Enable mobile preview", |
| 42 |
trigger: '.o_menu_systray .o_menu_systray_item.o_mobile_preview:not(.o_mobile_preview_active) span', |
| 43 |
run: "click", |
| 44 |
}, { |
| 45 |
content: "Disable mobile preview", |
| 46 |
trigger: '.o_menu_systray .o_menu_systray_item.o_mobile_preview.o_mobile_preview_active span', |
| 47 |
run: "click", |
| 48 |
}]; |
| 49 |
|
| 50 |
const cannotToggleMobilePreview = () => [{ |
| 51 |
content: 'Enable mobile preview', |
| 52 |
trigger: '.o_menu_systray:not(:has(.o_menu_systray_item.o_mobile_preview))', |
| 53 |
}]; |
| 54 |
|
| 55 |
// For non-website users, switching across website only works if the domains are |
| 56 |
// specified. Within the scope of test tours, this cannot be achieved. |
| 57 |
const canSwitchWebsiteNoCheck = () => [{ |
| 58 |
content: 'Open website switcher', |
| 59 |
trigger: '.o_menu_systray .o_menu_systray_item.o_website_switcher_container .dropdown-toggle:contains("My Website"):not(:contains("My Website 2"))', |
| 60 |
run: "click", |
| 61 |
}, { |
| 62 |
content: 'Can switch to other website', |
| 63 |
trigger: '.o-dropdown--menu .dropdown-item:contains("Other")', |
| 64 |
}]; |
| 65 |
|
| 66 |
const canSwitchWebsite = () => [{ |
| 67 |
content: "Open website switcher", |
| 68 |
trigger: '.o_menu_systray .o_menu_systray_item.o_website_switcher_container .dropdown-toggle:contains("My Website"):not(:contains("My Website 2"))', |
| 69 |
run: "click", |
| 70 |
}, { |
| 71 |
content: "Switch to other website", |
| 72 |
trigger: '.o-dropdown--menu .dropdown-item:contains("Other")', |
| 73 |
run: "click", |
| 74 |
}, { |
| 75 |
content: "Wait for other website", |
| 76 |
trigger: ':iframe body:contains("Test Model") div:contains("Other")', |
| 77 |
}]; |
| 78 |
|
| 79 |
const canAddNewContent = () => [{ |
| 80 |
content: "Open +New content", |
| 81 |
trigger: '.o_menu_systray .o_menu_systray_item.o_new_content_container button', |
| 82 |
run: "click", |
| 83 |
}, { |
| 84 |
content: "Close +New content", |
| 85 |
trigger: '.o_new_content_menu_choices', |
| 86 |
run: "click", |
| 87 |
}]; |
| 88 |
|
| 89 |
const cannotAddNewContent = () => [{ |
| 90 |
content: 'No +New content', |
| 91 |
trigger: '.o_menu_systray:not(:has(.o_menu_systray_item.o_new_content_container))', |
| 92 |
}]; |
| 93 |
|
| 94 |
const canEditInBackEnd = () => [{ |
| 95 |
content: "Edit in backend", |
| 96 |
trigger: '.o_menu_systray .o_website_edit_in_backend a', |
| 97 |
run: "click", |
| 98 |
}, { |
| 99 |
content: "Check that the form is editable", |
| 100 |
trigger: '.o_form_view_container .o_form_editable', |
| 101 |
}, { |
| 102 |
content: "Return to website", |
| 103 |
trigger: '.o-form-buttonbox .fa-globe', |
| 104 |
run: "click", |
| 105 |
}]; |
| 106 |
|
| 107 |
const canViewInBackEnd = () => [{ |
| 108 |
content: "Go to backend", |
| 109 |
trigger: '.o_menu_systray .o_website_edit_in_backend a', |
| 110 |
run: "click", |
| 111 |
}, { |
| 112 |
content: "Check that the form is read-only", |
| 113 |
trigger: '.o_form_view_container .o_form_readonly', |
| 114 |
}, { |
| 115 |
content: "Return to website", |
| 116 |
trigger: '.o-form-buttonbox .fa-globe', |
| 117 |
run: "click", |
| 118 |
}]; |
| 119 |
|
| 120 |
const canEdit = () => [ |
| 121 |
...clickOnEditAndWaitEditMode(), |
| 122 |
{ |
| 123 |
content: "Click on name", |
| 124 |
trigger: ':iframe span[data-oe-expression="test_model.name"][contenteditable="true"]', |
| 125 |
run: "click", |
| 126 |
}, { |
| 127 |
content: "Change name", |
| 128 |
trigger: ':iframe span[data-oe-expression="test_model.name"][contenteditable="true"]', |
| 129 |
run: "editor Better name", |
| 130 |
}, { |
| 131 |
content: "Check that field becomes dirty", |
| 132 |
trigger: ':iframe span[data-oe-expression="test_model.name"].o_dirty', |
| 133 |
}, |
| 134 |
...clickOnSave(), |
| 135 |
{ |
| 136 |
content: "Check whether name is saved", |
| 137 |
trigger: ':iframe span[data-oe-expression="test_model.name"]:contains("Better name")', |
| 138 |
}, |
| 139 |
]; |
| 140 |
|
| 141 |
const cannotEdit = () => [stepUtils.waitIframeIsReady(), { |
| 142 |
content: "Check Edit is not available", |
| 143 |
trigger: '.o_menu_systray:not(:has(.o_edit_website_container))', |
| 144 |
}]; |
| 145 |
|
| 146 |
const canEditButCannotChange = () => [ |
| 147 |
...clickOnEditAndWaitEditMode(), |
| 148 |
{ |
| 149 |
content: 'Cannot change name', |
| 150 |
trigger: ':iframe main:not(:has([data-oe-expression])):contains("Test Model")', |
| 151 |
}, |
| 152 |
]; |
| 153 |
|
| 154 |
const ensureWebsiteSwitcherIsNotVisible = [ |
| 155 |
{ |
| 156 |
content: "Ensure website switcher is hidden when only one website exists", |
| 157 |
trigger: ".o_menu_systray:not(:has(.o_website_switcher_container))", |
| 158 |
}, |
| 159 |
]; |
| 160 |
|
| 161 |
const ensureWebsiteSwitcherIsVisible = [ |
| 162 |
{ |
| 163 |
content: "Ensure website switcher is present when multiple website exists", |
| 164 |
trigger: ".o_menu_systray:has(.o_website_switcher_container)", |
| 165 |
}, |
| 166 |
]; |
| 167 |
|
| 168 |
const register = (title, steps) => { |
| 169 |
registerWebsitePreviewTour(title, { |
| 170 |
url: "/test_model/1", |
| 171 |
}, steps); |
| 172 |
}; |
| 173 |
|
| 174 |
register("test_systray_admin", () => [ |
| 175 |
...canPublish(), |
| 176 |
...canToggleMobilePreview(), |
| 177 |
...canSwitchWebsite(), |
| 178 |
...canAddNewContent(), |
| 179 |
...canEditInBackEnd(), |
| 180 |
...canEdit(), |
| 181 |
]); |
| 182 |
|
| 183 |
register("test_systray_reditor_tester", () => [ |
| 184 |
...canPublish(), |
| 185 |
...canToggleMobilePreview(), |
| 186 |
...canSwitchWebsite(), |
| 187 |
...canAddNewContent(), |
| 188 |
...canEditInBackEnd(), |
| 189 |
...canEdit(), |
| 190 |
]); |
| 191 |
|
| 192 |
register("test_systray_reditor_not_tester", () => [ |
| 193 |
...cannotPublish(), |
| 194 |
...canToggleMobilePreview(), |
| 195 |
...canSwitchWebsite(), |
| 196 |
...canAddNewContent(), |
| 197 |
...canViewInBackEnd(), |
| 198 |
...canEditButCannotChange(), |
| 199 |
]); |
| 200 |
|
| 201 |
register("test_systray_not_reditor_tester", () => [ |
| 202 |
...canPublish(), |
| 203 |
...cannotToggleMobilePreview(), |
| 204 |
...canSwitchWebsiteNoCheck(), |
| 205 |
...cannotAddNewContent(), |
| 206 |
...canEditInBackEnd(), |
| 207 |
...cannotEdit(), |
| 208 |
]); |
| 209 |
|
| 210 |
register("test_systray_not_reditor_not_tester", () => [ |
| 211 |
...cannotPublish(), |
| 212 |
...cannotToggleMobilePreview(), |
| 213 |
...canSwitchWebsiteNoCheck(), |
| 214 |
...cannotAddNewContent(), |
| 215 |
...canViewInBackEnd(), |
| 216 |
...cannotEdit(), |
| 217 |
{ |
| 218 |
trigger: ":iframe main:contains(test model)", |
| 219 |
}, |
| 220 |
]); |
| 221 |
|
| 222 |
register("test_systray_single_website", () => ensureWebsiteSwitcherIsNotVisible); |
| 223 |
|
| 224 |
register("test_systray_multi_website", () => ensureWebsiteSwitcherIsVisible); |