diff --git a/src/main/java/org/olat/modules/lecture/ui/EditLectureBlockController.java b/src/main/java/org/olat/modules/lecture/ui/EditLectureBlockController.java index 85eec406b38e6ac06fb61733bc2616a295c114ad..b6a6810626561c0b428b5166dfd50ba83c951c47 100644 --- a/src/main/java/org/olat/modules/lecture/ui/EditLectureBlockController.java +++ b/src/main/java/org/olat/modules/lecture/ui/EditLectureBlockController.java @@ -174,7 +174,7 @@ public class EditLectureBlockController extends FormBasicController { plannedLecturesEl.setEnabled(!readOnly && plannedLecturesEditable); String[] onValues = new String[]{ "" }; - boolean compulsory = lectureBlock != null && lectureBlock.isCompulsory(); + boolean compulsory = lectureBlock == null || lectureBlock.isCompulsory(); compulsoryEl = uifactory.addCheckboxesVertical("compulsory", "lecture.compulsory", formLayout, onKeys, onValues, 1); compulsoryEl.setEnabled(!readOnly && !lectureManagementManaged && !LectureBlockManagedFlag.isManaged(lectureBlock, LectureBlockManagedFlag.compulsory)); compulsoryEl.addActionListener(FormEvent.ONCHANGE); diff --git a/src/test/java/org/olat/selenium/LecturesTest.java b/src/test/java/org/olat/selenium/LecturesTest.java index 99d45f8ce08cebf8260354444184efe1ef271356..960769a94b83b1603a29a01ca9809beb95c1f131 100644 --- a/src/test/java/org/olat/selenium/LecturesTest.java +++ b/src/test/java/org/olat/selenium/LecturesTest.java @@ -573,4 +573,65 @@ public class LecturesTest extends Deployments { .assertOnParticipantLectureBlocks() .assertOnParticipantLectureBlockAuthorised(author, lectureTitle, title); } + + /** + * An author create a course to use the absence management + * and import some lectures blocks. + * + * @param loginPage + * @throws IOException + * @throws URISyntaxException + */ + @Test + @RunAsClient + public void importLectures(@InitialPage LoginPage loginPage) + throws IOException, URISyntaxException { + UserVO author = new UserRestClient(deploymentUrl).createAuthor(); + + // configure the lectures module + loginPage + .loginAs(author.getLogin(), author.getPassword()) + .resume(); + + //go to authoring + AuthoringEnvPage authoringEnv = navBar + .assertOnNavigationPage() + .openAuthoringEnvironment(); + + String title = "Lecture " + UUID.randomUUID(); + //create course + authoringEnv + .openCreateDropDown() + .clickCreate(ResourceType.course) + .fillCreateForm(title) + .assertOnGeneralTab() + .clickToolbarBack(); + + CoursePageFragment course = new CoursePageFragment(browser); + //enable the lectures + LectureRepositoryAdminPage lecturesAdmin = course + .lecturesAdministration(); + lecturesAdmin + .settings() + .enableLectures() + .overrideDefaultSettings() + .saveSettings(); + + LectureRepositoryAdminListPage lectureList = lecturesAdmin + .lectureList(); + + // import the lecture blocks + lectureList + .importLecturesBlocks() + .importFile("lectures/import_lectures.txt") + .next() + .assertOnNumberOfNewBlocks(3) + .finish(); + + //check the blocks + lectureList + .assertOnLectureBlock("Abschlussparty") + .assertOnLectureBlock("Excel Workshop") + .assertOnLectureBlock("Mathematik Einf"); + } } diff --git a/src/test/java/org/olat/selenium/page/lecture/ImportLecturesBlocksWizard.java b/src/test/java/org/olat/selenium/page/lecture/ImportLecturesBlocksWizard.java new file mode 100644 index 0000000000000000000000000000000000000000..1ff680932ea4226c12f421721defcead54b74367 --- /dev/null +++ b/src/test/java/org/olat/selenium/page/lecture/ImportLecturesBlocksWizard.java @@ -0,0 +1,82 @@ +package org.olat.selenium.page.lecture; + +import java.io.InputStream; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.olat.core.logging.OLog; +import org.olat.core.logging.Tracing; +import org.olat.selenium.page.graphene.OOGraphene; +import org.olat.test.JunitTestHelper; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +/** + * + * Initial date: 15 Oct 2018<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class ImportLecturesBlocksWizard { + + private static final OLog log = Tracing.createLoggerFor(ImportLecturesBlocksWizard.class); + + private final WebDriver browser; + + public ImportLecturesBlocksWizard(WebDriver browser) { + this.browser = browser; + } + + public ImportLecturesBlocksWizard importFile(String filename) { + StringBuilder sb = new StringBuilder(32000); + try(InputStream inStream = JunitTestHelper.class.getResourceAsStream("file_resources/" + filename)) { + String content = IOUtils.toString(inStream, "UTF-8"); + String[] lines = content.split("\r?\n"); + for(String line:lines) { + String[] cols = line.split("\t"); + for(String col:cols) { + sb.append(col).append("\\t"); + } + sb.append("\\n"); + } + } catch(Exception ex) { + log.error("", ex); + } + + By importAreaBy = By.cssSelector(".modal-content .o_wizard_steps_current_content textarea"); + WebElement importAreaEl = browser.findElement(importAreaBy); + OOGraphene.textarea(importAreaEl, sb.toString(), browser); + return this; + } + + public ImportLecturesBlocksWizard assertOnNumberOfNewBlocks(int numOfBlocks) { + By newRowsBy = By.cssSelector("td.o_dnd_label span i.o_icon.o_icon_check"); + OOGraphene.waitElement(newRowsBy, browser); + List<WebElement> newRowsEl = browser.findElements(newRowsBy); + Assert.assertEquals(numOfBlocks, newRowsEl.size()); + return this; + } + + /** + * Next + * @return this + */ + public ImportLecturesBlocksWizard next() { + OOGraphene.nextStep(browser); + return this; + } + + /** + * Finish the wizard + * @return this + */ + public ImportLecturesBlocksWizard finish() { + browser.findElement(OOGraphene.wizardFinishBy).click(); + OOGraphene.waitBusy(browser); + OOGraphene.waitElementDisappears(By.cssSelector(".modal-content .wizard"), 5, browser); + return this; + } + +} diff --git a/src/test/java/org/olat/selenium/page/lecture/LectureRepositoryAdminListPage.java b/src/test/java/org/olat/selenium/page/lecture/LectureRepositoryAdminListPage.java index ecd7d9c6a7ea17e66a15ff55cf6c8d7ccd59f513..e3d9d5953814eac8651ec991014993e9c82e3d3c 100644 --- a/src/test/java/org/olat/selenium/page/lecture/LectureRepositoryAdminListPage.java +++ b/src/test/java/org/olat/selenium/page/lecture/LectureRepositoryAdminListPage.java @@ -31,7 +31,7 @@ import org.openqa.selenium.WebDriver; */ public class LectureRepositoryAdminListPage { - private WebDriver browser; + private final WebDriver browser; public LectureRepositoryAdminListPage(WebDriver browser) { this.browser = browser; @@ -43,6 +43,12 @@ public class LectureRepositoryAdminListPage { return this; } + public LectureRepositoryAdminListPage assertOnLectureBlock(String title) { + By titleBy = By.xpath("//div[contains(@class,'o_table_flexi')]//td[text()[contains(.,'" + title + "')]]"); + OOGraphene.waitElement(titleBy, browser); + return this; + } + public EditLectureBlockPage newLectureBlock() { By addLectureBy = By.cssSelector("div.o_sel_repo_lectures_list a.o_sel_repo_add_lecture"); browser.findElement(addLectureBy).click(); @@ -50,6 +56,15 @@ public class LectureRepositoryAdminListPage { return new EditLectureBlockPage(browser); } + public ImportLecturesBlocksWizard importLecturesBlocks() { + By importLecturesBy = By.cssSelector("div.o_sel_repo_lectures_list a.o_sel_repo_import_lectures"); + browser.findElement(importLecturesBy).click(); + OOGraphene.waitModalDialog(browser); + return new ImportLecturesBlocksWizard(browser); + } + + + } diff --git a/src/test/java/org/olat/test/file_resources/lectures/import_lectures.txt b/src/test/java/org/olat/test/file_resources/lectures/import_lectures.txt new file mode 100644 index 0000000000000000000000000000000000000000..cafcf18d9f2919e14efdbfcdd3e2aeea5928b0fc --- /dev/null +++ b/src/test/java/org/olat/test/file_resources/lectures/import_lectures.txt @@ -0,0 +1,5 @@ +L1 Mathematik Einführung 4 10/8/18 8:00 12:00 yes kanu@cyberiacafe.ch COURSE Zürich, HS76 This is about this and that Make your HP ready Teacher identified via Email address, participants from course + Abschlussparty 2 12/23/18 18:00 21:00:00 no aoi GROUP::Curriculum course group 1 Im Wald Ein schönes Abschlussfest Ein Wichtelgeschenk mitbringen Teacher identified via user name, Participants from a course group named "Samichlaus" + Excel Workshop 8 11/15/18 9:15 17:30 yes kanu@cyberiacafe.ch CURR::Physik Online Learn the basics of Excel Teacher identified via institutional user identifier, participants from a course curriculum element with ID "2018-HS-INFO" + + \ No newline at end of file