2018-05-17 18:25:12 +02:00
|
|
|
(function (root, factory) {
|
2018-06-03 16:40:20 +02:00
|
|
|
define(["jasmine", "mock", "test-utils"], factory);
|
|
|
|
} (this, function (jasmine, mock, test_utils) {
|
2018-05-17 18:25:12 +02:00
|
|
|
|
|
|
|
describe("The Login Form", function () {
|
|
|
|
|
|
|
|
it("contains a checkbox to indicate whether the computer is trusted or not",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
|
|
|
|
.then(function () {
|
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
test_utils.openControlBox();
|
|
|
|
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
|
|
|
|
expect(checkboxes.length).toBe(1);
|
|
|
|
|
|
|
|
const checkbox = checkboxes[0];
|
|
|
|
const label = cbview.el.querySelector(`label[for="${checkbox.getAttribute('id')}"]`);
|
|
|
|
expect(label.textContent).toBe('This is a trusted device');
|
|
|
|
expect(checkbox.checked).toBe(true);
|
|
|
|
|
|
|
|
cbview.el.querySelector('input[name="jid"]').value = 'dummy@localhost';
|
|
|
|
cbview.el.querySelector('input[name="password"]').value = 'secret';
|
|
|
|
|
|
|
|
spyOn(cbview.loginpanel, 'connect');
|
|
|
|
cbview.delegateEvents();
|
|
|
|
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('local');
|
2018-05-17 18:25:12 +02:00
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('local');
|
2018-05-17 18:25:12 +02:00
|
|
|
expect(cbview.loginpanel.connect).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
|
|
checkbox.click();
|
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('session');
|
2018-05-17 18:25:12 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
2018-05-18 12:21:02 +02:00
|
|
|
|
|
|
|
it("checkbox can be set to false by default",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['connectionInitialized', 'chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
trusted: false,
|
|
|
|
allow_registration: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.waitUntil(() => _converse.chatboxviews.get('controlbox'))
|
2018-08-22 22:20:15 +02:00
|
|
|
.then(() => {
|
2018-05-18 12:21:02 +02:00
|
|
|
var cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
test_utils.openControlBox();
|
|
|
|
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
|
|
|
|
expect(checkboxes.length).toBe(1);
|
|
|
|
|
|
|
|
const checkbox = checkboxes[0];
|
|
|
|
const label = cbview.el.querySelector(`label[for="${checkbox.getAttribute('id')}"]`);
|
|
|
|
expect(label.textContent).toBe('This is a trusted device');
|
|
|
|
expect(checkbox.checked).toBe(false);
|
|
|
|
|
|
|
|
cbview.el.querySelector('input[name="jid"]').value = 'dummy@localhost';
|
|
|
|
cbview.el.querySelector('input[name="password"]').value = 'secret';
|
|
|
|
|
|
|
|
spyOn(cbview.loginpanel, 'connect');
|
|
|
|
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('session');
|
2018-05-18 12:21:02 +02:00
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('session');
|
2018-05-18 12:21:02 +02:00
|
|
|
expect(cbview.loginpanel.connect).toHaveBeenCalled();
|
|
|
|
|
|
|
|
checkbox.click();
|
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
2018-08-23 09:41:39 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('local');
|
2018-05-18 12:21:02 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}));
|
2018-05-17 18:25:12 +02:00
|
|
|
});
|
|
|
|
}));
|