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

HOTFIX: Prevent sharing of locked samples #1403

Merged
merged 11 commits into from
Nov 4, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export default function LockedSamplesList({ locked }) {
sampleId={sample.id}
projectId={sample.projectId}
>
<Button>{sample.sampleName || sample.name}</Button>
<Button className="t-locked-name">
{sample.sampleName || sample.name}
</Button>
</SampleDetailViewer>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,27 +621,7 @@ public void gotToPreviousTablePage() {

public boolean isMessageDisplayed(String message) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(4));
WebElement notification = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".ant-message-custom-content.ant-message-error span:nth-child(2)")));
WebElement notification = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("ant-notification-notice-message")));
return wait.until(ExpectedConditions.textToBePresentInElement(notification, message));
}

public boolean isShareWithLockedSamplesWarningDisplayed(int numSamples) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(4));
WebElement notification = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".ant-modal.ant-modal-confirm .ant-modal-confirm-title")));
return wait.until(ExpectedConditions.textToBePresentInElement(notification, numSamples + " samples are locked and cannot be shared:"));
}

public void closeShareWithLockedSamplesWarning() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(4));
WebElement notification = driver.findElement(By.cssSelector(".ant-modal.ant-modal-confirm"));
notification.findElement(By.className("ant-btn-default")).click();
wait.until(ExpectedConditions.invisibilityOf(notification));
}

public void shareSamplesFromLockedWarning() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(4));
WebElement notification = driver.findElement(By.cssSelector(".ant-modal.ant-modal-confirm"));
notification.findElement(By.className("ant-btn-primary")).click();
wait.until(ExpectedConditions.urlContains("/share"));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ca.corefacility.bioinformatics.irida.ria.integration.pages.projects;

import ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -8,9 +9,7 @@

import java.util.List;

import static ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage.waitForTime;

public class ShareSamplesPage {
public class ShareSamplesPage extends AbstractPage {
@FindBy(css = ".t-project-select .ant-select-selection-search-input")
private WebElement shareProjectSelectSearch;

Expand Down Expand Up @@ -74,6 +73,10 @@ public class ShareSamplesPage {
@FindBy(className = "t-field-label")
private List<WebElement> metadataFieldLabels;

public ShareSamplesPage(WebDriver driver) {
super(driver);
}

public static ShareSamplesPage initPage(WebDriver driver) {
return PageFactory.initElements(driver, ShareSamplesPage.class);
}
Expand All @@ -91,6 +94,10 @@ public int getNumberOfSamplesDisplayed() {
return shareSampleListItem.size();
}

public int getNumberOfLockedSamplesDisplayed() {
return driver.findElements(By.className("t-locked-name")).size();
}

public int getNumberOfUnlockedSamples() {
return unlockedSamples.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,6 @@ void testSharingWithLockedSamplesAsManager() {
page.openToolsDropDown();
page.shareSamples();
assertTrue(page.isMessageDisplayed("All samples are locked and cannot be shared."));

page.selectSampleByName(FIRST_SAMPLE_NAME);
page.openToolsDropDown();
page.shareSamples();
assertTrue(page.isShareWithLockedSamplesWarningDisplayed(1));

page.closeShareWithLockedSamplesWarning();
page.openToolsDropDown();
page.shareSamples();
page.shareSamplesFromLockedWarning();
assertTrue(driver().getCurrentUrl().contains("/share"));
}
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package ca.corefacility.bioinformatics.irida.ria.integration.projects;

import org.junit.jupiter.api.Test;

import ca.corefacility.bioinformatics.irida.ria.integration.AbstractIridaUIITChromeDriver;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.LoginPage;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.projects.ProjectSamplesPage;
import ca.corefacility.bioinformatics.irida.ria.integration.pages.projects.ShareSamplesPage;

import com.github.springtestdbunit.annotation.DatabaseSetup;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -119,4 +117,35 @@ public void testShareSamplesAsManager() {
assertEquals(1, shareSamplesPage.numberOfSamplesWithSameNames(),
"There should be one sample listed which exists in the target project with the same name and different identifier");
}

@Test
void testSharingWithALockedSample() {
final String LOCKED_SAMPLE_NAME = "sample5fdgr";

LoginPage.loginAsManager(driver());

// SHARING SINGLE SAMPLE
ProjectSamplesPage samplesPage = ProjectSamplesPage.goToPage(driver(), 1);
samplesPage.selectSampleByName("sample5fg44");
samplesPage.selectSampleByName(LOCKED_SAMPLE_NAME);
samplesPage.shareSamples();

assertFalse(shareSamplesPage.isNextButtonEnabled(), "");
deepsidhu85 marked this conversation as resolved.
Show resolved Hide resolved
shareSamplesPage.searchForProject("3");
assertThat(shareSamplesPage.getProjectSelectText()).contains("ID: 3");
assertTrue(shareSamplesPage.isNextButtonEnabled(), "Next button should be enabled");
shareSamplesPage.searchForProject("project2");
assertTrue(shareSamplesPage.isNextButtonEnabled(), "Next button should be enabled");
shareSamplesPage.gotToNextStep();

assertEquals(1, shareSamplesPage.getNumberOfSamplesDisplayed(), "Should display the one sample");
assertEquals(1, shareSamplesPage.getNumberOfLockedSamplesDisplayed(), "Should have 1 locked sample");
assertTrue(shareSamplesPage.isPreviousButtonEnabled(),
"Since on the second step, the previous button should be enabled");
shareSamplesPage.gotToNextStep();
assertEquals(0, shareSamplesPage.getNumberOfSharedMetadataEntries(), "Should have no fields to share");
shareSamplesPage.submitShareRequest();
assertTrue(shareSamplesPage.isShareSingleSuccessDisplayed(), "Success message should be displayed");

}
}