-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
dev/tests/js/jasmine/tests/app/code/Magento/Ui/frontend/js/model/messages.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |