forked from joomla/joomla-cms
-
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.
Tests for permissions.js (joomla#13)
* Test suite for permissions.js * Added karma-jasmine-ajax plugin
- Loading branch information
1 parent
839aacd
commit 4ad9c2a
Showing
5 changed files
with
162 additions
and
1 deletion.
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
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
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,17 @@ | ||
<div id="permissionsjs"> | ||
<span id="icon_0" class="icon"></span> | ||
<div id="ajax-test"> | ||
<table> | ||
<tr> | ||
<div> | ||
<td> | ||
<input id="sendBtn" type="button"> | ||
</td> | ||
</div> | ||
<td> | ||
<span></span> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</div> |
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,32 @@ | ||
/** | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
* @package Joomla | ||
* @subpackage JavaScript Tests | ||
* @since 3.6 | ||
* @version 1.0.0 | ||
*/ | ||
|
||
define(['jquery', 'text!testsRoot/permissions/fixtures/fixture.html', 'libs/permissions', 'libs/core', 'jasmineJquery'], function ($, fixture) { | ||
$('body').append(fixture); | ||
|
||
window.id = '0'; | ||
window.value = '1'; | ||
|
||
event = {target: '#sendBtn'}; | ||
|
||
responses = { | ||
success: { | ||
status: 200, | ||
statusText: 'HTTP/1.1 200 OK', | ||
contentType: 'text/plain', | ||
responseText: '{"data": "true", "message": "0"}' | ||
}, | ||
fail: { | ||
status: 404, | ||
statusText: 'HTTP/1.1 404 Not Found', | ||
contentType: 'text/plain', | ||
responseText: '' | ||
} | ||
}; | ||
}); |
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,110 @@ | ||
/** | ||
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
* @package Joomla | ||
* @subpackage JavaScript Tests | ||
* @since 3.6 | ||
* @version 1.0.0 | ||
*/ | ||
|
||
define(['jquery', 'testsRoot/permissions/spec-setup', 'jasmineJquery'], function ($) { | ||
describe('sendPermissions', function () { | ||
beforeAll(function() { | ||
jasmine.Ajax.install(); | ||
Joomla.JText._ = jasmine.createSpy('_'); | ||
Joomla.renderMessages = jasmine.createSpy('renderMessages'); | ||
sendPermissions(event); | ||
}); | ||
|
||
afterAll(function () { | ||
jasmine.Ajax.uninstall(); | ||
}); | ||
|
||
it("should remove attribute class from icon", function() { | ||
expect($('#icon_0')).not.toHaveAttr('class'); | ||
}); | ||
|
||
it("should set style attribute to display the spinner in icon", function() { | ||
expect($('#icon_0')).toHaveAttr('style', 'background: url(../media/system/images/modal/spinner.gif); display: inline-block; width: 16px; height: 16px'); | ||
}); | ||
|
||
describe("on success with resp.data == 'true' & resp.message == 0", function() { | ||
var spanContainer = $('#ajax-test'); | ||
|
||
beforeAll(function() { | ||
sendPermissions(event); | ||
request = jasmine.Ajax.requests.mostRecent(); | ||
request.respondWith(responses.success); | ||
}); | ||
|
||
it("should make a AJAX request of type GET", function() { | ||
expect(request.method).toBe('GET'); | ||
}); | ||
|
||
it("should set attribute class in icon to icon-cancel", function() { | ||
expect($('#icon_0')).toHaveAttr('class', 'icon-cancel'); | ||
}); | ||
|
||
it("should remove classes label label-important from span elements", function() { | ||
expect(spanContainer.find('span')).not.toHaveClass('label label-important'); | ||
}); | ||
|
||
it("should add classes label label-success to span elements", function() { | ||
expect(spanContainer.find('span')).toHaveClass('label label-success'); | ||
}); | ||
|
||
it("should remove attribute style from icon", function() { | ||
expect($('#icon_0')).not.toHaveAttr('style'); | ||
}); | ||
|
||
it("should call Joomla.JText._('JLIB_RULES_ALLOWED')", function() { | ||
expect(Joomla.JText._).toHaveBeenCalledWith('JLIB_RULES_ALLOWED'); | ||
}); | ||
|
||
it("should call Joomla.renderMessages({ error: [undefined] })", function() { | ||
expect(Joomla.renderMessages).toHaveBeenCalledWith({ error: [undefined] }); | ||
}); | ||
}); | ||
|
||
describe("on success with resp.data !== 'true' & resp.message !== 0", function() { | ||
beforeAll(function() { | ||
sendPermissions(event); | ||
request = jasmine.Ajax.requests.mostRecent(); | ||
responses.success.responseText = '{"data": "false", "message": "1"}'; | ||
request.respondWith(responses.success); | ||
}); | ||
|
||
it("should call Joomla.renderMessages({ error: [undefined] })", function() { | ||
expect(Joomla.renderMessages).toHaveBeenCalledWith({ error: [undefined] }); | ||
}); | ||
|
||
it("should remove attribute style from icon", function() { | ||
expect($('#icon_0')).not.toHaveAttr('style'); | ||
}); | ||
|
||
it("should set attribute class in icon to icon-cancel", function() { | ||
expect($('#icon_0')).toHaveAttr('class', 'icon-cancel'); | ||
}); | ||
}); | ||
|
||
describe("on failure", function() { | ||
beforeAll(function() { | ||
sendPermissions(event); | ||
request = jasmine.Ajax.requests.mostRecent(); | ||
request.respondWith(responses.fail); | ||
}); | ||
|
||
it("should call Joomla.renderMessages({ error: [undefined] })", function() { | ||
expect(Joomla.renderMessages).toHaveBeenCalledWith({ error: [undefined] }); | ||
}); | ||
|
||
it("should remove attribute style from icon", function() { | ||
expect($('#icon_0')).not.toHaveAttr('style'); | ||
}); | ||
|
||
it("should set attribute class in icon to icon-cancel", function() { | ||
expect($('#icon_0')).toHaveAttr('class', 'icon-cancel'); | ||
}); | ||
}); | ||
}); | ||
}); |