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

import com.atlassian.bitbucket.content.DiffSegmentType;
import com.atlassian.webdriver.bitbucket.element.Comment;
import com.atlassian.webdriver.bitbucket.page.PullRequestCommitDiffPage;
import org.junit.Before;
import org.junit.Test;

import java.util.function.Function;

public class PullRequestCommitDiffInlineCommentLikeTest extends BasePullRequestCommentLikeTest {

    private static final String COMMIT = "ff851cdafd5c9bda5b19d151c5f638f13c2b2f6e";

    private final Function<String, Comment> loginAndGetComment = username -> loginAs(username, username,
            PullRequestCommitDiffPage.class, PROJECT_KEY, REPO_NAME, pullRequestId, COMMIT).getFileContent()
            .getDiffLines().get(0).getComment(commentId);

    @Before
    public void setupInlineComment() {
        setUp(pr -> pr.addCommitComment(COMMIT, "This is an inline comment", "file.txt", 1, DiffSegmentType.REMOVED)
                .jsonPath().getLong("id"));

    }

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

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

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

    @Test
    public void testCommitDiffInlineCommentLikingFromDeepLink() {
        testLikingFromDeepLink(username -> loginAs(username, username, PullRequestCommitDiffPage.class, PROJECT_KEY,
                REPO_NAME, pullRequestId, "ff851cdafd5c9bda5b19d151c5f638f13c2b2f6e", commentId, "like").getFileContent()
                .getDiffLines().get(0).getComment(commentId));
    }

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

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

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