import AJS from 'aui';
import nav from 'bitbucket/internal/bbui/mirroring-admin/nav-builder';

QUnit.module('mirroring-nav-builder', {
    beforeEach: function() {
        if (!AJS.contextPath) {
            AJS.contextPath = function() {
            };
        }
        sinon.stub(AJS, 'contextPath').returns('');
    },
    afterEach: function() {
        AJS.contextPath.restore();
    },
});

QUnit.test('build relative rest url', function(assert) {
    assert.equal(nav.rest().build(), '/rest');

    assert.equal(
        nav.rest()
            .mirroring()
            .build(), '/rest/mirroring/latest');

    assert.equal(
        nav.rest()
            .path('abc', 'def', 'ghi')
            .build(), '/rest/abc/def/ghi');

    assert.equal(
        nav.rest()
            .mirroring()
            .params({ abc: 'def' })
            .build(), '/rest/mirroring/latest?abc=def');

    assert.equal(
        nav.rest()
            .mirroring()
            .path('mirrorServer', 'someIdHere')
            .params({ abc: 'def' })
            .build(), '/rest/mirroring/latest/mirrorServer/someIdHere?abc=def');

    assert.equal(
        nav.rest()
            .mirroring()
            .panel("id")
            .build(), "/rest/mirroring/latest/mirrorServers/id/webPanels/config");
});
