<commit_before>var assert = require('assert');
var { URL_PREFIX, ADMIN_USER, TEST_USER } = require('../fixtures.js');
const webUI = require('../web-ui.js');

// TODO: make sure that DB is clear
// mongo openwhyd_test --eval "db.dropDatabase();"

function takeSnapshot() {
    var results = browser.checkDocument(); // http://webdriver.io/guide/services/visual-regression.html
    results.forEach((result) => {
        assert(result.isWithinMisMatchTolerance, 'a difference was find on a snapshot');
    });
}

browser.waitForContent = function(regex, context) {
    return browser.waitUntil(() => regex.test(
        browser.getHTML(context || 'body')),
        5000,
        `${regex.toString()} should be in the page within 5 seconds`
    );
};

before(function() {
    // make sure that openwhyd/whydjs server is tested against the test database
    browser.url(URL_PREFIX + `/login?action=login&email=${encodeURIComponent(ADMIN_USER.email)}&md5=${ADMIN_USER.md5}`);
    browser.url(URL_PREFIX + '/admin/config/config.json');
    var config = JSON.parse(browser.getText('pre')).json;
    assert.equal(config.mongoDbDatabase, 'openwhyd_test');
    browser.url(URL_PREFIX + '/login?action=logout');
});

// reference scenario: https://www.youtube.com/watch?v=aZT8VlTV1YY

describe('landing page page', function() {

    it('should not let visitors access admin endpoints', function () {
        browser.url(URL_PREFIX + '/admin/config/config.json');
        assert(!browser.isExisting('pre'));
    });

    it('should have Openwhyd in its title', function () {
        browser.url(URL_PREFIX);
        var title = browser.getTitle();
        assert(/Openwhyd/.test(title));
    });

    it('should not have changed from previous build', function() {
        browser.url(URL_PREFIX);
        var results = browser.checkDocument(); // http://webdriver.io/guide/services/visual-regression.html
        results.forEach((result) => {
            assert(result.isWithinMisMatchTolerance);
        });
    });<commit_msg>testing: faster test database check (necessary when running acceptance tests against docker container)<commit_after>var assert = require('assert');
var { URL_PREFIX, ADMIN_USER, TEST_USER } = require('../fixtures.js');
const webUI = require('../web-ui.js');

// TODO: make sure that DB is clear
// mongo openwhyd_test --eval "db.dropDatabase();"

function takeSnapshot() {
    var results = browser.checkDocument(); // http://webdriver.io/guide/services/visual-regression.html
    results.forEach((result) => {
        assert(result.isWithinMisMatchTolerance, 'a difference was find on a snapshot');
    });
}

browser.waitForContent = function(regex, context) {
    return browser.waitUntil(() => regex.test(
        browser.getHTML(context || 'body')),
        5000,
        `${regex.toString()} should be in the page within 5 seconds`
    );
};

before(function() {
    // make sure that openwhyd/whydjs server is tested against the test database
    browser.url(URL_PREFIX + `/login?action=login&email=${encodeURIComponent(ADMIN_USER.email)}&md5=${ADMIN_USER.md5}&redirect=/admin/config/config.json`);
    var config = JSON.parse(browser.getText('pre')).json;
    assert.equal(config.mongoDbDatabase, 'openwhyd_test');
    browser.url(URL_PREFIX + '/login?action=logout');
});

// reference scenario: https://www.youtube.com/watch?v=aZT8VlTV1YY

describe('landing page page', function() {

    it('should not let visitors access admin endpoints', function () {
        browser.url(URL_PREFIX + '/admin/config/config.json');
        assert(!browser.isExisting('pre'));
    });

    it('should have Openwhyd in its title', function () {
        browser.url(URL_PREFIX);
        var title = browser.getTitle();
        assert(/Openwhyd/.test(title));
    });

    it('should not have changed from previous build', function() {
        browser.url(URL_PREFIX);
        var results = browser.checkDocument(); // http://webdriver.io/guide/services/visual-regression.html
        results.forEach((result) => {
            assert(result.isWithinMisMatchTolerance);
        });
    });
{'fraction_non_alphanumeric': 0.1523809523809524, 'fraction_numerical': 0.004395604395604396, 'mean_word_length': 3.5867861142217246, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '1771555', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1198, 'n_words': 256}