File: snippet_social_media.js

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (219 lines) | stat: -rw-r--r-- 8,955 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/** @odoo-module */

import {
    clickOnEditAndWaitEditMode,
    clickOnSave,
    clickOnSnippet,
    insertSnippet,
    registerWebsitePreviewTour,
} from '@website/js/tours/tour_utils';

// TODO: Remove following steps once fix of task-3212519 is done.
// Those steps are preventing a race condition to happen in the meantime: when
// the tour was clicking on the toggle to hide facebook in the next step, it
// would actually "ignore" the result of the click on the toggle and would just
// consider the action of focusing out the input.
const socialRaceConditionClass = 'social_media_race_condition';
const preventRaceConditionStep = [
    {
        trigger: `body:not(.${socialRaceConditionClass})`,
    },
    {
    content: "Wait a few ms to avoid race condition",
    // Ensure the class is remove from previous call of those steps
    trigger: ':iframe .s_social_media',
    run() {
        setTimeout(() => {
            document.body.classList.add(socialRaceConditionClass);
        }, 500);
    }
}, {
    content: "Check the race condition class is added after a few ms",
    trigger: `body.${socialRaceConditionClass}`,
    run() {
        document.body.classList.remove(socialRaceConditionClass);
    }
}];

const replaceIconByImage = function (url) {
    return [{
        content: "Replace the icon by an image",
        trigger: `:iframe .s_social_media a[href='${url}'] i.fa`,
        run: "dblclick",
    },
    {
        content: "Go to the Images tab in the media dialog",
        trigger: ".o_select_media_dialog .o_notebook_headers .nav-item a:contains('Images')",
        run: "click",
    },
    {
        content: "Select the image",
        trigger: ".o_select_media_dialog img[title='s_banner_default_image.jpg']",
        run: "click",
    },
    ...preventRaceConditionStep,
    ];
};

const addNewSocialNetwork = function (optionIndex, linkIndex, url, replaceIcon = false) {
    const replaceIconByImageSteps = replaceIcon ? replaceIconByImage("https://www.example.com") : [];
    return [{
        content: "Click on Add New Social Network",
        trigger: 'we-list we-button.o_we_list_add_optional',
        run: "click",
    },
    {
        content: "Ensure new option is found",
        trigger: `we-list table input:eq(${optionIndex})[data-list-position="${optionIndex}"][data-dom-position="${linkIndex}"][data-undeletable=false]`,
    },
    {
        content: "Ensure new link is found",
        trigger: `:iframe .s_social_media:has(a:eq(${linkIndex})[href='https://www.example.com'])`,
    },
    ...replaceIconByImageSteps,
    {
        content: "Change added Option label",
        trigger: `we-list table input:eq(${optionIndex})`,
        run: `edit ${url} && click body`,
    },
    {
        content: "Ensure new link is changed",
        trigger: `:iframe .s_social_media:has(a:eq(${linkIndex})[href='${url}'])`,
    },
    ...preventRaceConditionStep,
    ];
};

