forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for app/code/Magento/Ui/view/frontend/web/js/model/messag…
…es.js
- Loading branch information
akartavtsev
committed
Jan 13, 2020
1 parent
2596ca7
commit 2f5909e
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
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,128 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'ko', | ||
'uiRegistry', | ||
'Magento_Ui/js/model/messages' | ||
], function (ko, registry, Constr) { | ||
'use strict'; | ||
|
||
describe('Magento_Ui/js/model/messages', function () { | ||
var obj = new Constr({ | ||
provider: 'provName', | ||
name: '', | ||
index: '' | ||
}); | ||
|
||
registry.set('provName', { | ||
/** Stub */ | ||
on: function () { | ||
}, | ||
|
||
/** Stub */ | ||
get: function () { | ||
}, | ||
|
||
/** Stub */ | ||
set: function () { | ||
} | ||
}); | ||
|
||
describe('initialize method', function () { | ||
it('check for existing', function () { | ||
expect(obj).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe('add method', function () { | ||
it('simple message', function () { | ||
var messageObj = { | ||
message: "Message test" | ||
}, | ||
type = [], | ||
returnedObj = ["Message test"]; | ||
expect(obj.add(messageObj, type)).toEqual(true); | ||
expect(type).toEqual(returnedObj); | ||
}); | ||
|
||
it('message with parameters', function () { | ||
var messageObj = { | ||
message: "Message test case %1, case %2 and case %3", | ||
parameters: [ | ||
"one", | ||
"two", | ||
'three' | ||
] | ||
}, | ||
type = [], | ||
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); | ||
}); | ||
}); | ||
|
||
describe('check methods: hasMessages, addErrorMessage, getErrorMessages', function () { | ||
it('hasMessages method before adding messages', function () { | ||
expect(obj.hasMessages()).toEqual(false); | ||
}); | ||
|
||
it('check addErrorMessage method', function () { | ||
var messageObj = { | ||
message: "Error message test" | ||
}; | ||
|
||
expect(obj.addErrorMessage(messageObj)).toEqual(true); | ||
}); | ||
|
||
it('check getErrorMessage method', function () { | ||
var errorMessages = ko.observableArray(["Error message test"]); | ||
|
||
expect(obj.getErrorMessages()()).toEqual(errorMessages()); | ||
}); | ||
|
||
|
||
it('hasMessages method after adding Error messages', function () { | ||
expect(obj.hasMessages()).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('check clean method for Error messages', function () { | ||
it('check for cleaning messages', function () { | ||
obj.clear(); | ||
expect(obj.getErrorMessages()()).toEqual([]); | ||
expect(obj.hasMessages()).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('check methods: hasMessages, addSuccessMessage, getSuccessMessages', function () { | ||
it('check addSuccessMessage and getSuccessMessage', function () { | ||
var messageObj = { | ||
message: "Success message test" | ||
}; | ||
|
||
expect(obj.addSuccessMessage(messageObj)).toEqual(true); | ||
}); | ||
|
||
it('check method getSuccessMessage', function () { | ||
var successMessages = ko.observableArray(["Success message test"]); | ||
expect(obj.getSuccessMessages()()).toEqual(successMessages()); | ||
}); | ||
|
||
it('hasMessages method after adding Success messages', function () { | ||
expect(obj.hasMessages()).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('check clean method for Success messages', function () { | ||
it('check for cleaning messages', function () { | ||
obj.clear(); | ||
expect(obj.getSuccessMessages()()).toEqual([]); | ||
expect(obj.hasMessages()).toEqual(false); | ||
}); | ||
}); | ||
}); | ||
}); |