2020-10-20 06:45:35 +02:00
|
|
|
/*global mock, converse */
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
const u = converse.env.utils;
|
|
|
|
|
|
|
|
describe("The Login Form", function () {
|
|
|
|
|
|
|
|
it("contains a checkbox to indicate whether the computer is trusted or not",
|
|
|
|
mock.initConverse(
|
|
|
|
['chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
|
|
|
allow_registration: false },
|
|
|
|
async function (done, _converse) {
|
|
|
|
|
|
|
|
const cbview = await u.waitUntil(() => _converse.chatboxviews.get('controlbox'));
|
2020-10-20 06:45:35 +02:00
|
|
|
mock.toggleControlBox();
|
2020-12-08 12:54:14 +01:00
|
|
|
const checkboxes = cbview.querySelectorAll('input[type="checkbox"]');
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(checkboxes.length).toBe(1);
|
|
|
|
|
|
|
|
const checkbox = checkboxes[0];
|
2020-12-08 12:54:14 +01:00
|
|
|
const label = cbview.querySelector(`label[for="${checkbox.getAttribute('id')}"]`);
|
2020-04-22 13:11:48 +02:00
|
|
|
expect(label.textContent).toBe('This is a trusted device');
|
|
|
|
expect(checkbox.checked).toBe(true);
|
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[name="jid"]').value = 'romeo@montague.lit';
|
|
|
|
cbview.querySelector('input[name="password"]').value = 'secret';
|
2020-04-22 13:11:48 +02:00
|
|
|
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(_converse.config.get('trusted')).toBe(true);
|
|
|
|
expect(_converse.getDefaultStore()).toBe('persistent');
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[type="submit"]').click();
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(_converse.config.get('trusted')).toBe(true);
|
|
|
|
expect(_converse.getDefaultStore()).toBe('persistent');
|
2020-04-22 13:11:48 +02:00
|
|
|
|
|
|
|
checkbox.click();
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[type="submit"]').click();
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(_converse.config.get('trusted')).toBe(false);
|
|
|
|
expect(_converse.getDefaultStore()).toBe('session');
|
2020-04-22 13:11:48 +02:00
|
|
|
done();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it("checkbox can be set to false by default",
|
|
|
|
mock.initConverse(
|
|
|
|
['chatBoxesInitialized'],
|
|
|
|
{ auto_login: false,
|
2020-10-20 06:45:35 +02:00
|
|
|
allow_user_trust_override: 'off',
|
2020-04-22 13:11:48 +02:00
|
|
|
allow_registration: false },
|
2020-10-20 06:45:35 +02:00
|
|
|
async function (done, _converse) {
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2020-10-20 06:45:35 +02:00
|
|
|
await u.waitUntil(() => _converse.chatboxviews.get('controlbox'))
|
|
|
|
const cbview = _converse.chatboxviews.get('controlbox');
|
|
|
|
mock.toggleControlBox();
|
2020-12-08 12:54:14 +01:00
|
|
|
const checkboxes = cbview.querySelectorAll('input[type="checkbox"]');
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(checkboxes.length).toBe(1);
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2020-10-20 06:45:35 +02:00
|
|
|
const checkbox = checkboxes[0];
|
2020-12-08 12:54:14 +01:00
|
|
|
const label = cbview.querySelector(`label[for="${checkbox.getAttribute('id')}"]`);
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(label.textContent).toBe('This is a trusted device');
|
|
|
|
expect(checkbox.checked).toBe(false);
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[name="jid"]').value = 'romeo@montague.lit';
|
|
|
|
cbview.querySelector('input[name="password"]').value = 'secret';
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[type="submit"]').click();
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(_converse.config.get('trusted')).toBe(false);
|
|
|
|
expect(_converse.getDefaultStore()).toBe('session');
|
2018-05-17 18:25:12 +02:00
|
|
|
|
2020-10-20 06:45:35 +02:00
|
|
|
checkbox.click();
|
2020-12-08 12:54:14 +01:00
|
|
|
cbview.querySelector('input[type="submit"]').click();
|
2020-10-20 06:45:35 +02:00
|
|
|
expect(_converse.config.get('trusted')).toBe(true);
|
|
|
|
expect(_converse.getDefaultStore()).toBe('persistent');
|
|
|
|
done();
|
2020-04-22 13:11:48 +02:00
|
|
|
}));
|
2020-04-22 12:10:39 +02:00
|
|
|
});
|