From 1d8797369d3589061fd939c5230e47e43d8160f9 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Tue, 3 Nov 2020 18:43:13 +0100
Subject: [PATCH] no-jira: selenium test for document element with doc. from
 repository

---
 .../ui/DocumentSelectionController.java       |  1 +
 .../org/olat/selenium/CourseElementTest.java  | 57 +++++++++++++++++++
 .../course/DocumentConfigurationPage.java     | 30 +++++++++-
 3 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/olat/course/nodes/document/ui/DocumentSelectionController.java b/src/main/java/org/olat/course/nodes/document/ui/DocumentSelectionController.java
index 80669d82580..d0b36766ec8 100644
--- a/src/main/java/org/olat/course/nodes/document/ui/DocumentSelectionController.java
+++ b/src/main/java/org/olat/course/nodes/document/ui/DocumentSelectionController.java
@@ -82,6 +82,7 @@ public class DocumentSelectionController extends FormBasicController {
 		formLayout.add(selectCont);
 		selectCourseFolderLink = uifactory.addFormLink("config.select.course.folder", selectCont, "btn btn-default");
 		selectRepositoryEntryLink = uifactory.addFormLink("config.select.repo.entry", selectCont, "btn btn-default");
+		selectRepositoryEntryLink.setElementCssClass("o_sel_doc_select_repository_entry");
 		
 		// Create
 		List<DocTemplate> templates = docTemplates.getTemplates();
diff --git a/src/test/java/org/olat/selenium/CourseElementTest.java b/src/test/java/org/olat/selenium/CourseElementTest.java
index 72bd8041dc1..2cec457ef4b 100644
--- a/src/test/java/org/olat/selenium/CourseElementTest.java
+++ b/src/test/java/org/olat/selenium/CourseElementTest.java
@@ -1333,6 +1333,63 @@ public class CourseElementTest extends Deployments {
 		DocumentPage doc = new DocumentPage(browser);
 		doc.assertDocumentLink(pdfDocumentFile.getName());
 	}
+	
+
+	/**
+	 * An author upload a PDF document as learn resource, after that she creates
+	 * a course with a document course element, selects the PDF in the editor,
+	 * publish the course and go to the course element see if the document is
+	 * there.
+	 * 
+	 * @throws IOException
+	 * @throws URISyntaxException
+	 */
+	@Test
+	@RunAsClient
+	public void courseWithDocumentFromRepository()
+	throws IOException, URISyntaxException {
+						
+		UserVO author = new UserRestClient(deploymentUrl).createAuthor();
+
+		LoginPage loginPage = LoginPage.load(browser, deploymentUrl);
+		loginPage.loginAs(author.getLogin(), author.getPassword());
+		
+		URL pdfDocumentUrl = JunitTestHelper.class.getResource("file_resources/handInTopic1.pdf");
+		File pdfDocumentFile = new File(pdfDocumentUrl.toURI());
+		
+		//create a course
+		String docTitle = "PDF-" + UUID.randomUUID();
+		NavigationPage navBar = NavigationPage.load(browser);
+		navBar
+			.openAuthoringEnvironment()
+			.uploadResource(docTitle, pdfDocumentFile);
+
+		//create a course
+		String courseTitle = "PDFDoc-" + UUID.randomUUID();
+		navBar
+			.openAuthoringEnvironment()
+			.createCourse(courseTitle)
+			.clickToolbarBack();
+		
+		//create a course element of type Test with the test that we create above
+		String nodeTitle = "PDF";
+		CourseEditorPageFragment courseEditor = CoursePageFragment.getCourse(browser)
+			.edit();
+		courseEditor
+			.createNode("document")
+			.nodeTitle(nodeTitle);
+		
+		DocumentConfigurationPage docConfig = new DocumentConfigurationPage(browser);
+		docConfig
+			.selectConfiguration()
+			.selectDocument(docTitle);
+		
+		courseEditor
+			.autoPublish();
+		
+		DocumentPage doc = new DocumentPage(browser);
+		doc.assertDocumentLink(pdfDocumentFile.getName());
+	}
 
 
 	/**
diff --git a/src/test/java/org/olat/selenium/page/course/DocumentConfigurationPage.java b/src/test/java/org/olat/selenium/page/course/DocumentConfigurationPage.java
index 800bd519a66..9f3f7c63845 100644
--- a/src/test/java/org/olat/selenium/page/course/DocumentConfigurationPage.java
+++ b/src/test/java/org/olat/selenium/page/course/DocumentConfigurationPage.java
@@ -48,10 +48,38 @@ public class DocumentConfigurationPage {
 	public DocumentConfigurationPage uploadDocument(File file) {
 		By inputBy = By.xpath("//fieldset[contains(@class,'o_sel_document_settings_upload')]//div[contains(@class,'o_fileinput')]/input[@type='file']");
 		OOGraphene.uploadFile(inputBy, file, browser);
+		return assertOnPreview(file.getName());
+	}
+	
+
+	public DocumentConfigurationPage selectDocument(String name) {
+		By inputBy = By.cssSelector("fieldset.o_sel_document_settings_upload a.o_sel_doc_select_repository_entry");
+		OOGraphene.waitElement(inputBy, browser);
+		browser.findElement(inputBy).click();
+		OOGraphene.waitBusy(browser);
+		OOGraphene.waitModalDialog(browser);
+		
+		//find the row
+		By rowBy = By.xpath("//div[contains(@class,'')]//div[contains(@class,'o_segments_content')]//table[contains(@class,'o_table')]//tr/td/a[text()[contains(.,'" + name + "')]]");
+		OOGraphene.waitElement(rowBy, browser);
+		browser.findElement(rowBy).click();
+		OOGraphene.waitBusy(browser);
+		
+		//confirm
+		By confirmBy = By.xpath("//div[contains(@class,'modal-dialog')]//a[contains(@onclick,'link_0')]");
+		OOGraphene.waitElement(confirmBy, browser);
+		browser.findElement(confirmBy).click();
+		OOGraphene.waitBusy(browser);
 		
-		By previewBy = By.xpath("//div[contains(@class,'o_cnd_document')]/div[contains(@class,'o_cnd_header')]/h4[text()[contains(.,'" + file.getName() + "')]]");
+		return assertOnPreview(name);
+	}
+	
+	public DocumentConfigurationPage assertOnPreview(String name) {
+		By previewBy = By.xpath("//div[contains(@class,'o_cnd_document')]/div[contains(@class,'o_cnd_header')]/h4[text()[contains(.,'" + name + "')]]");
 		OOGraphene.waitElement(previewBy, browser);
 		return this;
 	}
+	
+	
 
 }
-- 
GitLab