/
ClassSheetIT.java
144 lines (128 loc) · 6.45 KB
/
ClassSheetIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.xclass.test.ui;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.xwiki.test.docker.junit5.TestReference;
import org.xwiki.test.docker.junit5.UITest;
import org.xwiki.test.ui.TestUtils;
import org.xwiki.test.ui.po.InlinePage;
import org.xwiki.test.ui.po.ViewPage;
import org.xwiki.test.ui.po.editor.ClassEditPage;
import org.xwiki.xclass.test.po.ClassSheetPage;
import org.xwiki.xclass.test.po.DataTypesPage;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests the default class sheet (XWiki.ClassSheet).
*
* @version $Id$
* @since 12.4RC1
*/
@UITest
class ClassSheetIT
{
@BeforeAll
void setup(TestUtils setup)
{
setup.loginAsSuperAdmin();
}
/**
* Tests the process of creating a class, its template, its sheet and an instance.
*/
@Test
@Order(1)
void createClass(TestUtils setup, TestReference reference)
{
//TODO: rewrite the test to not rely on the breadcrumb based on parent/child mechanism.
setup.setHierarchyMode("parentchild");
try {
String spaceName = reference.getLastSpaceReference().getName();
String className = reference.getClass().getSimpleName();
String classDocName = className + "Class";
String classTitle = className + " Class";
String pageName = "createClass";
// Make sure the document doesn't exist.
setup.deletePage(spaceName, pageName);
// Create the class document.
DataTypesPage dataTypesPage = DataTypesPage.gotoPage().waitUntilPageIsLoaded();
String dataTypesPageTitle = dataTypesPage.getDocumentTitle();
assertTrue(dataTypesPage.isClassListed("XWiki", "XWikiRights"));
assertFalse(dataTypesPage.isClassListed(spaceName, classDocName));
ClassSheetPage classSheetPage = dataTypesPage.createClass(spaceName, className).waitUntilPageIsLoaded();
assertEquals(classTitle, classSheetPage.getDocumentTitle());
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.
assertTrue(classSheetPage.hasProperty("color", "Your favorite color", "String"));
assertTrue(classSheetPage.hasProperty("age", "Your current age", "Number"));
// Create and bind a sheet.
classSheetPage = classSheetPage.clickCreateSheetButton().waitUntilPageIsLoaded()
.clickBindSheetLink().waitUntilPageIsLoaded();
ViewPage sheetPage = classSheetPage.clickSheetLink();
assertEquals(className + " Sheet", sheetPage.getDocumentTitle());
sheetPage.clickBreadcrumbLink(classTitle);
classSheetPage.waitUntilPageIsLoaded();
// Create the template.
classSheetPage = classSheetPage.clickCreateTemplateButton().waitUntilPageIsLoaded()
.clickAddObjectToTemplateLink().waitUntilPageIsLoaded();
ViewPage templatePage = classSheetPage.clickTemplateLink();
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.
assertEquals(spaceName, classSheetPage.getNewPagePicker().getParentInput().getAttribute("value"));
editPage = classSheetPage.createNewDocument(spaceName, pageName);
assertEquals(pageName, editPage.getDocumentTitle());
assertEquals("red", editPage.getValue("color"));
assertEquals("13", editPage.getValue("age"));
editPage.setValue("color", "blue");
editPage.setValue("age", "27");
ViewPage viewPage = editPage.clickSaveAndView();
assertEquals(pageName, viewPage.getDocumentTitle());
assertEquals("YOUR FAVORITE COLOR\nblue\nYOUR CURRENT AGE\n27", viewPage.getContent());
viewPage.clickBreadcrumbLink(classTitle);
classSheetPage.waitUntilPageIsLoaded();
// Assert the created document is listed.
assertTrue(classSheetPage.hasDocument(pageName));
} finally {
setup.setHierarchyMode("reference");
}
}
}