<commit_before>'use strict';

var login = require('../app/scripts/bower_components/superdesk/client/spec/helpers/utils').login,
    consumersManagement = require('./helpers/pages').consumersManagement;

function assertToastMsg(type, msg) {
    var cssSelector = '.notification-holder .alert-' + type,
        toast = $(cssSelector);

    browser.sleep(500);
    browser.ignoreSynchronization = true;
    expect(toast.getText()).toContain(msg);
    browser.sleep(500);
    browser.ignoreSynchronization = false;
}

var consumer = {
    name: '<NAME>',
    apiUrl: 'http://www.masseyferguson.de/api'
};

var contact = {
    firstName: 'Chuck',
    lastName: 'Norris',
    email: '<EMAIL>'
};

describe('Consumers', function() {

    beforeEach(function(done) {login().then(done);});

    describe('list', function() {
        it('can open consumers managements and list the consumers', function() {
            consumersManagement.openConsumersManagement();
        });

        it('can create a new consumer', function() {
            consumersManagement.openConsumersManagement();

            element(by.css('button.navbtn.sd-create-btn'))
                .click()
                .then(function() {
                    return element(by.css('input#name')).isDisplayed();
                })
                .then(function() {
                    return element(by.css('input#name')).sendKeys(consumer.name);
                })
                .then(function() {
                    return element(by.css('input#api-url')).sendKeys(consumer.apiUrl);
                })
                .then(function() {
                    return element(by.css('input[name="first_name"]'))
                        .sendKeys(contact.firstName);
                })
                .then(function() {
                    return element(by.css('input[name="last_name"]'))
                        .sendKeys(contact.lastName);
                })
                .then(function() {
                    return element(by.css('input[name="email"]'))
                        .sendKeys(contact.email);
                })
                .then(function() {
                    return element(by.css('#save-edit-btn')).click();
                })
                .then(function() {
                    return assertToastMsg('success', 'consumer saved.');
                })
                .then(function() {
                    var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
                    expect(firstRowName.getText()).toEqual(consumer.name);
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(2);
                });
        });

        it('can update a consumer', function() {
            consumersManagement.openConsumersManagement();

            var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
            expect(firstRowName.getText()).toEqual('<NAME>');

            firstRowName
                .click()
                .then(function() {
                    return element(by.css('input#name')).isDisplayed();
                })
                .then(function() {
                    return element(by.css('input#name')).clear();
                })
                .then(function() {
                    return element(by.css('input#name')).sendKeys(consumer.name);
                })
                .then(function() {
                    return element(by.css('#save-edit-btn')).click();
                })
                .then(function() {
                    return assertToastMsg('success', 'consumer saved.');
                })
                .then(function() {
                    var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
                    expect(firstRowName.getText()).toEqual(consumer.name);
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(1);
                });
        });

        it('can delete a consumer', function() {
           consumersManagement.openConsumersManagement();
            var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
            expect(firstRowName.getText()).toEqual('<NAME>');

            var elemToHover = element(by.css('ul.table-body div.row-wrapper'));

            browser.actions().mouseMove(elemToHover, {x: 3, y: 3}).perform()
                .then(function() {
                    return element(by.css('ul.table-body li a.delete-consumer'))
                        .click();
                })
                .then(function() {
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(0);
                });
        });
    });
});<commit_msg>New test, add a contact to an existing consumer<commit_after>'use strict';

var login = require('../app/scripts/bower_components/superdesk/client/spec/helpers/utils').login,
    consumersManagement = require('./helpers/pages').consumersManagement;

function assertToastMsg(type, msg) {
    var cssSelector = '.notification-holder .alert-' + type,
        toast = $(cssSelector);

    browser.sleep(500);
    browser.ignoreSynchronization = true;
    expect(toast.getText()).toContain(msg);
    browser.sleep(500);
    browser.ignoreSynchronization = false;
}

var consumer = {
    name: '<NAME>',
    apiUrl: 'http://www.masseyferguson.de/api'
};

var contact = {
    firstName: 'Chuck',
    lastName: 'Norris',
    email: '<EMAIL>'
};

var contact2 = {
    firstName: 'Steven',
    lastName: 'Seagal',
    email: '<EMAIL>'
};

