Search in sources :

Example 1 with ClassSheetPage

use of org.xwiki.xclass.test.po.ClassSheetPage in project xwiki-platform by xwiki.

the class ClassSheetTest method createClass.

/**
 * Tests the process of creating a class, its template, its sheet and an instance.
 */
@Test
public void createClass() {
    // TODO: rewrite the test to not rely on the breadcrumb based on parent/child mechanism.
    getUtil().setHierarchyMode("parentchild");
    try {
        String spaceName = getTestClassName();
        String className = RandomStringUtils.randomAlphabetic(5);
        String classDocName = className + "Class";
        String classTitle = className + " Class";
        String pageName = getTestMethodName();
        // Make sure the document doesn't exist.
        getUtil().deletePage(spaceName, pageName);
        // Create the class document.
        DataTypesPage dataTypesPage = DataTypesPage.gotoPage().waitUntilPageIsLoaded();
        String dataTypesPageTitle = dataTypesPage.getDocumentTitle();
        Assert.assertTrue(dataTypesPage.isClassListed("XWiki", "XWikiRights"));
        Assert.assertFalse(dataTypesPage.isClassListed(spaceName, classDocName));
        ClassSheetPage classSheetPage = dataTypesPage.createClass(spaceName, className).waitUntilPageIsLoaded();
        Assert.assertEquals(classTitle, classSheetPage.getDocumentTitle());
        Assert.assertTrue(classSheetPage.hasBreadcrumbContent(dataTypesPageTitle, false));
        // Add a property.
        ClassEditPage classEditor = classSheetPage.clickDefineClassLink();
        classEditor.addProperty("color", "String").setPrettyName("Your favorite color");
        classEditor.clickSaveAndView();
        // Add a new property.
        classEditor = classSheetPage.waitUntilPageIsLoaded().clickEditClassLink();
        classEditor.addProperty("age", "Number").setPrettyName("Your current age");
        classEditor.clickSaveAndView();
        // We have to wait for the page to load because Selenium doesn't do it all the time when we click on Save & View
        // (even if the Save & View button triggers a plain form submit; there must be something with the JavaScript
        // code that is executed on submit that interferes with Selenium).
        classSheetPage.waitUntilPageIsLoaded();
        // Assert that the properties are listed.
        Assert.assertTrue(classSheetPage.hasProperty("color", "Your favorite color", "String"));
        Assert.assertTrue(classSheetPage.hasProperty("age", "Your current age", "Number"));
        // Create and bind a sheet.
        classSheetPage = classSheetPage.clickCreateSheetButton().waitUntilPageIsLoaded().clickBindSheetLink().waitUntilPageIsLoaded();
        ViewPage sheetPage = classSheetPage.clickSheetLink();
        Assert.assertEquals(className + " Sheet", sheetPage.getDocumentTitle());
        sheetPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Create the template.
        classSheetPage = classSheetPage.clickCreateTemplateButton().waitUntilPageIsLoaded().clickAddObjectToTemplateLink().waitUntilPageIsLoaded();
        ViewPage templatePage = classSheetPage.clickTemplateLink();
        Assert.assertEquals(className + " Template", templatePage.getDocumentTitle());
        // The default edit button should take us to the In-line edit mode.
        templatePage.edit();
        InlinePage editPage = new InlinePage();
        editPage.setValue("color", "red");
        editPage.setValue("age", "13");
        editPage.clickSaveAndContinue();
        editPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Create a document based on the class template.
        Assert.assertEquals(spaceName, classSheetPage.getNewPagePicker().getParentInput().getAttribute("value"));
        editPage = classSheetPage.createNewDocument(spaceName, pageName);
        Assert.assertEquals(pageName, editPage.getDocumentTitle());
        Assert.assertEquals("red", editPage.getValue("color"));
        Assert.assertEquals("13", editPage.getValue("age"));
        editPage.setValue("color", "blue");
        editPage.setValue("age", "27");
        ViewPage viewPage = editPage.clickSaveAndView();
        Assert.assertEquals(pageName, viewPage.getDocumentTitle());
        Assert.assertEquals("Your favorite color\nblue\nYour current age\n27", viewPage.getContent());
        viewPage.clickBreadcrumbLink(classTitle);
        classSheetPage.waitUntilPageIsLoaded();
        // Assert the created document is listed.
        Assert.assertTrue(classSheetPage.hasDocument(pageName));
    } finally {
        getUtil().setHierarchyMode("reference");
    }
}
Also used : ClassEditPage(org.xwiki.test.ui.po.editor.ClassEditPage) InlinePage(org.xwiki.test.ui.po.InlinePage) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) ViewPage(org.xwiki.test.ui.po.ViewPage) DataTypesPage(org.xwiki.xclass.test.po.DataTypesPage) AbstractTest(org.xwiki.test.ui.AbstractTest) Test(org.junit.Test)

