package it.com.atlassian.stash.pull.like;

import com.atlassian.webdriver.bitbucket.element.Comment;
import com.atlassian.webdriver.bitbucket.page.PullRequestOverviewPage;
import org.junit.Before;
import org.junit.Test;

import java.util.function.Function;

public class PullRequestGeneralCommentLikeTest extends BasePullRequestCommentLikeTest {

    private final Function<String, Comment> loginAndGetComment = username -> loginAs(username, username,
            PullRequestOverviewPage.class, PROJECT_KEY, REPO_NAME, pullRequestId).getGeneralCommentAt(0);

    @Before
    public void setupGeneralComment() {
        setUp(pr -> pr.addGeneralComment("This is a general comment").jsonPath().getLong("id"));
    }

    @Test
    public void testGeneralCommentAuthorCannotSeeLikeButton() {
        testAuthorCannotSeeLikeButton(loginAndGetComment);
    }

    @Test
    public void testGeneralCommentInfoDialogThreeLikers() {
        testInfoDialogThreeLikers(loginAndGetComment);
    }

    @Test
    public void testGeneralCommentInfoDialogTwoLikers() {
        testInfoDialogTwoLikers(loginAndGetComment);
    }

    @Test
    public void testGeneralCommentLikingFromDeepLink() {
        testLikingFromDeepLink(username -> loginAs(username, username, PullRequestOverviewPage.class, PROJECT_KEY,
                REPO_NAME, pullRequestId, commentId, "like").getGeneralCommentAt(0));
    }

    @Test
    public void testGeneralCommentOnePersonLiking() {
        testOnePersonLiking(loginAndGetComment);
    }

    @Test
    public void testGeneralCommentOnePersonUnliking() {
        testOnePersonUnliking(loginAndGetComment);
    }

    @Test
    public void testGeneralCommentTwoPeopleLiking() {
        testTwoPeopleLiking(loginAndGetComment);
    }
}
