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

File FlamingoThemeTest.java

 

Code metrics

0
73
5
1
205
113
5
0.07
14.6
5
1

Classes

Class Line # Actions
FlamingoThemeTest 46 73 0% 5 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.flamingo.test.ui;
21   
22    import java.util.List;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.administration.test.po.AdministrationPage;
27    import org.xwiki.administration.test.po.PresentationAdministrationSectionPage;
28    import org.xwiki.flamingo.test.po.EditThemePage;
29    import org.xwiki.flamingo.test.po.PreviewBox;
30    import org.xwiki.flamingo.test.po.ThemeApplicationWebHomePage;
31    import org.xwiki.flamingo.test.po.ViewThemePage;
32    import org.xwiki.test.ui.AbstractTest;
33    import org.xwiki.test.ui.SuperAdminAuthenticationRule;
34    import org.xwiki.test.ui.po.ConfirmationPage;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.junit.Assert.assertFalse;
38    import static org.junit.Assert.assertTrue;
39   
40    /**
41    * UI tests for the Flamingo Theme Application.
42    *
43    * @version $Id: 675f55bdd430cebb31b360a3e289fec6a9c506cb $
44    * @since 6.3M1
45    */
 
46    public class FlamingoThemeTest extends AbstractTest
47    {
48    @Rule
49    public SuperAdminAuthenticationRule superAdminAuthenticationRule = new SuperAdminAuthenticationRule(getUtil());
 
50  1 toggle @Test
51    public void editFlamingoTheme() throws Exception
52    {
53    // Go to the presentation section of the administration
54  1 AdministrationPage administrationPage = AdministrationPage.gotoPage();
55  1 PresentationAdministrationSectionPage presentationAdministrationSectionPage =
56    administrationPage.clickPresentationSection();
57   
58    // Select the 'Charcoal' color theme
59  1 presentationAdministrationSectionPage.setColorTheme("Charcoal");
60  1 assertEquals("Charcoal", presentationAdministrationSectionPage.getCurrentColorTheme());
61   
62    // Click on the 'customize' button
63  1 presentationAdministrationSectionPage.clickOnCustomize();
64  1 EditThemePage editThemePage = new EditThemePage();
65   
66    // Wait for the preview to be fully loaded
67  1 assertTrue(editThemePage.isPreviewBoxLoading());
68  1 editThemePage.waitUntilPreviewIsLoaded();
69    // First, disable auto refresh because it slows down the test
70    // (and can even make it fails if the computer is slow)
71  1 editThemePage.setAutoRefresh(false);
72   
73  1 verifyAllVariablesCategoriesArePresent(editThemePage);
74  1 verifyVariablesCategoriesDoesNotDisappear(editThemePage);
75  1 verifyThatPreviewWorks(editThemePage);
76   
77    // We do not have a way top clear the browser's cache with selenium
78    // (see http://stackoverflow.com/questions/19310888/clear-browser-cache-using-selenium-webdriver).
79    // So we cannot ensure that saving an existing theme works.
80    }
81   
 
82  1 toggle private void verifyAllVariablesCategoriesArePresent(EditThemePage editThemePage) throws Exception
83    {
84  1 List<String> categories = editThemePage.getVariableCategories();
85  1 assertEquals(11, categories.size());
86  1 assertTrue(categories.contains("Logos"));
87  1 assertTrue(categories.contains("Base colors"));
88  1 assertTrue(categories.contains("Typography"));
89  1 assertTrue(categories.contains("Tables"));
90  1 assertTrue(categories.contains("Buttons"));
91  1 assertTrue(categories.contains("Navigation Bar"));
92  1 assertTrue(categories.contains("Drop downs"));
93  1 assertTrue(categories.contains("Forms"));
94  1 assertTrue(categories.contains("Panels"));
95  1 assertTrue(categories.contains("Breadcrumb"));
96  1 assertTrue(categories.contains("Advanced"));
97    }
98   
 
99  1 toggle private void verifyVariablesCategoriesDoesNotDisappear(EditThemePage editThemePage) throws Exception
100    {
101    // Because of an incompatibility between PrototypeJS and Bootstrap, the variables categories can disappear
102    // (see: http://jira.xwiki.org/browse/XWIKI-11670).
103    // This test verifies that the bug is still fixed.
104  1 assertEquals(11, editThemePage.getVariableCategories().size());
105    // We click on different categories
106  1 editThemePage.selectVariableCategory("Base colors");
107  1 editThemePage.selectVariableCategory("Typography");
108    // We verify that they are still there
109  1 assertEquals(11, editThemePage.getVariableCategories().size());
110    }
111   
112    /**
113    * @since 6.3M2
114    */
 
115  1 toggle private void verifyThatPreviewWorks(EditThemePage editThemePage) throws Exception
116    {
117    // Verify that the preview is working with the current values
118  1 PreviewBox previewBox = editThemePage.getPreviewBox();
119  1 assertFalse(previewBox.hasError());
120    // Select a variable category and change value
121  1 editThemePage.selectVariableCategory("Base colors");
122  1 editThemePage.setVariableValue("xwiki-page-content-bg", "#ff0000");
123    // Again...
124  1 editThemePage.selectVariableCategory("Typography");
125  1 editThemePage.setVariableValue("font-family-base", "Monospace");
126    // Test that the @lessCode variable is handled too!
127  1 editThemePage.selectVariableCategory("Advanced");
128  1 editThemePage.setTextareaValue("lessCode", ".main{ color: #0000ff; }");
129    // Refresh
130  1 editThemePage.refreshPreview();
131    // Verify that there is still no errors
132  1 assertFalse(previewBox.hasError());
133    // Verify that the modification have been made in the preview
134  1 assertEquals("rgba(255, 0, 0, 1)", previewBox.getPageBackgroundColor());
135  1 assertEquals("monospace", previewBox.getFontFamily());
136    // Test 'lessCode' is correctly handled (since 7.3M1)
137  1 assertEquals("rgba(0, 0, 255, 1)", previewBox.getTextColor());
138    }
139   
140    /**
141    * @since 6.3RC1
142    */
 
143  1 toggle @Test
144    public void createNewTheme() throws Exception
145    {
146    // Go to the presentation section of the administration
147  1 AdministrationPage administrationPage = AdministrationPage.gotoPage();
148  1 PresentationAdministrationSectionPage presentationAdministrationSectionPage =
149    administrationPage.clickPresentationSection();
150   
151    // Click on "manage color theme"
152  1 presentationAdministrationSectionPage.manageColorThemes();
153  1 ThemeApplicationWebHomePage themeApplicationWebHomePage = new ThemeApplicationWebHomePage();
154   
155    // Ensure the current theme is correct
156  1 assertEquals("Charcoal", themeApplicationWebHomePage.getCurrentTheme());
157    // Ensure the other themes are correct
158  1 List<String> otherThemes = themeApplicationWebHomePage.getOtherThemes();
159  1 assertTrue(otherThemes.contains("Marina"));
160  1 assertTrue(otherThemes.contains("Garden"));
161  1 assertTrue(otherThemes.contains("Kitty"));
162  1 assertFalse(otherThemes.contains("Charcoal"));
163   
164    // Create a new theme
165  1 EditThemePage editThemePage = themeApplicationWebHomePage.createNewTheme("Test");
166  1 editThemePage.waitUntilPreviewIsLoaded();
167   
168    // First, disable auto refresh because it slows down the test
169    // (and can even make it fails if the computer is slow)
170  1 editThemePage.setAutoRefresh(false);
171   
172    // Set variables
173  1 editThemePage.selectVariableCategory("Base colors");
174  1 editThemePage.setVariableValue("xwiki-page-content-bg", "#ff0000");
175  1 editThemePage.selectVariableCategory("Typography");
176  1 editThemePage.setVariableValue("font-family-base", "Monospace");
177  1 editThemePage.selectVariableCategory("Advanced");
178    // Insert lessCode too
179  1 editThemePage.setTextareaValue("lessCode", ".main{ color: #0000ff; }");
180    // Save the theme
181  1 editThemePage.clickSaveAndView();
182   
183    // Go back to the theme application
184  1 themeApplicationWebHomePage = ThemeApplicationWebHomePage.gotoPage();
185    // Set the new theme as current
186  1 themeApplicationWebHomePage.useTheme("Test");
187    // Verify that the new theme is used
188  1 assertEquals("Test", themeApplicationWebHomePage.getCurrentTheme());
189    // Look at the values
190  1 assertEquals("rgba(255, 0, 0, 1)", themeApplicationWebHomePage.getPageBackgroundColor());
191  1 assertEquals("monospace", themeApplicationWebHomePage.getFontFamily().toLowerCase());
192    // Test 'lessCode' is correctly handled
193  1 assertEquals("rgba(0, 0, 255, 1)", themeApplicationWebHomePage.getTextColor());
194   
195    // Switch back to Charcoal
196  1 themeApplicationWebHomePage.useTheme("Charcoal");
197   
198    // Remove the theme
199  1 ViewThemePage themePage = themeApplicationWebHomePage.seeTheme("Test");
200  1 themePage.waitUntilPreviewIsLoaded();
201  1 ConfirmationPage confirmationPage = themePage.delete();
202  1 confirmationPage.confirmDeletePage().waitUntilIsTerminated();
203    }
204   
205    }