registerWebsitePreviewTour('snippet_social_media', {
    url: '/',
    edition: true,
}, () => [
    ...insertSnippet({id: 's_social_media', name: 'Social Media'}),
    ...clickOnSnippet({id: 's_social_media', name: 'Social Media'}),
    ...addNewSocialNetwork(7, 7, 'https://www.youtu.be/y7TlnAv6cto'),
    {
        content: 'Click on the toggle to hide Facebook',
        trigger: 'we-list table we-button.o_we_user_value_widget',
        run: 'click',
    },
    {
        content: "Ensure twitter became first",
        trigger: ':iframe .s_social_media:has(a:eq(0)[href="/website/social/twitter"])',
    },
    {
        content: 'Drag the facebook link at the end of the list',
        trigger: 'we-list table we-button.o_we_drag_handle',
        tooltipPosition: 'bottom',
        run: "drag_and_drop we-list table tr:last-child",
    },
    {
        content: 'Check drop completed',
        trigger: 'we-list table input:eq(7)[data-media="facebook"]',
    },
    ...preventRaceConditionStep,
    // Create a Link for which we don't have an icon to propose.
    ...addNewSocialNetwork(8, 7, 'https://whatever.it/1EdSw9X'),
    // Create a custom instagram link.
    ...addNewSocialNetwork(9, 8, 'https://instagr.am/odoo.official/'),
    {
        content: "Check if the result is correct before removing",
        trigger: ":iframe .s_social_media" +
                 ":has(a:eq(0)[href='/website/social/twitter'])" +
                 ":has(a:eq(1)[href='/website/social/linkedin'])" +
                 ":has(a:eq(2)[href='/website/social/youtube'])" +
                 ":has(a:eq(3)[href='/website/social/instagram'])" +
                 ":has(a:eq(4)[href='/website/social/github'])" +
                 ":has(a:eq(5)[href='/website/social/tiktok'])" +
                 ":has(a:eq(6)[href='https://www.youtu.be/y7TlnAv6cto']:has(i.fa-youtube))" +
                 ":has(a:eq(7)[href='https://whatever.it/1EdSw9X']:has(i.fa-pencil))" +
                 ":has(a:eq(8)[href='https://instagr.am/odoo.official/']:has(i.fa-instagram))",
    },
    // Create a custom link, not officially supported, ensure icon is found.
    {
        content: 'Change custom social to unsupported link',
        trigger: 'we-list table input:eq(6)',
        run: "edit https://www.paypal.com/abc && click body",
    },
    {
        content: "Ensure paypal icon is found",
        trigger: ":iframe .s_social_media" +
                 ":has(a:eq(6)[href='https://www.paypal.com/abc']:has(i.fa-paypal))",
    },
    ...preventRaceConditionStep,
    {
        content: 'Delete the custom link',
        trigger: 'we-list we-button.o_we_select_remove_option',
        run: 'click',
    },
    {
        content: "Ensure custom link was removed",
        trigger: ':iframe .s_social_media:has(a:eq(6)[href="https://whatever.it/1EdSw9X"]:has(i.fa-pencil))',
    },
    {
        content: 'Click on the toggle to show Facebook',
        trigger: 'we-list table we-button.o_we_user_value_widget:not(.active)',
        run: 'click',
    },
    {
        content: "Check if the result is correct after removing",
        trigger: ":iframe .s_social_media" +
                 ":has(a:eq(0)[href='/website/social/twitter'])" +
                 ":has(a:eq(1)[href='/website/social/linkedin'])" +
                 ":has(a:eq(2)[href='/website/social/youtube'])" +
                 ":has(a:eq(3)[href='/website/social/instagram'])" +
                 ":has(a:eq(4)[href='/website/social/github'])" +
                 ":has(a:eq(5)[href='/website/social/tiktok'])" +
                 ":has(a:eq(6)[href='/website/social/facebook'])" +
                 ":has(a:eq(7)[href='https://whatever.it/1EdSw9X']:has(i.fa-pencil))" +
                 ":has(a:eq(8)[href='https://instagr.am/odoo.official/']:has(i.fa-instagram))",
    },
    {
        content: 'Change url of the DB instagram link',
        trigger: 'we-list table input:eq(3)',
        run: "edit https://instagram.com/odoo.official/ && click body",
    },
    ...preventRaceConditionStep,
    ...clickOnSave(),
    ...clickOnEditAndWaitEditMode(),
    ...clickOnSnippet({
        id: 's_social_media',
        name: 'Social Media',
    }),
    {
        content: "Check if we can still change custom icons",
        trigger: ':iframe .s_social_media a[href="https://whatever.it/1EdSw9X"] i.fa-pencil',
        run: 'dblclick',
    },
    {
        content: "Select a new icon",
        trigger: '.o_select_media_dialog .fa-heart',
        run: "click",
    },
    {
        content: "Check if the result is correct after setting the icon",
        trigger: ":iframe .s_social_media" +
                 ":has(a:eq(0)[href='/website/social/twitter'])" +
                 ":has(a:eq(1)[href='/website/social/linkedin'])" +
                 ":has(a:eq(2)[href='/website/social/youtube'])" +
                 ":has(a:eq(3)[href='/website/social/instagram'])" +
                 ":has(a:eq(4)[href='/website/social/github'])" +
                 ":has(a:eq(5)[href='/website/social/tiktok'])" +
                 ":has(a:eq(6)[href='/website/social/facebook'])" +
                 ":has(a:eq(7)[href='https://whatever.it/1EdSw9X']:has(i.fa-heart))" +
                 ":has(a:eq(8)[href='https://instagr.am/odoo.official/']:has(i.fa-instagram))",
    },
    // Create a social network but replace its icon by an image before setting
    // the link (`replaceIcon` parameter set to `true`).
    ...addNewSocialNetwork(9, 9, "https://google.com", true),
    // Create a social network after replacing the first icon by an image.
    ...replaceIconByImage("/website/social/twitter"),
    ...addNewSocialNetwork(10, 10, "https://facebook.com"),
    {
        content: "Check if the result is correct after adding images",
        trigger: ":iframe .s_social_media" +
                 ":has(a:eq(0)[href='/website/social/twitter']:has(img))" +
                 ":has(a:eq(9)[href='https://google.com']:has(img))" +
                 ":has(a:eq(10)[href='https://facebook.com']:has(img))",
    },
    ...clickOnSave(),
]);