<commit_before>var Login = require('./helpers/pages').login;

describe('blogs', function() {
    'use strict';
    var waitTime = 2 * 1000,
    blogs = [
            {title: 'title: end to end One', description: 'description: end to end one', username: 'admin'},
            {title: 'title: end to end two', description: 'description: end to end two', username: 'admin'},
            {title: 'title: end To end three', description: 'description: end to end three', username: 'admin'}
    ], archived = [
            {title: 'title: end to end closed', description: 'description: end to end closed', username: 'admin'}
    ], searchs = [
            {blogs: [0, 1, 2], search: 'title'},
            {blogs: [0], search: 'One'},
            {blogs: [0, 1, 2], search: 'to'}
    ];

    beforeEach(function() {
        (new Login()).login();
    });

    describe('blogs list:', function() {
        beforeEach(function() {
            element.all(by.css('[href="#/liveblog"]')).get(0).click();
        });
        it('can list blogs', function() {
            var blogsLength = blogs.length;
            expectBlogsLength(blogsLength);
            for (var i = 0; i < blogsLength; i++) {
                expectBlog(blogs[i], i);
            }
        });
        it('can search blogs', function() {
            element(by.css('[ng-click="flags.open = !flags.open"]')).click();
            function checkSearch() {
                expectBlogsLength(search.blogs.length);
                for (var j = 0, countj = search.blogs.length; j < countj; j++) {
                    expectBlog(blogs[search.blogs[j]], j);
                }
            }
            for (var i = 0, counti = searchs.length, search; i < counti; i++) {
                search = searchs[i];
                element(by.model('search')).sendKeys(search.search);
                browser.wait(checkSearch, waitTime, 'correct search result didn\'t appeared in 2 seconds');
            }
        });
        it('can list archived blogs', function() {
            element(by.binding('activeState.text')).click();
            element(by.repeater('state in states').row(1).column('state.text')).click();
            var blogsLength = archived.length;
                expectBlogsLength(blogsLength);
                for (var i = 0; i < blogsLength; i++) {
                    expectBlog(archived[i], i);
                }
            });

    });
    function expectBlogsLength(len) {
         element.all(by.repeater('blog in blogs._items')).then(function(blogs) {
            expect(blogs.length).toBe(len);
        });
    }
    function expectBlog(info, index) {
        index = index || 0;
        expect(element(by.repeater('blog in blogs._items').row(index).column('blog.title')).getText()).toBe(info.title);
        expect(element(by.repeater('blog in blogs._items').row(index).column('blog.description')).getText()).toBe(info.description);
        expect(element(
            by.repeater('blog in blogs._items')
                .row(index)
                .column('blog.original_creator | username'))
                .getText())
        .toBe(info.username);
    }
});
<commit_msg>fix(e2e): refactor tests.<commit_after>var openUrl = require('./helpers/utils').open;

describe('blogs', function() {
    'use strict';
    var waitTime = 2 * 1000;
    var blogs = [
            {title: 'title: end to end One', description: 'description: end to end one', username: 'first name last name'},
            {title: 'title: end to end two', description: 'description: end to end two', username: 'first name last name'},
            {title: 'title: end To end three', description: 'description: end to end three', username: 'first name last name'}
    ], archived = [
            {title: 'title: end to end closed', description: 'description: end to end closed', username: 'first name last name'}
    ], searchs = [
            {blogs: [0, 1, 2], search: 'title'},
            {blogs: [0], search: 'One'},
            {blogs: [0, 1, 2], search: 'to'}
    ];

    beforeEach(openUrl('/#/liveblog'));

    describe('blogs list:', function() {

        it('can list blogs', function() {
            var blogsLength = blogs.length;
            expectBlogsLength(blogsLength);
            for (var i = 0; i < blogsLength; i++) {
                expectBlog(blogs[i], i);
            }
        });
        function searchBlogs(search) {
            element(by.css('[ng-click="flags.open = !flags.open"]')).click();
            element(by.model('search')).clear().sendKeys(search.search);
            var currentUrl;
            browser.getCurrentUrl().then(function(url) {
                    currentUrl = url;
                }
            ).then(function() {
                    browser.wait(function() {
                        return browser.getCurrentUrl().then(function (url) {
                            return url !== currentUrl;
                        });
                    }, waitTime);
                }
            ).then(function () {
                expectBlogsLength(search.blogs.length);
                for (var j = 0, countj = search.blogs.length; j < countj; j++) {
                    expectBlog(blogs[search.blogs[j]], j);
                }
            });
        }
        it('can search all blogs', function() {
            searchBlogs(searchs[0]);
        });
        it('can search just one blog', function() {
            searchBlogs(searchs[1]);
        });
        it('can search case insensitive blogs', function() {
            searchBlogs(searchs[2]);
        });

        it('can list archived blogs', function() {
            element(by.binding('activeState.text')).click();
            element(by.repeater('state in states').row(1).column('state.text')).click();
            var blogsLength = archived.length;
            expectBlogsLength(blogsLength);
            for (var i = 0; i < blogsLength; i++) {
                expectBlog(archived[i], i);
            }
        });
    });
    function expectBlogsLength(len) {
        expect(element.all(by.repeater('blog in blogs._items')).count()).toEqual(len);
    }
    function expectBlog(blog, index) {
        index = index || 0;
        expect(element(by.repeater('blog in blogs._items').row(index).column('blog.title')).getText()).toBe(blog.title);
        expect(element(by.repeater('blog in blogs._items').row(index).column('blog.description')).getText()).toBe(blog.description);
        expect(element(
            by.repeater('blog in blogs._items')
                .row(index)
                .column('blog.original_creator | username'))
                .getText())
        .toBe(blog.username);
    }
});

{'fraction_non_alphanumeric': 0.15692168946339996, 'fraction_numerical': 0.006162633398466857, 'mean_word_length': 1.9705357142857143, 'pattern_counts': {'":': 0, '<': 10, '<?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': '1425001', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1809, 'n_words': 425}