Skip to content

Commit 5e7513e

Browse files
committed
[FIX] website: apply shape on 404 image
1 parent 35a2359 commit 5e7513e

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

addons/html_builder/static/src/plugins/image/image_shape_option_plugin.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { DEFAULT_PALETTE } from "@html_editor/utils/color";
44
import { isCSSColor } from "@web/core/utils/colors";
55
import { getCSSVariableValue } from "@html_builder/utils/utils_css";
66
import { getShapeURL } from "./image_helpers";
7-
import { activateCropper, createDataURL, loadImage } from "@html_editor/utils/image_processing";
7+
import {
8+
activateCropper,
9+
createDataURL,
10+
loadImage,
11+
loadImageInfo,
12+
} from "@html_editor/utils/image_processing";
813
import { getValueFromVar } from "@html_builder/utils/utils";
914
import { imageShapeDefinitions } from "./image_shapes_definition";
1015
import {
@@ -143,6 +148,8 @@ class ImageShapeOptionPlugin extends Plugin {
143148
return shapeSvgText;
144149
}
145150
async loadShape(img, newData = {}) {
151+
Object.assign(newData, await loadImageInfo(img));
152+
await loadImage(newData.originalSrc, img);
146153
return this.dependencies.imagePostProcess.processImage(img, newData);
147154
//todo: handle hover effect before
148155
// todo: is it still needed?

addons/website/static/tests/tours/drop_404_ir_attachment_url.js

+35-15
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {
2-
changeOption,
32
insertSnippet,
43
registerWebsitePreviewTour,
5-
changeOptionInPopover,
64
} from '@website/js/tours/tour_utils';
75

86
registerWebsitePreviewTour('drop_404_ir_attachment_url', {
@@ -26,12 +24,21 @@ registerWebsitePreviewTour('drop_404_ir_attachment_url', {
2624
content: 'Once the image UI appears, check the image has no size (404)',
2725
trigger: ":iframe [data-snippet='s_404_snippet'] img",
2826
run() {
29-
const imgEl = this.anchor;
30-
if (!imgEl.complete
31-
|| imgEl.naturalWidth !== 0
32-
|| imgEl.naturalHeight !== 0) {
33-
throw new Error('This is supposed to be a 404 image');
34-
}
27+
return new Promise((resolve, reject) => {
28+
const imgEl = this.anchor;
29+
const checkComplete = () => {
30+
if (imgEl.complete) {
31+
if (imgEl.naturalWidth !== 0 || imgEl.naturalHeight !== 0) {
32+
reject(new Error("This is supposed to be a 404 image"));
33+
} else {
34+
resolve();
35+
}
36+
} else {
37+
requestAnimationFrame(checkComplete);
38+
}
39+
};
40+
checkComplete();
41+
});
3542
},
3643
},
3744
{
@@ -50,14 +57,27 @@ registerWebsitePreviewTour('drop_404_ir_attachment_url', {
5057
},
5158
{
5259
content: 'Once the shape is applied, check the image has now a size (placeholder image)',
53-
trigger: ':iframe [data-snippet="s_404_snippet"] img',
60+
trigger: ":iframe [data-snippet='s_404_snippet'] img[src^='data:']",
5461
run() {
55-
const imgEl = this.anchor;
56-
if (!imgEl.complete
57-
|| imgEl.naturalWidth === 0
58-
|| imgEl.naturalHeight === 0) {
59-
throw new Error('Even though the original image was a 404, the option should have been applied on the placeholder image');
60-
}
62+
return new Promise((resolve, reject) => {
63+
const imgEl = this.anchor;
64+
const checkComplete = () => {
65+
if (imgEl.complete) {
66+
if (imgEl.naturalWidth === 0 || imgEl.naturalHeight === 0) {
67+
reject(
68+
new Error(
69+
"Even though the original image was a 404, the option should have been applied on the placeholder image"
70+
)
71+
);
72+
} else {
73+
resolve();
74+
}
75+
} else {
76+
requestAnimationFrame(checkComplete);
77+
}
78+
};
79+
checkComplete();
80+
});
6181
},
6282
},
6383
]);

addons/website/tests/test_ui.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def test_drop_404_ir_attachment_url(self):
713713
'model': 'ir.attachment',
714714
'res_id': attachment.id,
715715
})
716-
self.start_tour(self.env['website'].get_client_action_url('/'), 'drop_404_ir_attachment_url', login='admin', watch=True)
716+
self.start_tour(self.env['website'].get_client_action_url('/'), 'drop_404_ir_attachment_url', login='admin')
717717

718718
@unittest.skip
719719
def test_mobile_order_with_drag_and_drop(self):

0 commit comments

Comments
 (0)