PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/it/com/atlassian/stash/plugin/inbox/func/InboxTest.java

https://bitbucket.org/pepoirot/stash-inbox-plugin
Java | 143 lines | 115 code | 26 blank | 2 comment | 0 complexity | fe86f246baa95a491f0c9064ad52dc12 MD5 | raw file
Possible License(s): Apache-2.0
  1. package it.com.atlassian.stash.plugin.inbox.func;
  2. import com.atlassian.pageobjects.TestedProductFactory;
  3. import com.atlassian.pageobjects.page.LoginPage;
  4. import com.atlassian.stash.test.PullRequestTestHelper;
  5. import com.atlassian.stash.test.TestContext;
  6. import com.atlassian.stash.user.Permission;
  7. import com.atlassian.webdriver.stash.StashTestedProduct;
  8. import com.atlassian.webdriver.stash.element.PullRequestList;
  9. import com.atlassian.webdriver.stash.page.ProjectListPage;
  10. import com.atlassian.webdriver.stash.page.PullRequestOverviewPage;
  11. import com.atlassian.webdriver.stash.page.PullRequestPage;
  12. import com.atlassian.webdriver.testing.rule.SessionCleanupRule;
  13. import com.atlassian.webdriver.testing.rule.WebDriverScreenshotRule;
  14. import com.atlassian.webdriver.testing.rule.WindowSizeRule;
  15. import it.com.atlassian.stash.plugin.inbox.func.pageobjects.FeatureDiscoveryHelper;
  16. import it.com.atlassian.stash.plugin.inbox.func.pageobjects.InboxDialog;
  17. import it.com.atlassian.stash.plugin.inbox.func.pageobjects.InboxTrigger;
  18. import org.hamcrest.Description;
  19. import org.hamcrest.Matcher;
  20. import org.hamcrest.TypeSafeMatcher;
  21. import org.junit.*;
  22. import org.springframework.core.io.ClassPathResource;
  23. import java.util.List;
  24. import static com.atlassian.pageobjects.elements.query.Poller.waitUntilFalse;
  25. import static com.atlassian.pageobjects.elements.query.Poller.waitUntilTrue;
  26. import static org.hamcrest.Matchers.hasItem;
  27. import static org.hamcrest.Matchers.hasSize;
  28. import static org.junit.Assert.*;
  29. public class InboxTest {
  30. private static final String INBOX_PROJ = "PR_TEST";
  31. private static final String INBOX_REPO = "inbox_repo";
  32. private static final String GIT_PR_ZIP = "git/pull-requests.zip";
  33. private static final String SOURCE_BRANCH = "branch_that_has_same_file_modified_and_moved_src";
  34. private static final String TARGET_BRANCH = "branch_that_has_same_file_modified_and_moved_trgt";
  35. private static final String CREATOR = "pr_creator";
  36. private static final String REVIEWER = "pr_reviewer";
  37. private static final String PR_TITLE = "Some pull request";
  38. private static final StashTestedProduct STASH = TestedProductFactory.create(StashTestedProduct.class);
  39. protected PullRequestTestHelper pullRequest;
  40. @ClassRule
  41. public static TestContext classTestContext = new TestContext();
  42. @Rule
  43. public WindowSizeRule windowSizeRule = new WindowSizeRule();
  44. @Rule
  45. public WebDriverScreenshotRule screenshotRule = new WebDriverScreenshotRule();
  46. @Rule
  47. public TestContext testContext = new TestContext();
  48. @Rule
  49. public SessionCleanupRule cleanupRule = new SessionCleanupRule();
  50. @BeforeClass
  51. public static void setup() throws Exception {
  52. classTestContext
  53. .project(INBOX_PROJ)
  54. .repository(INBOX_PROJ, INBOX_REPO, new ClassPathResource(GIT_PR_ZIP))
  55. .user(CREATOR)
  56. .user(REVIEWER)
  57. .repositoryPermission(INBOX_PROJ, INBOX_REPO, CREATOR, Permission.REPO_WRITE)
  58. .repositoryPermission(INBOX_PROJ, INBOX_REPO, REVIEWER, Permission.REPO_READ);
  59. }
  60. @Before
  61. public void setupPullRequest() {
  62. pullRequest = testContext.pullRequest(new PullRequestTestHelper.Builder(CREATOR, CREATOR, PR_TITLE, "Description",
  63. INBOX_PROJ, INBOX_REPO, SOURCE_BRANCH, INBOX_PROJ, INBOX_REPO, TARGET_BRANCH).reviewers(REVIEWER));
  64. }
  65. @Test
  66. public void testStashInboxAsReviewer() {
  67. STASH.visit(LoginPage.class).login(REVIEWER, REVIEWER, ProjectListPage.class);
  68. PullRequestPage page = STASH.visit(PullRequestOverviewPage.class, INBOX_PROJ, INBOX_REPO, pullRequest.getId());
  69. FeatureDiscoveryHelper featureDiscoveryDialog = STASH.getPageBinder().bind(FeatureDiscoveryHelper.class);
  70. featureDiscoveryDialog.dismissAll();
  71. InboxTrigger inboxTrigger = STASH.getPageBinder().bind(InboxTrigger.class);
  72. waitUntilFalse(inboxTrigger.inboxIsEmpty());
  73. waitUntilTrue(inboxTrigger.isCountVisible());
  74. assertEquals("1", inboxTrigger.getCountText());
  75. InboxDialog inbox = inboxTrigger.open();
  76. assertTrue(inbox.isShowingReviewing());
  77. assertFalse(inbox.isActivePullRequestListEmpty());
  78. List<PullRequestList.Entry> pullRequestList = inbox.getActivePullRequestList().getRows();
  79. assertThat(pullRequestList, hasSize(1));
  80. assertThat(pullRequestList, hasItem(entry(PR_TITLE)));
  81. inbox.switchToCreated();
  82. assertTrue(inbox.isShowingCreated());
  83. assertTrue(inbox.isActivePullRequestListEmpty());
  84. // The inbox obscures the Approve button so needs to be closed
  85. inbox.close();
  86. // Approving/unapproving the pull request should update inbox count
  87. page.getApproveButton().clickButton();
  88. waitUntilTrue(inboxTrigger.inboxIsEmpty());
  89. page.getApproveButton().clickButton();
  90. waitUntilFalse(inboxTrigger.inboxIsEmpty());
  91. }
  92. @Test
  93. public void testStashInboxAsCreator() {
  94. STASH.visit(LoginPage.class).login(CREATOR, CREATOR, ProjectListPage.class);
  95. InboxTrigger inboxTrigger = STASH.getPageBinder().bind(InboxTrigger.class);
  96. waitUntilTrue(inboxTrigger.inboxIsEmpty());
  97. InboxDialog inbox = inboxTrigger.open();
  98. assertTrue(inbox.isShowingReviewing());
  99. assertTrue(inbox.isActivePullRequestListEmpty());
  100. inbox.switchToCreated();
  101. List<PullRequestList.Entry> pullRequestList = inbox.getActivePullRequestList().getRows();
  102. assertThat(pullRequestList, hasSize(1));
  103. assertThat(pullRequestList, hasItem(entry(PR_TITLE)));
  104. }
  105. private Matcher<PullRequestList.Entry> entry(final String title) {
  106. return new TypeSafeMatcher<PullRequestList.Entry>() {
  107. @Override
  108. protected boolean matchesSafely(PullRequestList.Entry entry) {
  109. return title.equals(entry.getTitle());
  110. }
  111. @Override
  112. public void describeTo(Description description) {
  113. description.appendText("a list entry with the title ").appendValue(title);
  114. }
  115. };
  116. }
  117. }