Skip to content

Commit 7fcd186

Browse files
committed
AC-15033:[JS deprecations] Investigate the Unit test Failures
1 parent 975e9e3 commit 7fcd186

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

dev/tests/js/jasmine/tests/lib/mage/tinymceAdapter.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define([
1010
], function (wysiwygAdapter, _, tinyMCE) {
1111
'use strict';
1212

13-
var obj;
13+
var obj, originalVarienEvents;
1414

1515
beforeEach(function () {
1616

@@ -23,6 +23,32 @@ define([
2323
Constr.prototype = wysiwygAdapter;
2424

2525
obj = new Constr();
26+
27+
// Store original varienEvents if it exists
28+
originalVarienEvents = window.varienEvents;
29+
30+
// Ensure varienEvents is available for CI environments
31+
if (typeof window.varienEvents === 'undefined') {
32+
window.varienEvents = function() {
33+
this.arrEvents = {};
34+
this.attachEvent = function(eventName, callback) {
35+
if (!this.arrEvents[eventName]) {
36+
this.arrEvents[eventName] = [];
37+
}
38+
this.arrEvents[eventName].push(callback);
39+
};
40+
this.fireEvent = function(eventName, data) {
41+
if (this.arrEvents[eventName]) {
42+
this.arrEvents[eventName].forEach(function(callback) {
43+
if (typeof callback === 'function') {
44+
callback(data);
45+
}
46+
});
47+
}
48+
};
49+
};
50+
}
51+
2652
obj.eventBus = new window.varienEvents();
2753
obj.initialize('id', {
2854
'store_id': 0,
@@ -34,6 +60,15 @@ define([
3460
obj.setup();
3561
});
3662

63+
afterEach(function () {
64+
// Restore original varienEvents or remove mock
65+
if (originalVarienEvents) {
66+
window.varienEvents = originalVarienEvents;
67+
} else if (window.varienEvents) {
68+
delete window.varienEvents;
69+
}
70+
});
71+
3772
describe('"openFileBrowser" method', function () {
3873
it('Opens file browser to given instance', function () {
3974
expect(_.size(obj.eventBus.arrEvents['open_browser_callback'])).toBe(1);

dev/tests/js/jasmine/tests/lib/mage/wysiwygAdapter.test.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ define([
3333
* @param {String} encodedHtml
3434
*/
3535
function runTests(decodedHtml, encodedHtml) {
36-
// Create test case with trailing slash - fix the regex to be more robust
37-
var encodedHtmlWithForwardSlashInImgSrc = encodedHtml.replace(/src="([^"]+)"/g, 'src="$1/"');
36+
var encodedHtmlWithForwardSlashInImgSrc = encodedHtml.replace(/src="([^"]+)/, 'src="$1/');
3837

3938
describe('"encodeDirectives" method', function () {
4039
it('converts media directive img src to directive URL', function () {
@@ -54,21 +53,8 @@ define([
5453
it('converts directive URL img src with a trailing forward slash ' +
5554
'to media url without a trailing forward slash',
5655
function () {
57-
try {
58-
expect(encodedHtmlWithForwardSlashInImgSrc).not.toEqual(encodedHtml);
59-
expect(obj.decodeDirectives(encodedHtmlWithForwardSlashInImgSrc)).toEqual(decodedHtml);
60-
} catch (error) {
61-
// Handle script errors that may occur due to malformed URLs or browser issues
62-
if (error && (error.message === null || error.message === 'Script error.' ||
63-
(typeof error.message === 'string' && error.message.includes('Script error')))) {
64-
// Log the issue but don't fail the test for script errors
65-
console.warn('Script error encountered in wysiwygAdapter test, marking as pending:', error);
66-
pending('Test pending due to script error in wysiwygAdapter when processing trailing slash URLs');
67-
} else {
68-
// Re-throw actual assertion failures
69-
throw error;
70-
}
71-
}
56+
expect(encodedHtmlWithForwardSlashInImgSrc).not.toEqual(encodedHtml);
57+
expect(obj.decodeDirectives(encodedHtmlWithForwardSlashInImgSrc)).toEqual(decodedHtml);
7258
}
7359
);
7460
});

0 commit comments

Comments
 (0)