<commit_before>'use strict';

var config = require('../support/config.json');

module.exports = function () {
    this.World = require('../support/world.js').World;

    this.Then(/^система отобразит список валидационных сообщений: (.*?)$/, function (messages) {
        var selector = this.selectors.XPATH.Toastr.messages();
        var xpath = this.by.xpath(selector);
        var that = this;

        messages = this._.map(messages.split('", '), function (item) {
            return item
                .replace(/"/g, '')
                .replace(/''/g, '"');
        });

        return this.driver.findElements(xpath).then(function (msgs) {
            that.assert.equal(msgs.length, messages.length, 'Количество сообщений не совпадает');

            return new Promise(function (resolve, reject) {
                msgs.forEach(function (msg, i) {
                    msg.getText().then(function (text) {
                        messages[i] = that.helpers.ignoreDates(text.trim(), messages[i]);

                        var linesActual = text.split('\n');
                        var linesExpected = messages[i].split('\\n');

                        try {
                            var diff = that._.difference(linesActual, linesExpected);

                            if (!that._.isArray(diff)) {
                                diff = [diff];
                            }

                            that.assert.deepEqual(linesActual, linesExpected, 'Не совпали:\n' + diff.join('\n') + '\n');
                        } catch (err) {
                            reject(err);
                        }

                        if (i == msgs.length - 1) {
                            that.driver.executeScript('$("#toast-container").remove();');
                            resolve();
                        }
                    });
                });
            });
        });
    });

    this.Then(/^система не отобразит валидационных сообщений$/, function () {
        var selector = this.selectors.XPATH.Toastr.messages();
        var xpath = this.by.xpath(selector);
        var that = this;

        this.driver.manage().timeouts().implicitlyWait(4500);

        return this.driver.findElements(xpath)
            .then(function (msgs) {
                that.driver.manage().timeouts().implicitlyWait(config.timeouts.main);
                if (msgs.length != 0) {
                    throw new Error('Найдено ' + msgs.length + ' сообщений');
                }
            });
    });

    this.When(/^я увижу элемент "([^"]*)"$/, function (elementName) {
        elementName = this.helpers.parseElement(elementName);

        var selector = this.selectors.XPATH.Element.byName(elementName.name);
        var xpath = this.by.xpath(selector);
        var that = this;

        return this.currentView.findElements(xpath)
            .then(function (elements) {
                if (elements.length < elementName.index + 1) {
                    throw new Error('Элемент не найден');
                }
                return elements[elementName.index].isDisplayed();
            })
            .then(function (value) {
                that.assert.equal(value, true);
            });
    });

    this.When(/^я не увижу элемент "([^"]*)"$/, function (elementName) {
        elementName = this.helpers.parseElement(elementName);

        var selector = this.selectors.XPATH.Element.byName(elementName.name);
        var xpath = this.by.xpath(selector);
        var that = this;

        return this.currentView.findElements(xpath)
            .then(function (elements) {
                if (elements.length < elementName.index + 1) {
                    throw new Error('Элемент не найден');
                }
                return elements[elementName.index].isDisplayed();
            })
            .then(function (value) {
                that.assert.equal(value, false);
            });
    });

    this.When(/^я нажму на клавишу "([^"]*)"$/, function (key) {
        var keys = {
            'enter': this.keys.ENTER
        };

        key = keys[key.toLowerCase()];

        if (!key) {
            throw new Error('Неизвестная клавиша');
        }

        return this.driver.switchTo().activeElement()
            .then(function (element) {<commit_msg>UI-2432: Добавить конструкцию "Я не увижу элемент в выпадающем списке кнопок" #resolved<commit_after>'use strict';

var config = require('../support/config.json');

module.exports = function () {
    this.World = require('../support/world.js').World;

    this.Then(/^система отобразит список валидационных сообщений: (.*?)$/, function (messages) {
        var selector = this.selectors.XPATH.Toastr.messages();
        var xpath = this.by.xpath(selector);
        var that = this;

        messages = this._.map(messages.split('", '), function (item) {
            return item
                .replace(/"/g, '')
                .replace(/''/g, '"');
        });

        return this.driver.findElements(xpath).then(function (msgs) {
            that.assert.equal(msgs.length, messages.length, 'Количество сообщений не совпадает');

            return new Promise(function (resolve, reject) {
                msgs.forEach(function (msg, i) {
                    msg.getText().then(function (text) {
                        messages[i] = that.helpers.ignoreDates(text.trim(), messages[i]);

                        var linesActual = text.split('\n');
                        var linesExpected = messages[i].split('\\n');

                        try {
                            var diff = that._.difference(linesActual, linesExpected);

                            if (!that._.isArray(diff)) {
                                diff = [diff];
                            }

                            that.assert.deepEqual(linesActual, linesExpected, 'Не совпали:\n' + diff.join('\n') + '\n');
                        } catch (err) {
                            reject(err);
                        }

                        if (i == msgs.length - 1) {
                            that.driver.executeScript('$("#toast-container").remove();');
                            resolve();
                        }
                    });
                });
            });
        });
    });

    this.Then(/^система не отобразит валидационных сообщений$/, function () {
        var selector = this.selectors.XPATH.Toastr.messages();
        var xpath = this.by.xpath(selector);
        var that = this;

        this.driver.manage().timeouts().implicitlyWait(4500);

        return this.driver.findElements(xpath)
            .then(function (msgs) {
                that.driver.manage().timeouts().implicitlyWait(config.timeouts.main);
                if (msgs.length != 0) {
                    throw new Error('Найдено ' + msgs.length + ' сообщений');
                }
            });
    });

    this.When(/^я увижу элемент "([^"]*)"$/, function (elementName) {
        elementName = this.helpers.parseElement(elementName);

        var selector = this.selectors.XPATH.Element.byName(elementName.name);
        var xpath = this.by.xpath(selector);
        var that = this;

        return this.currentView.findElements(xpath)
            .then(function (elements) {
                if (elements.length < elementName.index + 1) {
                    throw new Error('Элемент не найден');
                }
                return elements[elementName.index].isDisplayed();
            })
            .then(function (value) {
                that.assert.equal(value, true);
            });
    });

    this.When(/^я не увижу элемент "([^"]*)"$/, function (elementName) {
        elementName = this.helpers.parseElement(elementName);

        var selector = this.selectors.XPATH.Element.byName(elementName.name);
        var xpath = this.by.xpath(selector);
        var that = this;

        return this.currentView.findElements(xpath)
            .then(function (elements) {
                if (elements.length < elementName.index + 1) {
                    throw new Error('Элемент не найден');
                }
                return elements[elementName.index].isDisplayed();
            })
            .then(function (value) {
                that.assert.equal(value, false);
            });
    });

    this.When(/^я не увижу кнопку "([^"]*)" в выпадающем списке кнопок "([^"]*)"$/, function (buttonText, popupListText) {
        var selector = this.selectors.XPATH.Button.popupCaption(popupListText);
        var xpath = this.by.xpath(selector);
        var that = this;

        return this.currentView.findElement(xpath)
            .then(function (popupList) {
                return popupList.click();
            })
            .then(function () {
                selector = that.selectors.XPATH.Button.popupItem(buttonText);
                xpath = that.by.xpath(selector);

                return that.driver.findElements(xpath);
            })
            .then(function (elements) {
                if(elements.length == 0) {
                    throw new Error('Кнопки не существует');
                }
                return elements[0].isDisplayed();
            })
            .then(function (value) {
                that.assert.equal(value, false, 'Кнопка видна');
            });
    });

    this.When(/^я нажму на клавишу "([^"]*)"$/, function (key) {
        var keys = {
            'enter': this.keys.ENTER
        };

        key = keys[key.toLowerCase()];

        if (!key) {
            throw new Error('Неизвестная клавиша');
        }

        return this.driver.switchTo().activeElement()
            .then(function (element) {
{'fraction_non_alphanumeric': 0.13681592039800994, 'fraction_numerical': 0.0022802653399668325, 'mean_word_length': 1.5425559947299077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '2133289', 'n_tokens_mistral': 2743, 'n_tokens_neox': 2697, 'n_words': 475}