Example 2 with ClassSheetPage

use of org.xwiki.xclass.test.po.ClassSheetPage in project xwiki-platform by xwiki.

the class ClassEditorTest method testReorderFields.

/**
 * Tests that class fields can be reordered.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testReorderFields() {
    // Add two class fields.
    editor.addField("Date").setPrettyName("Start Date");
    editor.addField("Date").setPrettyName("End Date");
    // Save and edit the class template in in-line edit mode.
    editor.clickSaveAndView();
    new ClassSheetPage().clickTemplateLink().edit();
    // Assert the order of the form fields.
    List<String> fieldNames = new EntryEditPage().getFieldNames();
    Assert.assertEquals("date1", fieldNames.get(0));
    Assert.assertEquals("date2", fieldNames.get(1));
    // Go back to the class editor.
    getDriver().navigate().back();
    getDriver().navigate().back();
    new ViewPage().edit();
    editor = new ApplicationClassEditPage();
    // Change the order of the class fields.
    editor.moveFieldBefore("date2", "date1");
    // Save and edit the class template again.
    editor.clickSaveAndView();
    new ClassSheetPage().clickTemplateLink().edit();
    // Assert the order of the form fields.
    fieldNames = new EntryEditPage().getFieldNames();
    Assert.assertEquals("date2", fieldNames.get(0));
    Assert.assertEquals("date1", fieldNames.get(1));
}
Also used : EntryEditPage(org.xwiki.appwithinminutes.test.po.EntryEditPage) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) ViewPage(org.xwiki.test.ui.po.ViewPage) ApplicationClassEditPage(org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Example 3 with ClassSheetPage

use of org.xwiki.xclass.test.po.ClassSheetPage in project xwiki-platform by xwiki.

the class UserClassFieldTest method testApplicationEntry.

@Test
public void testApplicationEntry() {
    // Create the application class.
    UserPicker userPicker = new UserClassFieldEditPane(editor.addField("User").getName()).getUserPicker();
    userPicker.sendKeys("thomas").waitForSuggestions().sendKeys(Keys.ENTER);
    editor.clickSaveAndView();
    // Create the application entry.
    ClassSheetPage classSheetPage = new ClassSheetPage();
    InlinePage entryEditPage = classSheetPage.createNewDocument(getTestClassName(), getTestMethodName() + "Entry");
    // Assert the initial value.
    String id = getTestClassName() + "." + getTestMethodName() + "_0_user1";
    userPicker = new UserPicker(getDriver().findElement(By.id(id)));
    List<UserElement> selectedUsers = userPicker.waitToLoad().getAcceptedSuggestions();
    Assert.assertEquals(1, selectedUsers.size());
    assertUserElement(selectedUsers.get(0), "Thomas Mortagne");
    Assert.assertEquals("", userPicker.getValue());
    // Change the selected user.
    userPicker.sendKeys("eduard").waitForSuggestions().sendKeys(Keys.ENTER).waitForSuggestionsToFadeOut();
    // We wait for the page to load because Selenium doesn't do it all the time when Save & View is clicked.
    entryEditPage.clickSaveAndView().waitUntilPageIsLoaded();
    // Assert the view mode.
    List<WebElement> users = getDriver().findElements(By.className("user"));
    Assert.assertEquals(1, users.size());
    assertUserElement(new UserElement(users.get(0)), "Eduard Moraru", "Enygma2002");
}
Also used : UserClassFieldEditPane(org.xwiki.appwithinminutes.test.po.UserClassFieldEditPane) InlinePage(org.xwiki.test.ui.po.InlinePage) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) WebElement(org.openqa.selenium.WebElement) UserPicker(org.xwiki.test.ui.po.editor.UserPicker) UserElement(org.xwiki.test.ui.po.editor.UserPicker.UserElement) Test(org.junit.Test)

Example 4 with ClassSheetPage

use of org.xwiki.xclass.test.po.ClassSheetPage in project xwiki-platform by xwiki.

the class ClassEditorTest method testDeleteField.

/**
 * Tests that class fields can be deleted and that documents having objects of that class are updated.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testDeleteField() {
    // Add two fields.
    editor.addField("Boolean").setPrettyName("Available");
    editor.addField("Date").setPrettyName("Day");
    // Save and assert they are present.
    ViewPage classView = editor.clickSaveAndView();
    Assert.assertTrue(classView.getContent().contains("Available (boolean1: Boolean)"));
    Assert.assertTrue(classView.getContent().contains("Day (date1: Date)"));
    // Edit again and delete one of the fields.
    classView.edit();
    new ClassFieldEditPane("boolean1").delete().clickYes();
    // Save and check if the field was removed.
    classView = new ApplicationClassEditPage().clickSaveAndView();
    Assert.assertFalse(classView.getContent().contains("Available (boolean1: Boolean)"));
    Assert.assertTrue(classView.getContent().contains("Day (date1: Date)"));
    // Edit the class template and see if the deleted field is now deprecated.
    ObjectEditPage objectEditor = new ClassSheetPage().clickTemplateLink().editObjects();
    String className = String.format("%s.%s", getTestClassName(), getTestMethodName());
    Assert.assertTrue(objectEditor.isPropertyDeprecated(className, "boolean1"));
    Assert.assertFalse(objectEditor.isPropertyDeprecated(className, "date1"));
}
Also used : LongTextClassFieldEditPane(org.xwiki.appwithinminutes.test.po.LongTextClassFieldEditPane) ClassFieldEditPane(org.xwiki.appwithinminutes.test.po.ClassFieldEditPane) ObjectEditPage(org.xwiki.test.ui.po.editor.ObjectEditPage) ViewPage(org.xwiki.test.ui.po.ViewPage) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) ApplicationClassEditPage(org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Example 5 with ClassSheetPage

use of org.xwiki.xclass.test.po.ClassSheetPage in project xwiki-platform by xwiki.

the class ClassEditorTest method testUpdateSheetAndTemplate.

/**
 * Tests the options to update the class sheet and the class template.
 */
