1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui.appwithinminutes

File WizardTest.java

 

Code metrics

0
103
3
1
295
151
3
0.03
34.33
3
1

Classes

Class Line # Actions
WizardTest 51 103 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.ui.appwithinminutes;
21   
22    import java.util.Arrays;
23   
24    import org.apache.commons.lang.RandomStringUtils;
25    import org.junit.Assert;
26    import org.junit.Before;
27    import org.junit.Test;
28    import org.xwiki.appwithinminutes.test.po.AppWithinMinutesHomePage;
29    import org.xwiki.appwithinminutes.test.po.ApplicationClassEditPage;
30    import org.xwiki.appwithinminutes.test.po.ApplicationCreatePage;
31    import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
32    import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
33    import org.xwiki.appwithinminutes.test.po.ApplicationTemplateProviderEditPage;
34    import org.xwiki.appwithinminutes.test.po.ApplicationsLiveTableElement;
35    import org.xwiki.appwithinminutes.test.po.ClassFieldEditPane;
36    import org.xwiki.appwithinminutes.test.po.EntryEditPage;
37    import org.xwiki.appwithinminutes.test.po.EntryNamePane;
38    import org.xwiki.index.tree.test.po.DocumentPickerModal;
39    import org.xwiki.test.ui.AbstractTest;
40    import org.xwiki.test.ui.browser.IgnoreBrowser;
41    import org.xwiki.test.ui.browser.IgnoreBrowsers;
42    import org.xwiki.test.ui.po.LiveTableElement;
43    import org.xwiki.test.ui.po.PagesLiveTableElement;
44   
45    /**
46    * Tests the App Within Minutes wizard.
47    *
48    * @version $Id: c81867526853ab84453a5788c2c8bc63a51716a8 $
49    * @since 3.3
50    */
 
