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

File LiveTableEditorTest.java

 

Code metrics

0
51
5
1
167
100
5
0.1
10.2
5
1

Classes

Class Line # Actions
LiveTableEditorTest 43 51 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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.HashMap;
23    import java.util.Map;
24   
25    import org.junit.Assert;
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.appwithinminutes.test.po.ApplicationHomeEditPage;
30    import org.xwiki.appwithinminutes.test.po.ApplicationHomePage;
31    import org.xwiki.test.ui.AbstractTest;
32    import org.xwiki.test.ui.AdminAuthenticationRule;
33    import org.xwiki.test.ui.browser.IgnoreBrowser;
34    import org.xwiki.test.ui.browser.IgnoreBrowsers;
35    import org.xwiki.test.ui.po.LiveTableElement;
36   
37    /**
38    * Tests the last step of the App Within Minutes wizard.
39    *
40    * @version $Id: 6a336fec0c09d5912be360dea5277456153053e9 $
41    * @since 4.0M1
42    */
 
43    public class LiveTableEditorTest extends AbstractTest
44    {
45    @Rule
46    public AdminAuthenticationRule adminAuthenticationRule = new AdminAuthenticationRule(getUtil());
47   
48    /**
49    * The page being tested.
50    */
51    private ApplicationHomeEditPage editPage;
52   
53    /**
54    * The query string parameters passed to the edit action.
55    */
56    private final Map<String, String> editQueryStringParameters = new HashMap<String, String>();
57   
 
58  4 toggle @Before
59    public void setUp() throws Exception
60    {
61  4 getUtil().rest().deletePage(getTestClassName(), getTestMethodName());
62  4 editQueryStringParameters.put("editor", "inline");
63  4 editQueryStringParameters.put("template", "AppWithinMinutes.LiveTableTemplate");
64  4 editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_class", "XWiki.XWikiUsers");
65  4 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
66  4 editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();
67    }
68   
69    /**
70    * Adds, removes and reorders live table columns.
71    */
 
72  1 toggle @Test
73    @IgnoreBrowsers({
74    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
75    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
76    })
77    public void testManageColumns()
78    {
79  1 editPage.addLiveTableColumn("First Name");
80  1 Assert.assertTrue(editPage.hasLiveTableColumn("First Name"));
81  1 editPage.moveLiveTableColumnBefore("First Name", "Location");
82  1 editPage.removeLiveTableColumn("Page Title");
83  1 Assert.assertFalse(editPage.hasLiveTableColumn("Page Title"));
84  1 LiveTableElement liveTable = ((ApplicationHomePage) editPage.clickSaveAndView()).getEntriesLiveTable();
85  1 liveTable.waitUntilReady();
86    // The column headers aren't translated because we haven't generated the document translation bundle.
87  1 Assert.assertFalse(liveTable.hasColumn("xwikiusers.livetable.doc.title"));
88  1 Assert.assertEquals(0, liveTable.getColumnIndex("xwikiusers.livetable.first_name"));
89  1 Assert.assertEquals(1, liveTable.getColumnIndex("xwikiusers.livetable.doc.location"));
90    }
91   
92    /**
93    * Tests that Save & Continue works fine.
94    */
 
95  1 toggle @Test
96    @IgnoreBrowsers({
97    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
98    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
99    })
100    public void testSaveAndContinue()
101    {
102  1 editPage.setDescription("wait for WYSIWYG to load");
103  1 editPage.clickSaveAndContinue();
104  1 ApplicationHomePage viewPage = editPage.clickCancel();
105  1 LiveTableElement liveTable = viewPage.getEntriesLiveTable();
106  1 liveTable.waitUntilReady();
107    // The column header isn't translated because we haven't generated the document translation bundle.
108  1 Assert.assertTrue(liveTable.hasColumn("xwikiusers.livetable.doc.title"));
109    }
110   
111    /**
112    * Tests how deprecated columns are handled.
113    */
 
114  1 toggle @Test
115    public void testDeprecatedColumns()
116    {
117    // Fake a deprecated column by using a column that doesn't exist.
118  1 editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_columns", "doc.name foo");
119  1 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
120  1 editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();
121   
122  1 Assert.assertTrue(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
123  1 Assert.assertFalse(editPage.isLiveTableColumnDeprecated("Page Name"));
124  1 Assert.assertTrue(editPage.isLiveTableColumnDeprecated("foo"));
125   
126    // Keep deprecated columns.
127  1 editPage.removeAllDeprecatedLiveTableColumns(false);
128  1 Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
129  1 Assert.assertTrue(editPage.isLiveTableColumnDeprecated("foo"));
130  1 ApplicationHomePage viewPage = editPage.clickSaveAndView();
131  1 LiveTableElement liveTable = viewPage.getEntriesLiveTable();
132  1 liveTable.waitUntilReady();
133    // The column header isn't translated because we haven't generated the document translation bundle.
134  1 Assert.assertTrue(liveTable.hasColumn("xwikiusers.livetable.foo"));
135   
136    // Edit again and remove the deprecated column.
137  1 editPage = viewPage.editInline();
138  1 Assert.assertTrue(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
139  1 editPage.removeLiveTableColumn("foo");
140  1 Assert.assertFalse(editPage.hasLiveTableColumn("foo"));
141    // The warning must disappear if we remove the deprecated column.
142  1 Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
143   
144    // Reload and remove all deprecated columns.
145  1 getDriver().navigate().refresh();
146  1 editPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded();
147  1 editPage.removeAllDeprecatedLiveTableColumns(true);
148  1 Assert.assertFalse(editPage.isDeprecatedLiveTableColumnsWarningDisplayed());
149  1 Assert.assertTrue(editPage.hasLiveTableColumn("Page Name"));
150  1 Assert.assertFalse(editPage.hasLiveTableColumn("foo"));
151    }
152   
153    /**
154    * Tests that the live table isn't generated if the list of columns is empty.
155    */
 
156  1 toggle @Test
157    public void testNoColumns()
158    {
159    // Make sure the list of columns is empty.
160  1 editQueryStringParameters.put("AppWithinMinutes.LiveTableClass_0_columns", "");
161  1 getUtil().gotoPage(getTestClassName(), getTestMethodName(), "edit", editQueryStringParameters);
162    // Wait for the page to load before clicking on the save button to be sure the page layout is stable.
163  1 ApplicationHomePage viewPage = new ApplicationHomeEditPage().waitUntilPageIsLoaded().clickSaveAndView();
164  1 Assert.assertFalse(viewPage.hasEntriesLiveTable());
165  1 Assert.assertEquals("", viewPage.editWiki().getContent());
166    }
167    }