@Test
@IgnoreBrowsers({ @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason = "See https://jira.xwiki.org/browse/XE-1146"), @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason = "See https://jira.xwiki.org/browse/XE-1177") })
public void testUpdateSheetAndTemplate() {
    // The options panel is not displayed if the class template and sheet don't exists.
    Assert.assertFalse(editor.getContent().contains("Update class template"));
    // Add a class field.
    editor.addField("Number");
    // Save and edit again.
    editor.clickSaveAndView().edit();
    editor = new ApplicationClassEditPage();
    // Set default value for the previously added field.
    new ClassFieldEditPane("number1").setDefaultValue("9");
    // Add a new field
    editor.addField("Database List");
    // The options panel should be displayed now.
    editor.setUpdateClassSheet(false);
    // Save and edit the template.
    editor.clickSaveAndView();
    new ClassSheetPage().clickTemplateLink().edit();
    // The sheet should display only the first field.
    EntryEditPage inlineEditor = new EntryEditPage();
    List<String> fieldNames = inlineEditor.getFieldNames();
    Assert.assertEquals(1, fieldNames.size());
    Assert.assertEquals("number1", fieldNames.get(0));
    // Assert the value of the first field. The class template should have been updated.
    Assert.assertEquals("9", inlineEditor.getValue("number1"));
}
Also used : EntryEditPage(org.xwiki.appwithinminutes.test.po.EntryEditPage) LongTextClassFieldEditPane(org.xwiki.appwithinminutes.test.po.LongTextClassFieldEditPane) ClassFieldEditPane(org.xwiki.appwithinminutes.test.po.ClassFieldEditPane) ClassSheetPage(org.xwiki.xclass.test.po.ClassSheetPage) ApplicationClassEditPage(org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage) IgnoreBrowsers(org.xwiki.test.ui.browser.IgnoreBrowsers) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ClassSheetPage (org.xwiki.xclass.test.po.ClassSheetPage)6 ApplicationClassEditPage (org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage)4 IgnoreBrowsers (org.xwiki.test.ui.browser.IgnoreBrowsers)4 ViewPage (org.xwiki.test.ui.po.ViewPage)4 ClassFieldEditPane (org.xwiki.appwithinminutes.test.po.ClassFieldEditPane)3 EntryEditPage (org.xwiki.appwithinminutes.test.po.EntryEditPage)3 LongTextClassFieldEditPane (org.xwiki.appwithinminutes.test.po.LongTextClassFieldEditPane)3 InlinePage (org.xwiki.test.ui.po.InlinePage)2 WebElement (org.openqa.selenium.WebElement)1 UserClassFieldEditPane (org.xwiki.appwithinminutes.test.po.UserClassFieldEditPane)1 AbstractTest (org.xwiki.test.ui.AbstractTest)1 ClassEditPage (org.xwiki.test.ui.po.editor.ClassEditPage)1 ObjectEditPage (org.xwiki.test.ui.po.editor.ObjectEditPage)1 UserPicker (org.xwiki.test.ui.po.editor.UserPicker)1 UserElement (org.xwiki.test.ui.po.editor.UserPicker.UserElement)1 DataTypesPage (org.xwiki.xclass.test.po.DataTypesPage)1