51    public class WizardTest extends AbstractTest
52    {
53    /**
54    * The first step of the wizard.
55    */
56    private ApplicationCreatePage appCreatePage;
57   
 
58  2 toggle @Before
59    public void setUp()
60    {
61    // Register a simple user, login and go to the App Within Minutes home page.
62  2 String userName = RandomStringUtils.randomAlphanumeric(5);
63  2 String password = RandomStringUtils.randomAlphanumeric(6);
64  2 getUtil().createUserAndLogin(userName, password);
65    // Make sure the application location exists so that we can select it with the location picker.
66  2 getUtil().createPage(Arrays.asList(getClass().getSimpleName(), this.testName.getMethodName()), "WebHome", null,
67    null);
68  2 AppWithinMinutesHomePage appWithinMinutesHomePage = AppWithinMinutesHomePage.gotoPage();
69   
70    // Click the Create Application button.
71  2 appCreatePage = appWithinMinutesHomePage.clickCreateApplication();
72    }
73   
74    /**
75    * Tests the application creation process from start to end.
76    */
 
77  1 toggle @Test
78    @IgnoreBrowsers({
79    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
80    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
81    })
82    public void testCreateApplication()
83    {
84    // Step 1
85    // Set the application location.
86  1 appCreatePage.getLocationPicker().browseDocuments();
87  1 new DocumentPickerModal().selectDocument(getClass().getSimpleName(), this.testName.getMethodName(), "WebHome");
88  1 appCreatePage.getLocationPicker().waitForLocation(
89    Arrays.asList("", getClass().getSimpleName(), this.testName.getMethodName(), ""));
90   
91    // Enter the application name (random name), making sure we also use some special chars.
92    // See XWIKI-11747: Impossible to create new entry with an application having UTF8 chars in its name
93  1 String appName = RandomStringUtils.randomAscii(10) + "\u00E2";
94  1 String[] appPath = new String[] {getClass().getSimpleName(), this.testName.getMethodName(), appName};
95  1 appCreatePage.setApplicationName(appName);
96   
97    // Wait for the preview.
98  1 appCreatePage.waitForApplicationNamePreview();
99   
100    // Move to the next step.
101  1 ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
102   
103    // Step 2
104    // Add a 'Short Text' field.
105  1 ClassFieldEditPane fieldEditPane = classEditPage.addField("Short Text");
106   
107    // Set the field pretty name and default value
108  1 fieldEditPane.setPrettyName("City Name");
109  1 fieldEditPane.setDefaultValue("Paris");
110   
111    // Move to the next step.
112  1 ApplicationTemplateProviderEditPage templateProviderEditPage = classEditPage.clickNextStep();
113   
114    // Move back to the second step.
115  1 classEditPage = templateProviderEditPage.clickPreviousStep();
116   
117    // Open the configuration panel and set the field name
118  1 fieldEditPane = new ClassFieldEditPane("shortText1");
119  1 fieldEditPane.openConfigPanel();
120  1 fieldEditPane.setName("cityName");
121   
122    // Move to the next step.
123  1 templateProviderEditPage = classEditPage.clickNextStep();
124   
125    // Step 3
126  1 templateProviderEditPage.setIcon("worl");
127  1 templateProviderEditPage.setDescription("A city page");
128   
129    // Move to the next step.
130  1 ApplicationHomeEditPage homeEditPage = templateProviderEditPage.clickNextStep().waitUntilPageIsLoaded();
131   
132    // Step 4
133    // Enter the application description.
134  1 String appDescription = "Simple application to manage data about various cities";
135  1 homeEditPage.setDescription(appDescription);
136   
137    // Add the Short Text field from the previous step to the list of columns.
138  1 homeEditPage.addLiveTableColumn("City Name");
139   
140    // Click the finish button which should lead us to the application home page.
141  1 ApplicationHomePage homePage = homeEditPage.clickFinish();
142   
143    // Assert the application description is present.
144  1 Assert.assertTrue(homePage.getContent().contains(appDescription));
145   
146    // Add a new entry.
147  1 String firstEntryName = RandomStringUtils.randomAscii(6);
148  1 EntryNamePane entryNamePane = homePage.clickAddNewEntry();
149  1 entryNamePane.setName(firstEntryName);
150  1 EntryEditPage entryEditPage = entryNamePane.clickAdd();
151   
152    // Assert the pretty name and the default value of the Short Text field.
153    // Apparently WebElement#getText() takes into account the text-transform CSS property.
154  1 Assert.assertEquals("CITY NAME", entryEditPage.getLabel("cityName"));
155  1 Assert.assertEquals("Paris", entryEditPage.getValue("cityName"));
156   
157    // Change the field value.
158  1 entryEditPage.setValue("cityName", "London");
159   
160    // Save and go back to the application home page.
161  1 entryEditPage.clickSaveAndView().clickBreadcrumbLink(appName);
162  1 homePage = new ApplicationHomePage();
163   
164    // Assert the entry we have just created is listed in the live table.
165  1 LiveTableElement entriesLiveTable = homePage.getEntriesLiveTable();
166  1 entriesLiveTable.waitUntilReady();
167  1 Assert.assertTrue(entriesLiveTable.hasRow("City Name", "London"));
168   
169    // Assert that only the entry we have just created is listed as child of the application home page. The rest of
170    // the documents (class, template, sheet, preferences) should be marked as hidden.
171  1 PagesLiveTableElement childrenLiveTable = homePage.viewChildren().getLiveTable();
172  1 childrenLiveTable.waitUntilReady();
173  1 Assert.assertEquals(1, childrenLiveTable.getRowCount());
174  1 Assert.assertTrue(childrenLiveTable.hasPageWithTitle(firstEntryName));
175   
176    // Go back to the application home page.
177  1 getDriver().navigate().back();
178   
179    // Click the edit button.
180  1 homePage.edit();
181  1 homeEditPage = new ApplicationHomeEditPage();
182   
183    // Change the application description.
184  1 appDescription = "The best app!";
185  1 homeEditPage.setDescription(appDescription);
186   
187    // Remove one of the live table columns.
188  1 homeEditPage.removeLiveTableColumn("Actions");
189   
190    // Save
191  1 homePage = homeEditPage.clickSaveAndView();
192   
193    // Assert that the application description has changed and that the column has been removed.
194  1 Assert.assertTrue(homePage.getContent().contains(appDescription));
195  1 entriesLiveTable = homePage.getEntriesLiveTable();
196  1 entriesLiveTable.waitUntilReady();
197  1 Assert.assertFalse(entriesLiveTable.hasColumn("Actions"));
198   
199    // Click the link to edit the application.
200  1 classEditPage = homePage.clickEditApplication();
201   
202    // Drag a Number field.
203  1 fieldEditPane = classEditPage.addField("Number");
204   
205    // Set the field pretty name.
206  1 fieldEditPane.setPrettyName("Population Size");
207   
208    // Fast forward.
209  1 homeEditPage = classEditPage.clickNextStep().clickNextStep();
210    // Just wait for the WYSIWYG editor (which is used for setting the application description) to load so that the
211    // page layout is stable before we click on the Finish button.
212  1 homeEditPage.setDescription(appDescription);
213  1 homePage = homeEditPage.clickFinish();
214   
215    // Add a new entry.
216  1 String secondEntryName = RandomStringUtils.randomAscii(6);
217  1 entryNamePane = homePage.clickAddNewEntry();
218  1 entryNamePane.setName(secondEntryName);
219  1 entryEditPage = entryNamePane.clickAdd();
220   
221    // Assert the new field is displayed in the edit sheet (field name was auto-generated).
222    // Apparently WebElement#getText() takes into account the text-transform CSS property.
223  1 Assert.assertEquals("POPULATION SIZE", entryEditPage.getLabel("number1"));
224   
225    // Save and go back to the application home page.
226  1 entryEditPage.clickSaveAndView().clickBreadcrumbLink(appName);
227  1 homePage = new ApplicationHomePage();
228   
229    // Assert both entries are displayed in the live table.
230  1 entriesLiveTable = homePage.getEntriesLiveTable();
231  1 entriesLiveTable.waitUntilReady();
232  1 Assert.assertTrue(entriesLiveTable.hasRow("Page Title", firstEntryName));
233  1 Assert.assertTrue(entriesLiveTable.hasRow("Page Title", secondEntryName));
234   
235    // Go to the App Within Minutes home page.
236  1 AppWithinMinutesHomePage appWithinMinutesHomePage = AppWithinMinutesHomePage.gotoPage();
237   
238    // Assert that the created application is listed in the live table.
239  1 ApplicationsLiveTableElement appsLiveTable = appWithinMinutesHomePage.getAppsLiveTable();
240  1 appsLiveTable.waitUntilReady();
241  1 Assert.assertTrue(appsLiveTable.isApplicationListed(appPath));
242   
243    // Delete the application entries.
244  1 homePage = appsLiveTable.viewApplication(appPath);
245  1 homePage.clickDeleteAllEntries().clickYes();
246    // Verify that the entries live table is empty.
247  1 entriesLiveTable = homePage.getEntriesLiveTable();
248  1 entriesLiveTable.waitUntilReady();
249  1 Assert.assertEquals(0, entriesLiveTable.getRowCount());
250   
251    // Delete the application.
252  1 homePage.clickDeleteApplication().clickYes();
253    // Verify that the application is not listed anymore.
254  1 appsLiveTable = AppWithinMinutesHomePage.gotoPage().getAppsLiveTable();
255  1 appsLiveTable.waitUntilReady();
256  1 Assert.assertFalse(appsLiveTable.isApplicationListed(appPath));
257    }
258   
259    /**
260    * @see XWIKI-7380: Cannot go back from step 2 to step 1
261    */
 
262  1 toggle @Test
263    @IgnoreBrowsers({
264    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
265    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
266    })
267    public void testGoBackToFirstStep()
268    {
269    // Step 1
270  1 String appName = RandomStringUtils.randomAscii(6);
271  1 appCreatePage.setApplicationName(appName);
272  1 appCreatePage.waitForApplicationNamePreview();
273   
274    // Step 2
275  1 ApplicationClassEditPage classEditPage = appCreatePage.clickNextStep();
276  1 classEditPage.addField("Short Text");
277   
278    // Back to Step 1
279  1 appCreatePage = classEditPage.clickPreviousStep();
280  1 appCreatePage.setApplicationName(appName);
281  1 appCreatePage.waitForApplicationNamePreview();
282    // Test that the application wasn't created.
283  1 Assert.assertFalse(appCreatePage.getContent().contains(ApplicationNameTest.APP_NAME_USED_WARNING_MESSAGE));
284   
285    // Step 2 again
286  1 classEditPage = appCreatePage.clickNextStep();
287  1 Assert.assertTrue(classEditPage.getContent().contains(ClassEditorTest.EMPTY_CANVAS_HINT));
288  1 classEditPage.addField("Number");
289   
290    // Step 3 and back to Step 2
291  1 classEditPage = classEditPage.clickNextStep().clickPreviousStep();
292  1 Assert.assertFalse(classEditPage.getContent().contains(ClassEditorTest.EMPTY_CANVAS_HINT));
293  1 Assert.assertFalse(classEditPage.hasPreviousStep());
294    }
295    }