package rocketboard;

import static org.junit.Assert.assertEquals;

import org.junit.Ignore;
import org.junit.Test;
import org.openqa.selenium.By;

public class AssigneTests extends AbstractRocketboardTests {
	
	@Test
	public void AssignMeCard() throws Exception{
		rocketboardPage.waitingLoading();
		rocketboardPage.createIssue(title, desc, getRandomProject().getName());
		rocketboardPage.waitCreatedIssue(title);
		String idCard = rocketboardPage.getInfo(title, "id");
		rocketboardPage.assignMe(idCard);
		assertEquals((driver.findElement(By.xpath("//*[@id='"+idCard+"']/div[1]/a[1]/img")).isDisplayed()), Boolean.TRUE);
	}
	
	@Test
	@Ignore
	public void UnassignLabel() throws Exception {
		rocketboardPage.waitingLoading();
		rocketboardPage.createIssue(title, desc, getRandomProject().getName());
		String href = rocketboardPage.getInfo(title, "href");
		String idCard = rocketboardPage.getInfo(title, "id");
		rocketboardPage.restAssign(href, "{\"assignee\":\"nayaramoura\"}");
		rocketboardPage.visible(idCard);
		rocketboardPage.alreadyAssignee(idCard);
		String btn1 = driver.findElement(
				By.xpath("//*[@id='" + idCard + "']/div[1]/div/div[2]/div/button[1]")).getText();
		assertEquals(btn1.equals("Unassign"), Boolean.TRUE);
		String btn2 = driver.findElement(
				By.xpath("//*[@id='" + idCard + "']/div[1]/div/div[2]/div/button[2]")).getText();
		assertEquals(btn2.equals("Cancel"), Boolean.TRUE);
	}

	@Test
	@Ignore
	public void CancelUnassignAction() throws Exception {
		String repoCreateIssue = getRandomProject().getName();
		rocketboardPage.waitingLoading();
		rocketboardPage.createIssue(title, desc, repoCreateIssue);
		String href = rocketboardPage.getInfo(title, "href");
		String idCard = rocketboardPage.getInfo(title, "id");
		rocketboardPage.restAssign(href, "{\"assignee\":\"nayaramoura\"}");
		rocketboardPage.visible(idCard);
		rocketboardPage.alreadyAssignee(idCard);
		rocketboardPage.unassignCancel(idCard);
		assertEquals(
				(driver.findElement(By.xpath("//*[@id='" + idCard + "']/div[1]/a[1]/img"))
						.isDisplayed()),
				Boolean.TRUE);
	}

	@Test
	public void ConfirmUnassignAction() throws Exception {
		String repoCreateIssue = getRandomProject().getName();
		rocketboardPage.waitingLoading();
		rocketboardPage.createIssue(title, desc, repoCreateIssue);
		String href = rocketboardPage.getInfo(title, "href");
		String idCard = rocketboardPage.getInfo(title, "id");
		rocketboardPage.restAssign(href, "{\"assignee\":\"nayaramoura\"}");
		rocketboardPage.visible(idCard);
		rocketboardPage.alreadyAssignee(idCard);
		rocketboardPage.unassignConfirm(idCard);
		assertEquals((driver.findElement(By.xpath("//*[@id='"+idCard+"']/div[1]/a[1]/img")).isDisplayed()), Boolean.FALSE);
	}
	
	@Test
	public void UnassignOwnUser() throws Exception{
		rocketboardPage.waitingLoading();
		rocketboardPage.createIssue(title, desc, getRandomProject().getName());
		rocketboardPage.waitCreatedIssue(title);
		String idCard = rocketboardPage.getInfo(title, "id");
		rocketboardPage.assignMe(idCard);
		rocketboardPage.unassignMe(idCard);
		assertEquals((driver.findElement(By.xpath("//*[@id='"+idCard+"']/div[1]/a[1]/img")).isDisplayed()), Boolean.FALSE);
	}
	
	
}
	
	
@@ -202,17 +202,16 @@
 Tests %7B%0A
-%09
 %0A%09@Test%0A
@@ -617,25 +617,24 @@
 n.TRUE);%0A%09%7D%0A
-%09
 %0A%09@Test%0A%09@Ig
@@ -2084,651 +2084,8 @@
 %09%7D%0A%0A
-%09@Test%0A%09public void ConfirmUnassignAction() throws Exception %7B%0A%09%09String repoCreateIssue = getRandomProject().getName();%0A%09%09rocketboardPage.waitingLoading();%0A%09%09rocketboardPage.createIssue(title, desc, repoCreateIssue);%0A%09%09String href = rocketboardPage.getInfo(title, %22href%22);%0A%09%09String idCard = rocketboardPage.getInfo(title, %22id%22);%0A%09%09rocketboardPage.restAssign(href, %22%7B%5C%22assignee%5C%22:%5C%22nayaramoura%5C%22%7D%22);%0A%09%09rocketboardPage.visible(idCard);%0A%09%09rocketboardPage.alreadyAssignee(idCard);%0A%09%09rocketboardPage.unassignConfirm(idCard);%0A%09%09assertEquals((driver.findElement(By.xpath(%22//*%5B@id='%22+idCard+%22'%5D/div%5B1%5D/a%5B1%5D/img%22)).isDisplayed()), Boolean.FALSE);%0A%09%7D%0A%09%0A
 %09@Te
@@ -2544,13 +2544,9 @@
 %0A%09%7D%0A
-%09%0A%09%0A%7D%0A%09%0A%09
+%0A%7D%0A%0A%0A

Remove functional test which remove assignment from other users in issues, it's already checked when user removes assigment from itself in a issue