Skip to content

Commit

Permalink
ENGCOM-6996: Fix #25243 #25359
Browse files Browse the repository at this point in the history
 - Merge Pull Request #25359 from korostii/magento2:korostii-patch-25243
 - Merged commits:
   1. 2596ca7
   2. 2f5909e
   3. d1b63cb
   4. f08857b
   5. 71ca4bb
   6. d79bf5e
   7. 3d36928
   8. 9db06e5
   9. df48d3e
   10. 9ccac04
   11. ce19171
  • Loading branch information
magento-engcom-team committed Feb 27, 2020
2 parents 9f093a3 + ce19171 commit ee53a9f
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Ui/view/frontend/web/js/model/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ define([
message = messageObj.message.replace(expr, function (varName) {
varName = varName.substr(1);

if (!isNaN(varName)) {
varName--;
}

if (messageObj.parameters.hasOwnProperty(varName)) {
return messageObj.parameters[varName];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'uiRegistry',
'Magento_Ui/js/model/messages'
], function (registry, Constr) {
'use strict';

describe('Magento_Ui/js/model/messages', function () {

var obj,
errorMessageText,
successMessageText,
messageObj;

beforeEach(function () {
obj = new Constr(
{
provider: 'provName',
name: '',
index: ''
});
errorMessageText = 'Error message test';
successMessageText = 'Success message test';

registry.set('provName', {
/** Stub */
on: function () {
},

/** Stub */
get: function () {
},

/** Stub */
set: function () {
}
});
});

it('adds massage without parameters', function () {
var type = [];

messageObj = {
message: 'Message test'
};
expect(obj.add(messageObj, type)).toEqual(true);
expect(type).toEqual([messageObj.message]);
});

it('add message with parameters', function () {
var returnedObj,
type = [];

messageObj = {
message: 'Message test case %1, case %2 and case %3',
parameters: [
'one',
'two',
'three'
]
};
returnedObj = ['Message test case ' + messageObj.parameters[0] + ', case ' +
messageObj.parameters[1] + ' and case ' + messageObj.parameters[2]];

expect(obj.add(messageObj, type)).toEqual(true);
expect(type).toEqual(returnedObj);
});

it('add error message, get error message, verify has error message', function () {
messageObj = {
message: errorMessageText
};

expect(obj.hasMessages()).toEqual(false);
expect(obj.addErrorMessage(messageObj)).toEqual(true);
expect(obj.getErrorMessages()()).toEqual([errorMessageText]);
expect(obj.hasMessages()).toEqual(true);
});

it('add success message, get success message, verify has success message', function () {
messageObj = {
message: successMessageText
};

expect(obj.addSuccessMessage(messageObj)).toEqual(true);
expect(obj.getSuccessMessages()()).toEqual([successMessageText]);
expect(obj.hasMessages()).toEqual(true);
});

it('cleaning messages', function () {
messageObj = {
message: 'Message test case %1, case %2 and case %3',
parameters: [
'one',
'two',
'three'
]
};
expect(obj.addErrorMessage(messageObj)).toEqual(true);
obj.clear();
expect(obj.getErrorMessages()()).toEqual([]);
expect(obj.hasMessages()).toEqual(false);
});
});
});

0 comments on commit ee53a9f

Please sign in to comment.