/**
 * Tests KickbackEventHandler
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var KickbackEventHandler_1 = require("../../../src/client/event/KickbackEventHandler");
describe('Handle kickback event', function () {
    [
        {
            label: 'kickback when top and current step is greater than kickback step',
            kb_step: 3,
            current_step: 5,
            top_visited_step: 5,
            expected_nav_called: true,
        },
        {
            label: 'does not kickback when current step is less than the kickback step',
            kb_step: 3,
            current_step: 2,
            top_visited_step: 5,
            expected_nav_called: false,
        },
        {
            label: 'does not kickback when top visited step is less than kickback step',
            kb_step: 5,
            current_step: 4,
            top_visited_step: 4,
            expected_nav_called: false,
        },
        {
            label: 'does not kickback when current step matches the kickback step',
            kb_step: 5,
            current_step: 5,
            top_visited_step: 6,
            expected_nav_called: false,
        },
    ].forEach(function (_a) {
        var label = _a.label, kb_step = _a.kb_step, current_step = _a.current_step, top_visited_step = _a.top_visited_step, expected_nav_called = _a.expected_nav_called;
        it(label, function (done) {
            var _a = createStubs(top_visited_step, current_step), nav = _a.nav, client = _a.client;
            var navigate_to_step_called = false;
            nav.navigateToStep = function (_step_id, _force) {
                navigate_to_step_called = true;
            };
            var sut = new KickbackEventHandler_1.KickbackEventHandler(client);
            sut.handle('kickBack', function () { }, {
                action: 'kickBack',
                stepId: kb_step,
            });
            chai_1.expect(navigate_to_step_called).to.equal(expected_nav_called);
            done();
        });
    });
    [
        {
            label: 'navigates with force when set in event data',
            data: {
                action: 'backBack',
                stepId: 1,
                force: true,
            },
            expected_with_force: true,
        },
        {
            label: 'does not navigate with force when not requested',
            data: {
                action: 'backBack',
                stepId: 1,
                force: false,
            },
            expected_with_force: false,
        },
        {
            label: 'does not navigate with force when omitted from event data',
            data: {
                action: 'backBack',
                stepId: 1,
            },
            expected_with_force: false,
        },
    ].forEach(function (_a) {
        var label = _a.label, data = _a.data, expected_with_force = _a.expected_with_force;
        it(label, function (done) {
            var _a = createStubs(5, 5), nav = _a.nav, client = _a.client;
            var navigate_to_step_called = false;
            var navigate_with_force = false;
            nav.navigateToStep = function (_step_id, force) {
                navigate_to_step_called = true;
                navigate_with_force = force;
            };
            var sut = new KickbackEventHandler_1.KickbackEventHandler(client);
            sut.handle('kickBack', function () { }, data);
            chai_1.expect(navigate_to_step_called).to.be.true;
            chai_1.expect(navigate_with_force).to.equal(expected_with_force);
            done();
        });
    });
});
function createStubClientQuote(top_visited_step, current_step) {
    return {
        getTopVisitedStepId: function () { return top_visited_step; },
        setTopVisitedStepId: function () { },
        getCurrentStepId: function () { return current_step; },
    };
}
function createStubNavigation() {
    return {
        navigateToStep: function (_step_id) { },
        setTopVisitedStepId: function (_step_id) { },
    };
}
function createStubUi() {
    return {
        redrawNav: function () { },
    };
}
function createStubClient(quote, nav, ui) {
    return {
        getQuote: function () { return quote; },
        nav: nav,
        getUi: function () { return ui; },
    };
}
function createStubs(top_visited_step, current_step) {
    var quote = createStubClientQuote(top_visited_step, current_step);
    var nav = createStubNavigation();
    var ui = createStubUi();
    var client = createStubClient(quote, nav, ui);
    return {
        client: client,
        quote: quote,
        nav: nav,
        ui: ui,
    };
}
//# sourceMappingURL=data:application/json;base64, 