Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the logic of NewVersionTest #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.tle.webtests.test.workflow.rejection;

import static org.testng.Assert.assertEquals;

import static org.testng.Assert.assertTrue;
import org.openqa.selenium.Alert;
import org.openqa.selenium.UnhandledAlertException;
import org.testng.annotations.Test;

import com.tle.webtests.framework.TestInstitution;
import com.tle.webtests.pageobject.searching.ItemAdminPage;
import com.tle.webtests.pageobject.searching.ItemListPage;
Expand All @@ -15,81 +16,111 @@
import com.tle.webtests.pageobject.wizard.WizardPageTab;
import com.tle.webtests.test.AbstractCleanupTest;


@TestInstitution("workflow")
public class NewVersionTest extends AbstractCleanupTest
{
private static final String BACKTICK_PASSWORD = "``````";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are all public static final String, the whitespaces between each line should be removed.


private static final String SORTING = "datemodified";

private static final String ADMIN_USERNAME = "admin";

private static final String FIRST_MODERATOR_USERNAME = "SimpleModerator";

private static final String SECOND_MODERATOR_USERNAME = "SecondStepModerator";

public NewVersionTest()
{
setDeleteCredentials("admin", "``````");
setDeleteCredentials(ADMIN_USERNAME, BACKTICK_PASSWORD );
}

@Test
public void newVersion()
{

// Login as admin user and contribute an item to the collection
logon("admin", "``````");

logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
WizardPageTab wizard = new ContributePage(context).load().openWizard("Move to Live During Moderation");
String itemFullName = context.getFullName("item");
String itemFullName2 = itemFullName + " 2";
wizard.editbox(1, itemFullName);
wizard.save().submit();
saveItem(wizard,1,itemFullName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be space between the parameters.

logout();

// Login as SimpleModerator and moderate the item at the first step.
logon("SimpleModerator", "``````");
logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD);
doModeration( FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName, false );
logout();

TaskListPage taskListPage = new TaskListPage(context).load();
ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName);
assertEquals(modResults.getStepName(itemFullName), "moderation step 1");
modResults.moderate(itemFullName).accept();
//login as admin to validate that we can't create a new version while an item is still under moderation
logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
Boolean alertDisplayed = false;
try {
SearchPage.searchAndView(context, itemFullName).adminTab().newVersion();
}
catch(UnhandledAlertException f){
Alert alert = getContext().getDriver().switchTo().alert();
alert.accept();
alertDisplayed = true;
}
assertTrue( alertDisplayed, "Failed to trigger check of new version not allowed when already version in moderation.");
logout();

// login as the owner of the item and new version it.
logon("admin", "``````");
// Login as the SecondStepModerator and moderate again because this workflow needs moderating twice.
logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD);
doModeration( SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 2", itemFullName, false );
logout();

// Now the item should be in a state where we're allowed to create a new version.
// login as admin and new version it.
logon(ADMIN_USERNAME, BACKTICK_PASSWORD);
wizard = SearchPage.searchAndView(context, itemFullName).adminTab().newVersion();
wizard.editbox(1, itemFullName2);
wizard.save().submit();

// check that there is a version that is live, and one that is
// moderating.
ItemAdminPage adminPage = new ItemAdminPage(context).load();
adminPage.exactQuery(itemFullName);
adminPage.setSort("datemodified");
ItemListPage itemList = adminPage.results();
saveItem(wizard,1,itemFullName2);
// check that there is a version that is live, and one that is moderating.
ItemListPage itemList = getItemList(itemFullName);
assertEquals(itemList.getResultForTitle(itemFullName, 1).getStatus(), "live");
assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "moderating");
logout();

// Login as SimpleModerator and moderate the item at the first step.
logon("SimpleModerator", "``````");

taskListPage = new TaskListPage(context).load();
modResults = taskListPage.exactQuery(itemFullName2);
assertEquals(modResults.getStepName(itemFullName2), "moderation step 1");
modResults.moderate(itemFullName2).accept();

// After moderation, check that the item has gone life after the first
// moderation step
adminPage = new ItemAdminPage(context).load();
adminPage.exactQuery(itemFullName2);
adminPage.setSort("datemodified");
itemList = adminPage.results();
// Login as SimpleModerator and moderate the new version of this item at the first step.
logon(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD);
doModeration(FIRST_MODERATOR_USERNAME, BACKTICK_PASSWORD, "moderation step 1", itemFullName2,false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a constant for "moderation step 1" string, as it is used more than once. Probably step 2 as well, for consistency.

// After moderation, check that the item has gone life after the first moderation step
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo:

has gone life

should be

has gone live

itemList = getItemList(itemFullName2);
assertEquals(itemList.getResultForTitle(itemFullName2, 1).getStatus(), "live");
logout();

// Login as the SecondStepModerator and check that the item is still
// there to moderate, and is still live once moderated from second step.
logon("SecondStepModerator", "``````");
taskListPage = new TaskListPage(context).load();
modResults = taskListPage.exactQuery(itemFullName2);
ModerationView tasksTab = modResults.moderate(itemFullName2);
tasksTab.assignToMe();
tasksTab.accept();
logon(SECOND_MODERATOR_USERNAME, BACKTICK_PASSWORD);
doModeration(SECOND_MODERATOR_USERNAME,BACKTICK_PASSWORD,"", itemFullName2, true);
logout();
}

private void doModeration( String username, String password, String stepName, String itemFullName, Boolean lastModeration ) {
TaskListPage taskListPage = new TaskListPage(context).load();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

username and password are unused. Remove.

ModerateListSearchResults modResults = taskListPage.exactQuery(itemFullName);
if(!lastModeration)
{
assertEquals(modResults.getStepName(itemFullName), stepName );
modResults.moderate(itemFullName).accept();
}
else
{
ModerationView tasksTab = modResults.moderate(itemFullName);
tasksTab.assignToMe();
tasksTab.accept();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this if/else the braces should follow the statement.

Shame we don't have formatting here yet, but we will once we merge this repo in.

}

private ItemListPage getItemList(String itemFullName){
ItemAdminPage adminPage = new ItemAdminPage(context).load();
adminPage.exactQuery(itemFullName);
adminPage.setSort(SORTING);
return adminPage.results();
}

private void saveItem(WizardPageTab wizard, int ctrlNum, String itemFullName){
wizard.editbox(ctrlNum, itemFullName);
wizard.save().submit();
}
}