This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 19fb4113a62bd82437754d7487576a33738e52e9 Author: juanpablo <[email protected]> AuthorDate: Sat Nov 7 18:39:59 2020 +0100 added functional tests for page edits --- .../src/main/java/org/apache/wiki/its/EditIT.java | 53 +++++++++++++++ .../apache/wiki/pages/haddock/EditWikiPage.java | 78 ++++++++++++++++++++++ 2 files changed, 131 insertions(+) diff --git a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/EditIT.java b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/EditIT.java new file mode 100644 index 0000000..7f5c302 --- /dev/null +++ b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/its/EditIT.java @@ -0,0 +1,53 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.its; + +import com.codeborne.selenide.junit5.ScreenShooterExtension; +import org.apache.wiki.pages.haddock.EditWikiPage; +import org.apache.wiki.pages.haddock.ReadWikiPage; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Edit-related tests for Apache JSPWiki + */ +@ExtendWith( ScreenShooterExtension.class ) +public class EditIT { + + @Test + void createPageAndTestEditPermissions() { + final String pageName = "RandomPage" + System.currentTimeMillis(); + + final ReadWikiPage randomPage = EditWikiPage.open( pageName ) + .saveText( "random page [{ALLOW edit janne}] [{ALLOW view All}]", "random page" ); + Assertions.assertEquals( pageName, randomPage.wikiTitle() ); + Assertions.assertEquals( "random page", randomPage.wikiPageContent() ); + + final ReadWikiPage requiresJannesAccess = randomPage.hoverLoginArea().clickOnLogin().performLogin(); + requiresJannesAccess.editPage().saveText( "random page [{ALLOW edit janne}]", "random page" ); + Assertions.assertEquals( pageName, requiresJannesAccess.wikiTitle() ); + Assertions.assertEquals( "random page", requiresJannesAccess.wikiPageContent() ); + + requiresJannesAccess.hoverLoginArea().logout(); + Assertions.assertEquals( "Main", requiresJannesAccess.wikiTitle() ); // no access for anonymous user, so redirected to main + Assertions.assertNotEquals( "random page", randomPage.wikiPageContent() ); + } + +} diff --git a/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/pages/haddock/EditWikiPage.java b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/pages/haddock/EditWikiPage.java new file mode 100644 index 0000000..89d6c29 --- /dev/null +++ b/jspwiki-it-tests/jspwiki-selenide-tests/src/main/java/org/apache/wiki/pages/haddock/EditWikiPage.java @@ -0,0 +1,78 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.pages.haddock; + +import com.codeborne.selenide.Condition; +import com.codeborne.selenide.Selenide; +import org.apache.wiki.pages.Page; +import org.openqa.selenium.By; + +/** + * Actions available on the Edit page. + */ +public class EditWikiPage implements HaddockPage { + + private static final String EDIT_TEXTAREA = "textarea.editor.form-control.snipeable"; + + /** + * Open a given page for edition. + * + * @param pageName Wiki page name to Edit. + * @return {@link EditWikiPage} instance, to allow chaining of actions. + */ + public static EditWikiPage open( final String pageName ) { + return Page.withUrl( Page.baseUrl() + "/Edit.jsp?page=" + pageName ).openAs( new EditWikiPage() ); + } + + /** + * Press the cancel button and disacrd page Edit. + * + * @return {@link ReadWikiPage} instance, to allow chaining of actions. + */ + public ReadWikiPage cancel() { + Selenide.$( By.name( "cancel" ) ).click(); + return new ReadWikiPage(); + } + + /** + * Edits the page with the given text. Ensures edition is complete by ensuring the preview pane shows the edited text. + * + * @param text text to edit. + * @return {@link ReadWikiPage} instance, to allow chaining of actions. + */ + public ReadWikiPage saveText(final String text ) { + return saveText( text, text ); + } + + /** + * Edits the page with the given text. Ensures edition is complete by ensuring the preview pane shows the preview text. + * + * @param text text text to edit. + * @param preview expected text to hsow up on the preview pane (i.e., page directives on edit pane shouldn't show up here). + * @return {@link ReadWikiPage} instance, to allow chaining of actions. + */ + public ReadWikiPage saveText(final String text, final String preview ) { + Selenide.$( By.cssSelector( EDIT_TEXTAREA ) ).clear(); + Selenide.$( By.cssSelector( EDIT_TEXTAREA ) ).val( text ); + Selenide.$( By.className( "ajaxpreview" ) ).waitUntil( Condition.text( preview ), 1_000L ); + Selenide.$( By.name( "ok" ) ).click(); + return new ReadWikiPage(); + } + +}
