Skip to content

Commit 5f78f94

Browse files
committed
Merge remote-tracking branch 'origin/ACP2E-4054' into PR_2025_08_04_chittima
2 parents 14e0739 + 3879518 commit 5f78f94

File tree

2 files changed

+46
-10
lines changed
  • app/code/Magento/Ui/view/base/web/js/form/element
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/element

2 files changed

+46
-10
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/abstract.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2014 Adobe
3+
* All Rights Reserved.
44
*/
55

66
/**
@@ -11,8 +11,9 @@ define([
1111
'mageUtils',
1212
'uiLayout',
1313
'uiElement',
14-
'Magento_Ui/js/lib/validation/validator'
15-
], function (_, utils, layout, Element, validator) {
14+
'Magento_Ui/js/lib/validation/validator',
15+
'uiRegistry'
16+
], function (_, utils, layout, Element, validator, registry) {
1617
'use strict';
1718

1819
return Element.extend({
@@ -483,6 +484,17 @@ define([
483484
}
484485

485486
return id;
487+
},
488+
489+
/**
490+
* Destroys switcher.
491+
*/
492+
destroy: function () {
493+
this._super();
494+
495+
if (this.switcherConfig.enabled) {
496+
registry.remove(this.switcherConfig.name);
497+
}
486498
}
487499
});
488500
});

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/form/element/abstract.test.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2015 Adobe
3+
* All Rights Reserved.
44
*/
55

66
/*eslint max-nested-callbacks: 0*/
@@ -23,7 +23,11 @@ define([
2323
},
2424
create: jasmine.createSpy(),
2525
set: jasmine.createSpy(),
26-
async: jasmine.createSpy()
26+
async: jasmine.createSpy(),
27+
remove: jasmine.createSpy()
28+
},
29+
'uiRegistry': {
30+
remove: jasmine.createSpy()
2731
},
2832
'/mage/utils/wrapper': jasmine.createSpy()
2933
},
@@ -37,16 +41,17 @@ define([
3741
template: 'ui/form/element/helper/service'
3842
}
3943
},
40-
model;
44+
model, registry;
4145

4246
beforeEach(function (done) {
4347
injector.mock(mocks);
4448
injector.require([
4549
'Magento_Ui/js/form/element/abstract',
50+
'uiRegistry',
4651
'knockoutjs/knockout-es5'
47-
], function (Constr) {
52+
], function (Constr, uiRegistry) {
4853
model = new Constr(params);
49-
54+
registry = uiRegistry;
5055
done();
5156
});
5257
});
@@ -342,5 +347,24 @@ define([
342347
expect(model.serviceDisabled()).toBeFalsy();
343348
});
344349
});
350+
describe('destroy method', function () {
351+
beforeEach(function () {
352+
model.switcherConfig = {
353+
enabled: true,
354+
name: 'test_switcher'
355+
};
356+
model.source = { off: function () {} };
357+
358+
if (typeof model._super !== 'function') {
359+
model._super = function () {};
360+
}
361+
spyOn(model, '_super').and.callThrough();
362+
});
363+
364+
it('should call registry.remove when switcherConfig.enabled is true', function () {
365+
model.destroy();
366+
expect(registry.remove).toHaveBeenCalledWith('test_switcher');
367+
});
368+
});
345369
});
346370
});

0 commit comments

Comments
 (0)