<commit_before>var common = require('../casper_lib/common.js').common;

common.start_and_log_in();

casper.then(function () {
    var menu_selector = '#settings-dropdown';

    casper.test.info('Streams page');

    casper.waitUntilVisible(menu_selector, function () {
        casper.click(menu_selector);
        casper.then(function () {
            casper.click('a[href^="#streams"]');
            casper.test.assertUrlMatch(
                /^http:\/\/[^/]+\/#streams/,
                'URL suggests we are on streams page');
            casper.waitUntilVisible('#subscription_overlay.new-style', function () {
                casper.test.assertExists('#subscription_overlay.new-style', 'Streams page is active');
            });
        });
    });
});

casper.waitUntilVisible('.sub_unsub_button.checked', function () {
    casper.test.assertExists('.sub_unsub_button.checked', 'Initial subscriptions loaded');
    casper.click('#create_stream_button');
});

casper.then(function () {
    casper.test.assertExists('#user-checkboxes [data-email="<EMAIL>"]', 'Original user list contains Cordelia');
    casper.test.assertExists('#user-checkboxes [data-email="<EMAIL>"]', 'Original user list contains Othello');
});

casper.waitUntilVisible("#copy-from-stream-expand-collapse", function () {
    casper.click('#copy-from-stream-expand-collapse');
});

casper.waitUntilVisible("#stream-checkboxes", function () {
    casper.test.assertExists('#stream-checkboxes [data-stream-name="Scotland"]', 'Original stream list contains Scotland');
    casper.test.assertExists('#stream-checkboxes [data-stream-name="Rome"]', 'Original stream list contains Rome');
});