describe('Consumers', function() {

    beforeEach(function(done) {login().then(done);});

    describe('list', function() {
        it('can open consumers managements and list the consumers', function() {
            consumersManagement.openConsumersManagement();
        });

        it('can create a new consumer', function() {
            consumersManagement.openConsumersManagement();

            element(by.css('button.navbtn.sd-create-btn'))
                .click()
                .then(function() {
                    return element(by.css('input#name')).isDisplayed();
                })
                .then(function() {
                    return element(by.css('input#name')).sendKeys(consumer.name);
                })
                .then(function() {
                    return element(by.css('input#api-url')).sendKeys(consumer.apiUrl);
                })
                .then(function() {
                    return element(by.css('input[name="first_name"]'))
                        .sendKeys(contact.firstName);
                })
                .then(function() {
                    return element(by.css('input[name="last_name"]'))
                        .sendKeys(contact.lastName);
                })
                .then(function() {
                    return element(by.css('input[name="email"]'))
                        .sendKeys(contact.email);
                })
                .then(function() {
                    return element(by.css('#save-edit-btn')).click();
                })
                .then(function() {
                    return assertToastMsg('success', 'consumer saved.');
                })
                .then(function() {
                    var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
                    expect(firstRowName.getText()).toEqual(consumer.name);
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(2);
                });
        });

        it('can update a consumer', function() {
            consumersManagement.openConsumersManagement();

            var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
            expect(firstRowName.getText()).toEqual('<NAME>');

            firstRowName
                .click()
                .then(function() {
                    return element(by.css('input#name')).isDisplayed();
                })
                .then(function() {
                    return element(by.css('input#name')).clear();
                })
                .then(function() {
                    return element(by.css('input#name')).sendKeys(consumer.name);
                })
                .then(function() {
                    return element(by.css('#save-edit-btn')).click();
                })
                .then(function() {
                    return assertToastMsg('success', 'consumer saved.');
                })
                .then(function() {
                    var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
                    expect(firstRowName.getText()).toEqual(consumer.name);
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(1);
                });
        });

        it('can delete a consumer', function() {
           consumersManagement.openConsumersManagement();
            var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
            expect(firstRowName.getText()).toEqual('<NAME>');

            var elemToHover = element(by.css('ul.table-body div.row-wrapper'));

            browser.actions().mouseMove(elemToHover, {x: 3, y: 3}).perform()
                .then(function() {
                    return element(by.css('ul.table-body li a.delete-consumer'))
                        .click();
                })
                .then(function() {
                    return element.all(by.repeater('consumer in consumers')).count();
                })
                .then(function(count) {
                    expect(count).toEqual(0);
                });
        });
    });

    describe('Contacts', function() {
        it('can add a contact to an existing entry', function() {
            consumersManagement.openConsumersManagement();

            var firstRowName = element(by.css('ul.table-body div.row-wrapper div.name'));
            expect(firstRowName.getText()).toEqual('<NAME>');

            firstRowName
                .click()
                .then(function() {
                    return element(by.css('button[ng-click="addContact()"]')).isDisplayed();
                })
                .then(function() {
                    return element(by.css('button[ng-click="addContact()"]')).click();
                })
                .then(function() {
                    return element.all(by.repeater('contact in contacts')).get(1).isDisplayed();
                })
                .then(function() {
                    return element
                        .all(by.repeater('contact in contacts'))
                        .get(1)
                        .element(by.css('input[name="first_name"]'))
                        .sendKeys(contact2.firstName);
                })
                .then(function() {
                    return element
                        .all(by.repeater('contact in contacts'))
                        .get(1)
                        .element(by.css('input[name="last_name"]'))
                        .sendKeys(contact2.lastName);
                })
                .then(function() {
                    return element
                        .all(by.repeater('contact in contacts'))
                        .get(1)
                        .element(by.css('input[name="email"]'))
                        .sendKeys(contact2.email);
                })
                .then(function() {
                    return element(by.css('#save-edit-btn')).click();
                })
                .then(function() {
                    return assertToastMsg('success', 'consumer saved.');
                });
         });
    });
});
{'fraction_non_alphanumeric': 0.14428923582580114, 'fraction_numerical': 0.0024650780608052587, 'mean_word_length': 1.4991786447638604, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1437529', 'n_tokens_mistral': 3176, 'n_tokens_neox': 2988, 'n_words': 448}