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
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
const u = converse.env.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",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['chatBoxesInitialized'],
|
2018-05-17 18:25:12 +02:00
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: false },
|
2018-05-29 12:00:23 +02:00
|
|
|
async function (done, _converse) {
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2019-07-11 22:50:30 +02:00
|
|
|
const cbview = await u.waitUntil(() => _converse.chatboxviews.get('controlbox'));
|
2018-05-29 12:00:23 +02:00
|
|
|
const checkboxes = cbview.el.querySelectorAll('input[type="checkbox"]');
|
|
|
|
expect(checkboxes.length).toBe(1);
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
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);
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
cbview.el.querySelector('input[name="jid"]').value = 'romeo@montague.lit';
|
2018-05-29 12:00:23 +02:00
|
|
|
cbview.el.querySelector('input[name="password"]').value = 'secret';
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
spyOn(cbview.loginpanel, 'connect');
|
|
|
|
cbview.delegateEvents();
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
expect(_converse.config.get('storage')).toBe('local');
|
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
|
|
|
expect(_converse.config.get('storage')).toBe('local');
|
|
|
|
expect(cbview.loginpanel.connect).toHaveBeenCalled();
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2018-05-29 12:00:23 +02:00
|
|
|
checkbox.click();
|
|
|
|
cbview.el.querySelector('input[type="submit"]').click();
|
|
|
|
expect(_converse.config.get('storage')).toBe('session');
|
|
|
|
done();
|
2018-05-17 18:25:12 +02:00
|
|
|
}));
|
2018-05-18 12:21:02 +02:00
|
|
|
|
|
|
|
it("checkbox can be set to false by default",
|
2019-02-12 14:21:45 +01:00
|
|
|
mock.initConverse(
|
2019-10-11 16:38:01 +02:00
|
|
|
['chatBoxesInitialized'],
|
2018-05-18 12:21:02 +02:00
|
|
|
{ auto_login: false,
|
|
|
|
trusted: false,
|
|
|
|
allow_registration: false },
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2019-07-11 22:50:30 +02:00
|
|
|
u.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');
|
2019-10-24 14:29:15 +02:00
|
|
|
test_utils.openControlBox(_converse);
|
2018-05-18 12:21:02 +02:00
|
|
|
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);
|
|
|
|
|
2019-06-03 07:58:51 +02:00
|
|
|
cbview.el.querySelector('input[name="jid"]').value = 'romeo@montague.lit';
|
2018-05-18 12:21:02 +02:00
|
|
|
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
|
|
|
});
|
|
|
|
}));
|