casper.waitUntilVisible("form#stream_creation_form", function () {
    casper.test.info("Filtering with keyword 'ot'");
    casper.fill('form#stream_creation_form', {user_list_filter: 'ot'});
});
casper.waitUntilVisible("#user-checkboxes", function () {
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             false,
                             "Cordelia is not visible");
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Othello is visible");

    /* The filter should not impact streams */
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Scotland"]'),
                             true,
                             "Scotland is visible");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Rome"]'),
                             true,
                             "Rome is visible");
});
casper.then(function () {
    casper.test.info("Check Uncheck only visible users for new stream");
    casper.click('.subs_set_all_users');
    casper.wait(100, function () {
        casper.test.assert(casper.evaluate(function () {
            return !$('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Cordelia is unchecked");
        casper.test.assert(casper.evaluate(function () {
            return $('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Othello is checked");
    });
});
casper.then(function () {
    casper.test.info("Check Uncheck only visible users for new stream");
    casper.click('.subs_unset_all_users');
    casper.wait(100, function () {
        casper.test.assert(casper.evaluate(function () {
            return !$('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Othello is unchecked");
    });
});
casper.then(function () {
    casper.test.info("Clearing user filter search box");
    casper.fill('form#stream_creation_form', {user_list_filter: ''});
});
casper.then(function () {
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Cordelia is visible again");
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Othello is visible again");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Scotland"]'),
                             true,
                             "Scotland is visible again");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Rome"]'),
                             true,
                             "Rome is visible again");
});
casper.waitUntilVisible('#stream_creation_form', function () {
    casper.test.assertTextExists('Create stream', 'New stream creation panel');
    casper.fill('form#stream_creation_form', {stream_name: 'Waseemio', stream_description: 'Oimeesaw'});
    casper.click('input[value="Scotland"] ~ span');
    casper.click('input[value="<EMAIL>"] ~ span');
    casper.click('input[value="<EMAIL>"] ~ span');
    casper.click('form#stream_creation_form button.btn.btn-primary');
});

casper.waitFor(function () {
    return casper.evaluate(function () {
        return $('.stream-name').is(':contains("Waseemio")');
    });
});
casper.then(function () {
    casper.test.info("User should be subscribed to stream Waseemio");
    casper.test.assertSelectorHasText('.stream-name', 'Waseemio');
    casper.test.assertSelectorHasText('.description', 'Oimeesaw');
    // Based on the selected checkboxes while creating stream,
    // 4 users from Scotland are added.
    // 1 user, Cordelia, is added. Othello (subscribed to Scotland) is not added twice.
    casper.test.assertSelectorHasText('.subscriber-count-text', '5');
    casper.fill('form#add_new_subscription', {stream_name: 'WASeemio'});
    casper.click('#create_stream_button');
});
casper.then(function () {
    casper.click('#create_stream_button');
    casper.fill('form#stream_creation_form', {stream_name: '  '});
    casper.click('form#stream_creation_form button.btn.btn-primary');
});
casper.waitForText('A stream needs to have a name', function () {
    casper.test.assertTextExists('A stream needs to have a name', "Can't create a stream with an empty name");
    casper.click('form#stream_creation_form button.btn.btn-default');
    casper.fill('form#add_new_subscription', {stream_name: '  '});
    casper.click('#create_stream_button');
    casper.fill('form#stream_creation_form', {stream_name: 'Waseemio'});
    casper.click('form#stream_creation_form button.btn.btn-primary');
});
casper.waitForText('A stream with this name already exists', function () {
    casper.test.assertTextExists('A stream with this name already exists', "Can't create a stream with a duplicate name");
    casper.test.info('Streams should be filtered when typing in the create box');<commit_msg>casper: Fix missing casper.then in subscriptions tests.<commit_after>var common = require('../casper_lib/common.js').common;

common.start_and_log_in();

casper.then(function () {
    var menu_selector = '#settings-dropdown';

    casper.test.info('Streams page');

    casper.waitUntilVisible(menu_selector, function () {
        casper.click(menu_selector);
        casper.then(function () {
            casper.click('a[href^="#streams"]');
            casper.test.assertUrlMatch(
                /^http:\/\/[^/]+\/#streams/,
                'URL suggests we are on streams page');
            casper.waitUntilVisible('#subscription_overlay.new-style', function () {
                casper.test.assertExists('#subscription_overlay.new-style', 'Streams page is active');
            });
        });
    });
});

casper.waitUntilVisible('.sub_unsub_button.checked', function () {
    casper.test.assertExists('.sub_unsub_button.checked', 'Initial subscriptions loaded');
    casper.click('#create_stream_button');
});

casper.then(function () {
    casper.test.assertExists('#user-checkboxes [data-email="<EMAIL>"]', 'Original user list contains Cordelia');
    casper.test.assertExists('#user-checkboxes [data-email="<EMAIL>"]', 'Original user list contains Othello');
});

casper.waitUntilVisible("#copy-from-stream-expand-collapse", function () {
    casper.click('#copy-from-stream-expand-collapse');
});

casper.waitUntilVisible("#stream-checkboxes", function () {
    casper.test.assertExists('#stream-checkboxes [data-stream-name="Scotland"]', 'Original stream list contains Scotland');
    casper.test.assertExists('#stream-checkboxes [data-stream-name="Rome"]', 'Original stream list contains Rome');
});

casper.waitUntilVisible("form#stream_creation_form", function () {
    casper.test.info("Filtering with keyword 'ot'");
    casper.fill('form#stream_creation_form', {user_list_filter: 'ot'});
});
casper.waitUntilVisible("#user-checkboxes", function () {
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             false,
                             "Cordelia is not visible");
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Othello is visible");

    /* The filter should not impact streams */
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Scotland"]'),
                             true,
                             "Scotland is visible");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Rome"]'),
                             true,
                             "Rome is visible");
});
casper.then(function () {
    casper.test.info("Check Uncheck only visible users for new stream");
    casper.click('.subs_set_all_users');
    casper.wait(100, function () {
        casper.test.assert(casper.evaluate(function () {
            return !$('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Cordelia is unchecked");
        casper.test.assert(casper.evaluate(function () {
            return $('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Othello is checked");
    });
});
casper.then(function () {
    casper.test.info("Check Uncheck only visible users for new stream");
    casper.click('.subs_unset_all_users');
    casper.wait(100, function () {
        casper.test.assert(casper.evaluate(function () {
            return !$('#user-checkboxes [value="<EMAIL>"]')[0].checked;
        }), "Othello is unchecked");
    });
});
casper.then(function () {
    casper.test.info("Clearing user filter search box");
    casper.fill('form#stream_creation_form', {user_list_filter: ''});
});
casper.then(function () {
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Cordelia is visible again");
    casper.test.assertEquals(casper.visible('#user-checkboxes [data-email="<EMAIL>"]'),
                             true,
                             "Othello is visible again");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Scotland"]'),
                             true,
                             "Scotland is visible again");
    casper.test.assertEquals(casper.visible('#stream-checkboxes [data-stream-name="Rome"]'),
                             true,
                             "Rome is visible again");
});
casper.then(function () {
    casper.waitUntilVisible('#stream_creation_form', function () {
        casper.test.assertTextExists('Create stream', 'New stream creation panel');
        casper.fill('form#stream_creation_form', {stream_name: 'Waseemio', stream_description: 'Oimeesaw'});
        casper.click('input[value="Scotland"] ~ span');
        casper.click('input[value="<EMAIL>"] ~ span');
        casper.click('input[value="<EMAIL>"] ~ span');
        casper.click('form#stream_creation_form button.btn.btn-primary');
    });
});

casper.then(function () {
    casper.waitFor(function () {
        return casper.evaluate(function () {
            return $('.stream-name').is(':contains("Waseemio")');
        });
    });
});

casper.then(function () {
    casper.test.info("User should be subscribed to stream Waseemio");
    casper.test.assertSelectorHasText('.stream-name', 'Waseemio');
    casper.test.assertSelectorHasText('.description', 'Oimeesaw');
    // Based on the selected checkboxes while creating stream,
    // 4 users from Scotland are added.
    // 1 user, Cordelia, is added. Othello (subscribed to Scotland) is not added twice.
    casper.test.assertSelectorHasText('.subscriber-count-text', '5');
    casper.fill('form#add_new_subscription', {stream_name: 'WASeemio'});
    casper.click('#create_stream_button');
});
casper.then(function () {
    casper.click('#create_stream_button');
    casper.fill('form#stream_creation_form', {stream_name: '  '});
    casper.click('form#stream_creation_form button.btn.btn-primary');
});
casper.waitForText('A stream needs to have a name', function () {
    casper.test.assertTextExists('A stream needs to have a name', "Can't create a stream with an empty name");
    casper.click('form#stream_creation_form button.btn.btn-default');
    casper.fill('form#add_new_subscription', {stream_name: '  '});
    casper.click('#create_stream_button');
    casper.fill('form#stream_creation_form', {stream_name: 'Waseemio'});
    casper.click('form#stream_creation_form button.btn.btn-primary');
});
casper.waitForText('A stream with this name already exists', function () {
    casper.test.assertTextExists('A stream with this name already exists', "Can't create a stream with a duplicate name");
    casper.test.info('Streams should be filtered when typing in the create box');
{'fraction_non_alphanumeric': 0.15856081230225885, 'fraction_numerical': 0.001765874475756015, 'mean_word_length': 3.197652872143298, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2227891', 'n_tokens_mistral': 4024, 'n_tokens_neox': 3961, 'n_words': 685}