package com.atlassian.stash.internal.web.soy.functions.nav;

import com.atlassian.soy.renderer.JsExpression;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public final class JsNavBuilderTest {

    @Test
    public void testWithParam() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').withParams(test).build()", new JsNavBuilder().withParams(new JsExpression("test")).build().getText());
    }

    @Test
    public void testWithParamAvailable() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').withParams(test).build()", new JsNavBuilder().withParamsIfAvailable(new JsExpression[]{new JsExpression("test")}, 0).build().getText());
        assertEquals("require('bitbucket/util/navbuilder').build()", new JsNavBuilder().withParamsIfAvailable(new JsExpression[]{new JsExpression("test")}, 1).build().getText());
    }

    @Test
    public void testProjectAndRepo() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').project(prj).repo(prj).build()", new JsNavBuilder().project(new JsExpression("prj")).repo(new JsExpression("prj")).build().getText());
    }

    @Test
    public void testAllProjects() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').allProjects().build()", new JsNavBuilder().allProjects().build().getText());
    }

    @Test
    public void testAdmin() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').admin().build()", new JsNavBuilder().admin().build().getText());
    }

    @Test
    public void testBranches() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').branches().build()", new JsNavBuilder().branches().build().getText());
    }

    @Test
    public void testCompare() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').compare().build()", new JsNavBuilder().compare().build().getText());
    }

    @Test
    public void testCommits() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').commits().build()", new JsNavBuilder().commits().build().getText());
    }

    @Test
    public void testTags() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').tags().build()", new JsNavBuilder().tags().build().getText());
    }

    @Test
    public void testCommit() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').commit(42).build()", new JsNavBuilder().commit(new JsExpression("42")).build().getText());
    }

    @Test
    public void testLogin() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').login().build()", new JsNavBuilder().login().build().getText());
    }

    @Test
    public void testLogout() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').logout().build()", new JsNavBuilder().logout().build().getText());
    }

    @Test
    public void testUsers() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').users().build()", new JsNavBuilder().users().build().getText());
    }

    @Test
    public void testUserView() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').users().view(name).build()", new JsNavBuilder().users().view(new JsExpression("name")).build().getText());
    }

    @Test
    public void testGroups() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').groups().build()", new JsNavBuilder().groups().build().getText());
    }

    @Test
    public void testGroupView() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').groups().view(name).build()", new JsNavBuilder().groups().view(new JsExpression("name")).build().getText());
    }

    @Test
    public void testPullRequestDiff() throws Exception {
        assertEquals("require('bitbucket/util/navbuilder').pullRequest(pr).diff().build()", new JsNavBuilder().pullRequest(new JsExpression("pr")).diff().build().getText());
    }
}
