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

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

import java.util.function.Function;

public class PullRequestEffectiveDiffFileCommentLikeTest extends BasePullRequestCommentLikeTest {

    private final Function<String, Comment> loginAndGetComment = username -> loginAs(username, username,
            PullRequestEffectiveDiffPage.class, PROJECT_KEY, REPO_NAME, pullRequestId).getFileContent().getComments().get(0);

    @Before
    public void setupFileComment() {
        setUp(pr -> pr.addFileComment("This is a file comment", "Folder/file.txt").jsonPath().getLong("id"));
    }

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

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

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

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

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

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

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