2015-10-14 00:21:23 +02:00
|
|
|
var common = require('../casper_lib/common.js').common;
|
2016-07-24 07:11:12 +02:00
|
|
|
var test_credentials = require('../../var/casper/test_credentials.js').test_credentials;
|
2016-07-19 14:35:08 +02:00
|
|
|
var REALMS_HAVE_SUBDOMAINS = casper.cli.get('subdomains');
|
2013-03-20 22:38:20 +01:00
|
|
|
|
|
|
|
common.start_and_log_in();
|
|
|
|
|
2013-06-12 17:38:13 +02:00
|
|
|
var form_sel = 'form[action^="/json/settings/change"]';
|
2016-12-07 18:38:59 +01:00
|
|
|
var regex_zuliprc = /^data:application\/octet-stream;charset=utf-8,\[api\]\nemail=.+\nkey=.+\nsite=.+\n$/;
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2016-10-07 19:06:35 +02:00
|
|
|
casper.then(function () {
|
|
|
|
var menu_selector = '#settings-dropdown';
|
|
|
|
casper.waitUntilVisible(menu_selector, function () {
|
|
|
|
casper.click(menu_selector);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('a[href^="#settings"]', function () {
|
|
|
|
casper.test.info('Settings page');
|
|
|
|
casper.click('a[href^="#settings"]');
|
|
|
|
});
|
2016-06-10 09:03:36 +02:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible("#settings-change-box", function () {
|
2016-12-06 19:57:46 +01:00
|
|
|
casper.test.assertUrlMatch(/^http:\/\/[^/]+\/#settings/, 'URL suggests we are on settings page');
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.test.assertExists('#settings.tab-pane.active', 'Settings page is active');
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.test.assertNotVisible("#pw_change_controls");
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.click(".change_password_button");
|
|
|
|
});
|
2013-06-12 17:38:13 +02:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible("#pw_change_controls", function () {
|
|
|
|
casper.waitForResource("zxcvbn.js", function () {
|
|
|
|
casper.test.assertVisible("#old_password");
|
|
|
|
casper.test.assertVisible("#new_password");
|
|
|
|
casper.test.assertVisible("#confirm_password");
|
|
|
|
|
|
|
|
casper.test.assertEqual(casper.getFormValues(form_sel).full_name, "Iago");
|
|
|
|
|
|
|
|
casper.fill(form_sel, {
|
2016-12-03 03:08:47 +01:00
|
|
|
full_name: "IagoNew",
|
|
|
|
old_password: test_credentials.default_user.password,
|
|
|
|
new_password: "qwertyuiop",
|
2017-01-12 00:17:43 +01:00
|
|
|
confirm_password: "qwertyuiop",
|
2016-11-17 12:25:05 +01:00
|
|
|
});
|
|
|
|
casper.click('input[name="change_settings"]');
|
2016-06-04 02:19:07 +02:00
|
|
|
});
|
2013-06-12 17:38:13 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#settings-status', function () {
|
|
|
|
casper.test.assertSelectorHasText('#settings-status', 'Updated settings!');
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.click('#api_key_button');
|
|
|
|
});
|
2013-06-12 17:38:13 +02:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#get_api_key_password', function () {
|
2016-12-03 03:08:47 +01:00
|
|
|
casper.fill('form[action^="/json/fetch_api_key"]', {password:'qwertyuiop'});
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.click('input[name="view_api_key"]');
|
|
|
|
});
|
2013-03-20 22:38:20 +01:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#show_api_key_box', function () {
|
|
|
|
casper.test.assertMatch(casper.fetchText('#api_key_value'), /[a-zA-Z0-9]{32}/, "Looks like an API key");
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
// Change it all back so the next test can still log in
|
|
|
|
casper.fill(form_sel, {
|
2016-12-03 03:08:47 +01:00
|
|
|
full_name: "Iago",
|
|
|
|
old_password: "qwertyuiop",
|
|
|
|
new_password: test_credentials.default_user.password,
|
2017-01-12 00:17:43 +01:00
|
|
|
confirm_password: test_credentials.default_user.password,
|
2016-11-17 12:25:05 +01:00
|
|
|
});
|
|
|
|
casper.click('input[name="change_settings"]');
|
2013-06-12 17:38:13 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-07 18:38:59 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#show_api_key_box', function () {
|
|
|
|
casper.test.assertExists('#download_zuliprc', '~/.zuliprc button exists');
|
|
|
|
casper.click('#download_zuliprc');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#download_zuliprc[href^="data:application"]', function () {
|
|
|
|
casper.test.assertMatch(
|
|
|
|
decodeURIComponent(casper.getElementsAttribute('#download_zuliprc', 'href')),
|
|
|
|
regex_zuliprc,
|
2017-01-11 23:47:14 +01:00
|
|
|
'Looks like a zuliprc file');
|
2016-12-07 18:38:59 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#settings-status', function () {
|
|
|
|
casper.test.assertSelectorHasText('#settings-status', 'Updated settings!');
|
|
|
|
});
|
2013-06-12 17:38:13 +02:00
|
|
|
});
|
|
|
|
|
2014-02-19 16:07:28 +01:00
|
|
|
casper.then(function create_bot() {
|
|
|
|
casper.test.info('Filling out the create bot form');
|
|
|
|
|
|
|
|
casper.fill('#create_bot_form',{
|
|
|
|
bot_name: 'Bot 1',
|
|
|
|
bot_short_name: '1',
|
|
|
|
bot_default_sending_stream: 'Denmark',
|
2017-01-12 00:17:43 +01:00
|
|
|
bot_default_events_register_stream: 'Rome',
|
2014-02-19 16:07:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.test.info('Submiting the create bot form');
|
|
|
|
casper.click('#create_bot_button');
|
|
|
|
});
|
|
|
|
|
2016-12-07 18:38:59 +01:00
|
|
|
casper.then(function () {
|
|
|
|
var button_sel = '.download_bot_zuliprc[data-email="1-bot@zulip.com"]';
|
|
|
|
|
|
|
|
casper.waitUntilVisible(button_sel, function () {
|
|
|
|
casper.click(button_sel);
|
|
|
|
|
|
|
|
casper.waitUntilVisible(button_sel + '[href^="data:application"]', function () {
|
|
|
|
casper.test.assertMatch(
|
|
|
|
decodeURIComponent(casper.getElementsAttribute(button_sel, 'href')),
|
|
|
|
regex_zuliprc,
|
2017-01-11 23:47:14 +01:00
|
|
|
'Looks like a bot ~/.zuliprc file');
|
2016-12-07 18:38:59 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('.open_edit_bot_form[data-email="1-bot@zulip.com"]', function open_edit_bot_form() {
|
|
|
|
casper.test.info('Opening edit bot form');
|
|
|
|
casper.click('.open_edit_bot_form[data-email="1-bot@zulip.com"]');
|
|
|
|
});
|
2014-02-19 16:07:28 +01:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('.edit_bot_form[data-email="1-bot@zulip.com"]', function test_edit_bot_form_values() {
|
|
|
|
var form_sel = '.edit_bot_form[data-email="1-bot@zulip.com"]';
|
|
|
|
casper.test.info('Testing edit bot form values');
|
|
|
|
|
|
|
|
// casper.test.assertEqual(
|
|
|
|
// common.get_form_field_value(form_sel + ' [name=bot_name]'),
|
2017-01-11 23:47:14 +01:00
|
|
|
// 'Bot 1');
|
2016-11-17 12:25:05 +01:00
|
|
|
// casper.test.assertEqual(
|
|
|
|
// common.get_form_field_value(form_sel + ' [name=bot_default_sending_stream]'),
|
2017-01-11 23:47:14 +01:00
|
|
|
// 'Denmark');
|
2016-11-17 12:25:05 +01:00
|
|
|
// casper.test.assertEqual(
|
|
|
|
// common.get_form_field_value(form_sel + ' [name=bot_default_events_register_stream]'),
|
2017-01-11 23:47:14 +01:00
|
|
|
// 'Rome');
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.test.assertEqual(
|
|
|
|
common.get_form_field_value(form_sel + ' [name=bot_name]'),
|
2017-01-11 23:47:14 +01:00
|
|
|
'Bot 1');
|
2016-11-17 12:25:05 +01:00
|
|
|
});
|
2014-02-19 16:07:28 +01:00
|
|
|
});
|
|
|
|
|
2016-07-19 08:53:09 +02:00
|
|
|
/*
|
|
|
|
This test needs a modification. As it stands now, it will cause a race
|
|
|
|
condition with all subsequent tests which access the UserProfile object
|
|
|
|
this test modifies. Currently, if we modify alert words, we don't get
|
|
|
|
any notification from the server, issue reported at
|
|
|
|
https://github.com/zulip/zulip/issues/1269. Consequently, we can't wait
|
|
|
|
on any condition to avoid the race condition.
|
|
|
|
|
2016-06-24 01:53:49 +02:00
|
|
|
casper.waitForSelector('#create_alert_word_form', function () {
|
2016-07-14 01:32:25 +02:00
|
|
|
casper.test.info('Attempting to submit an empty alert word');
|
|
|
|
casper.click('#create_alert_word_button');
|
|
|
|
casper.test.info('Checking that an error is displayed');
|
|
|
|
casper.test.assertVisible('#empty_alert_word_error');
|
|
|
|
|
|
|
|
casper.test.info('Closing the error message');
|
|
|
|
casper.click('.close-empty-alert-word-error');
|
|
|
|
casper.test.info('Checking the error is hidden');
|
|
|
|
casper.test.assertNotVisible('#empty_alert_word_error');
|
|
|
|
|
2016-06-24 01:53:49 +02:00
|
|
|
casper.test.info('Filling out the alert word input');
|
|
|
|
casper.sendKeys('#create_alert_word_name', 'some phrase');
|
|
|
|
casper.click('#create_alert_word_button');
|
|
|
|
|
|
|
|
casper.test.info('Checking that an element was created');
|
|
|
|
casper.test.assertExists('div.alert-word-information-box');
|
|
|
|
casper.test.assertSelectorHasText('span.value', 'some phrase');
|
|
|
|
|
|
|
|
casper.test.info('Deleting element');
|
|
|
|
casper.click('button.remove-alert-word');
|
|
|
|
casper.test.info('Checking that the element was deleted');
|
|
|
|
casper.test.assertDoesntExist('div.alert-word-information-box');
|
|
|
|
});
|
2016-07-19 08:53:09 +02:00
|
|
|
*/
|
2016-06-24 01:53:49 +02:00
|
|
|
|
2016-07-05 08:03:22 +02:00
|
|
|
casper.then(function change_default_language() {
|
|
|
|
casper.test.info('Changing the default language');
|
2016-08-02 15:03:42 +02:00
|
|
|
casper.waitForSelector('#default_language');
|
2016-07-05 08:03:22 +02:00
|
|
|
});
|
|
|
|
|
2016-08-02 15:03:42 +02:00
|
|
|
casper.thenClick('#default_language');
|
|
|
|
|
|
|
|
casper.waitUntilVisible('#default_language_modal');
|
|
|
|
|
|
|
|
casper.thenClick('a[data-code="zh_CN"]');
|
|
|
|
|
2016-07-05 08:03:22 +02:00
|
|
|
casper.waitUntilVisible('#display-settings-status', function () {
|
|
|
|
casper.test.assertSelectorHasText('#display-settings-status', '简体中文 is now the default language');
|
2016-07-19 08:57:51 +02:00
|
|
|
casper.test.info("Reloading the page.");
|
|
|
|
casper.reload();
|
2016-07-05 08:03:22 +02:00
|
|
|
});
|
|
|
|
|
2016-11-17 12:25:05 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitForSelector("#default_language", function () {
|
|
|
|
casper.test.info("Checking if we are on Chinese page.");
|
|
|
|
casper.test.assertEvalEquals(function () {
|
|
|
|
return $('#default_language_name').text();
|
|
|
|
}, '简体中文');
|
|
|
|
casper.test.info("Opening German page through i18n url.");
|
|
|
|
});
|
2016-07-05 08:03:22 +02:00
|
|
|
});
|
|
|
|
|
2016-07-19 14:35:08 +02:00
|
|
|
var settings_url = "";
|
|
|
|
if (REALMS_HAVE_SUBDOMAINS) {
|
|
|
|
settings_url = 'http://zulip.zulipdev.com:9981/de/#settings';
|
|
|
|
} else {
|
2016-10-07 00:19:19 +02:00
|
|
|
settings_url = 'http://zulipdev.com:9981/de/#settings';
|
2016-07-19 14:35:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
casper.thenOpen(settings_url);
|
2016-07-05 08:03:22 +02:00
|
|
|
|
2016-07-19 08:57:51 +02:00
|
|
|
casper.waitForSelector("#settings-change-box", function check_url_preference() {
|
|
|
|
casper.test.info("Checking the i18n url language precedence.");
|
2016-07-05 08:03:22 +02:00
|
|
|
casper.test.assertEvalEquals(function () {
|
|
|
|
return document.documentElement.lang;
|
|
|
|
}, 'de');
|
|
|
|
casper.test.info("Changing language back to English.");
|
|
|
|
});
|
|
|
|
|
2016-08-02 15:03:42 +02:00
|
|
|
casper.thenClick('#default_language');
|
|
|
|
|
|
|
|
casper.waitUntilVisible('#default_language_modal');
|
|
|
|
|
|
|
|
casper.thenClick('a[data-code="en"]');
|
|
|
|
|
2016-07-19 08:57:51 +02:00
|
|
|
/*
|
|
|
|
* Changing the language back to English so that subsequent tests pass.
|
|
|
|
*/
|
2016-07-05 08:03:22 +02:00
|
|
|
casper.waitUntilVisible('#display-settings-status', function () {
|
|
|
|
casper.test.assertSelectorHasText('#display-settings-status', 'English is now the default language');
|
|
|
|
});
|
|
|
|
|
2016-12-15 12:43:08 +01:00
|
|
|
if (REALMS_HAVE_SUBDOMAINS) {
|
|
|
|
settings_url = 'http://zulip.zulipdev.com:9981/';
|
|
|
|
} else {
|
|
|
|
settings_url = 'http://zulipdev.com:9981/';
|
|
|
|
}
|
|
|
|
|
|
|
|
casper.thenOpen(settings_url);
|
|
|
|
|
2013-08-06 21:32:15 +02:00
|
|
|
// TODO: test the "Declare Zulip Bankruptcy option"
|
2013-06-12 17:38:13 +02:00
|
|
|
|
2013-03-20 22:38:20 +01:00
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|