|
1 | 1 | package com.tle.webtests.test.workflow.rejection; |
2 | 2 |
|
3 | 3 | import static org.testng.Assert.assertEquals; |
4 | | - |
| 4 | +import static org.testng.Assert.assertTrue; |
| 5 | +import org.openqa.selenium.Alert; |
| 6 | +import org.openqa.selenium.UnhandledAlertException; |
5 | 7 | import org.testng.annotations.Test; |
6 | | - |
7 | 8 | import com.tle.webtests.framework.TestInstitution; |
8 | 9 | import com.tle.webtests.pageobject.searching.ItemAdminPage; |
9 | 10 | import com.tle.webtests.pageobject.searching.ItemListPage; |
|
15 | 16 | import com.tle.webtests.pageobject.wizard.WizardPageTab; |
16 | 17 | import com.tle.webtests.test.AbstractCleanupTest; |
17 | 18 |
|
| 19 | + |
18 | 20 | @TestInstitution("workflow") |
19 | 21 | public class NewVersionTest extends AbstractCleanupTest |
20 | 22 | { |
| 23 | + private static final String BACKTICK_PASSWORD = "``````"; |
| 24 | + |
| 25 | + private static final String SORTING = "datemodified"; |
| 26 | + |
| 27 | + private static final String ADMIN_USERNAME = "admin"; |
| 28 | + |
| 29 | + private static final String FIRST_MODERATOR_USERNAME = "SimpleModerator"; |
| 30 | + |
| 31 | + private static final String SECOND_MODERATOR_USERNAME = "SecondStepModerator"; |
21 | 32 |
|
22 | 33 | public NewVersionTest() |
23 | 34 | { |
24 | | - setDeleteCredentials("admin", "``````"); |
| 35 | + setDeleteCredentials(ADMIN_USERNAME, BACKTICK_PASSWORD ); |
25 | 36 | } |
26 | 37 |
|
27 | 38 | @Test |
28 | 39 | public void newVersion() |
29 | 40 | { |
30 | | - |
31 | 41 | // Login as admin user and contribute an item to the collection |
32 | | - logon("admin", "``````"); |
33 | | - |
| 42 | + logon(ADMIN_USERNAME, BACKTICK_PASSWORD); |
34 | 43 | WizardPageTab wizard = new ContributePage(context).load().openWizard("Move to Live During Moderation"); |
35 | 44 | String itemFullName = context.getFullName("item"); |
36 | 45 | String itemFullName2 = itemFullName + " 2"; |
37 | | - wizard.editbox(1, itemFullName); |
38 | | - wizard.save().submit(); |
| 46 | + saveItem(wizard,1,itemFullName); |
39 | 47 | logout(); |
40 | 48 |
|
41 | 49 | // Login as SimpleModerator and moderate the item at the first step. |
42 | | - logon("SimpleModerator", "``````"); |
| 50 | + logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD); |
| 51 | + doModeration( FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName, false ); |
| 52 | + logout(); |
43 | 53 |
|
44 | | - TaskListPage taskListPage = new TaskListPage(context).load(); |
45 | | - ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName); |
46 | | - assertEquals(modResults.getStepName(itemFullName), "moderation step 1"); |
47 | | - modResults.moderate(itemFullName).accept(); |
| 54 | + //login as admin to validate that we can't create a new version while an item is still under moderation |
| 55 | + logon(ADMIN_USERNAME, BACKTICK_PASSWORD); |
| 56 | + Boolean alertDisplayed = false; |
| 57 | + try { |
| 58 | + SearchPage.searchAndView(context, itemFullName).adminTab().newVersion(); |
| 59 | + } |
| 60 | + catch(UnhandledAlertException f){ |
| 61 | + Alert alert = getContext().getDriver().switchTo().alert(); |
| 62 | + alert.accept(); |
| 63 | + alertDisplayed = true; |
| 64 | + } |
| 65 | + assertTrue( alertDisplayed, "Failed to trigger check of new version not allowed when already version in moderation."); |
48 | 66 | logout(); |
49 | 67 |
|
50 | | - // login as the owner of the item and new version it. |
51 | | - logon("admin", "``````"); |
| 68 | + // Login as the SecondStepModerator and moderate again because this workflow needs moderating twice. |
| 69 | + logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD); |
| 70 | + doModeration( SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 2", itemFullName, false ); |
| 71 | + logout(); |
52 | 72 |
|
| 73 | + // Now the item should be in a state where we're allowed to create a new version. |
| 74 | + // login as admin and new version it. |
| 75 | + logon(ADMIN_USERNAME, BACKTICK_PASSWORD); |
53 | 76 | wizard = SearchPage.searchAndView(context, itemFullName).adminTab().newVersion(); |
54 | | - wizard.editbox(1, itemFullName2); |
55 | | - wizard.save().submit(); |
56 | | - |
57 | | - // check that there is a version that is live, and one that is |
58 | | - // moderating. |
59 | | - ItemAdminPage adminPage = new ItemAdminPage(context).load(); |
60 | | - adminPage.exactQuery(itemFullName); |
61 | | - adminPage.setSort("datemodified"); |
62 | | - ItemListPage itemList = adminPage.results(); |
| 77 | + saveItem(wizard,1,itemFullName2); |
| 78 | + // check that there is a version that is live, and one that is moderating. |
| 79 | + ItemListPage itemList = getItemList(itemFullName); |
63 | 80 | assertEquals(itemList.getResultForTitle(itemFullName, 1).getStatus(), "live"); |
64 | 81 | assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "moderating"); |
65 | 82 | logout(); |
66 | 83 |
|
67 | | - // Login as SimpleModerator and moderate the item at the first step. |
68 | | - logon("SimpleModerator", "``````"); |
69 | | - |
70 | | - taskListPage = new TaskListPage(context).load(); |
71 | | - modResults = taskListPage.exactQuery(itemFullName2); |
72 | | - assertEquals(modResults.getStepName(itemFullName2), "moderation step 1"); |
73 | | - modResults.moderate(itemFullName2).accept(); |
74 | | - |
75 | | - // After moderation, check that the item has gone life after the first |
76 | | - // moderation step |
77 | | - adminPage = new ItemAdminPage(context).load(); |
78 | | - adminPage.exactQuery(itemFullName2); |
79 | | - adminPage.setSort("datemodified"); |
80 | | - itemList = adminPage.results(); |
| 84 | + // Login as SimpleModerator and moderate the new version of this item at the first step. |
| 85 | + logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD); |
| 86 | + doModeration(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName2,false); |
| 87 | + // After moderation, check that the item has gone life after the first moderation step |
| 88 | + itemList = getItemList(itemFullName2); |
81 | 89 | assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "live"); |
82 | 90 | logout(); |
83 | 91 |
|
84 | 92 | // Login as the SecondStepModerator and check that the item is still |
85 | 93 | // there to moderate, and is still live once moderated from second step. |
86 | | - logon("SecondStepModerator", "``````"); |
87 | | - taskListPage = new TaskListPage(context).load(); |
88 | | - modResults = taskListPage.exactQuery(itemFullName2); |
89 | | - ModerationView tasksTab = modResults.moderate(itemFullName2); |
90 | | - tasksTab.assignToMe(); |
91 | | - tasksTab.accept(); |
| 94 | + logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD); |
| 95 | + doModeration(SECOND_MODERATOR_USERNAME,BACKTICK_PASSWORD,"", itemFullName2, true); |
92 | 96 | logout(); |
93 | 97 | } |
94 | 98 |
|
| 99 | + private void doModeration( String username, String password, String stepName, String itemFullName, Boolean lastModeration ) { |
| 100 | + TaskListPage taskListPage = new TaskListPage(context).load(); |
| 101 | + ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName); |
| 102 | + if(!lastModeration) |
| 103 | + { |
| 104 | + assertEquals(modResults.getStepName(itemFullName), stepName ); |
| 105 | + modResults.moderate(itemFullName).accept(); |
| 106 | + } |
| 107 | + else |
| 108 | + { |
| 109 | + ModerationView tasksTab = modResults.moderate(itemFullName); |
| 110 | + tasksTab.assignToMe(); |
| 111 | + tasksTab.accept(); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + private ItemListPage getItemList(String itemFullName){ |
| 116 | + ItemAdminPage adminPage = new ItemAdminPage(context).load(); |
| 117 | + adminPage.exactQuery(itemFullName); |
| 118 | + adminPage.setSort(SORTING); |
| 119 | + return adminPage.results(); |
| 120 | + } |
| 121 | + |
| 122 | + private void saveItem(WizardPageTab wizard, int ctrlNum, String itemFullName){ |
| 123 | + wizard.editbox(ctrlNum, itemFullName); |
| 124 | + wizard.save().submit(); |
| 125 | + } |
95 | 126 | } |
0 commit comments