Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #796 from zanata/rhbz1211849-change-slug
Browse files Browse the repository at this point in the history
Rhbz1211849 change slug
  • Loading branch information
Patrick Huang committed May 14, 2015
2 parents 1dd5258 + 549ac4b commit 4995a02
Show file tree
Hide file tree
Showing 42 changed files with 1,060 additions and 312 deletions.
Expand Up @@ -302,7 +302,7 @@ private void waitForLoaders() {
public boolean apply(WebDriver input) {
// Find all elements with class name js-loader, or return []
String script = "return (typeof $ == 'undefined') ? [] : " +
"$('.js-loader')";
"$('.js-loader').toArray()";
@SuppressWarnings("unchecked")
List<WebElement> loaders = (List<WebElement>) getExecutor()
.executeScript(script);
Expand Down
Expand Up @@ -38,7 +38,7 @@
@Slf4j
public class ProjectGeneralTab extends ProjectBasePage {

private By projectIdField = By.id("settings-general-form:slugField");
private By projectIdField = By.id("settings-general-form:slugField:slug");
private By projectNameField = By.id("settings-general-form:nameField:name");
private By descriptionField = By.id("settings-general-form:descriptionField:description");
private By projectTypeList = By.id("project-types");
Expand All @@ -63,6 +63,20 @@ public String getProjectId() {
return readyElement(projectIdField).getAttribute("value");
}

/**
* Enter a new slug for the project. Removes any existing text.
*
* @param projectSlug new project slug
* @return new Project General Settings page
*/
public ProjectGeneralTab enterProjectSlug(String projectSlug) {
log.info("Enter project slug {}", projectSlug);
waitForWebElement(projectIdField).clear();
waitForWebElement(projectIdField).sendKeys(projectSlug);
defocus(projectIdField);
return new ProjectGeneralTab(getDriver());
}

/**
* Enter a new name for the project. Removes any existing text.
*
Expand Down
Expand Up @@ -20,17 +20,40 @@
*/
package org.zanata.page.projectversion.versionsettings;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.zanata.page.projectversion.VersionBasePage;
import lombok.extern.slf4j.Slf4j;

/**
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a>
*/
@Slf4j
public class VersionGeneralTab extends VersionBasePage {
private By versionIdField = By.id("settings-general_form:slugField:slug");
private By updateButton = By.id("settings-general_form:updateButton");

public VersionGeneralTab(WebDriver driver) {
super(driver);
}


public VersionGeneralTab enterVersionID(String newSlug) {
log.info("Enter project version slug {}", newSlug);
waitForWebElement(versionIdField).clear();
waitForWebElement(versionIdField).sendKeys(newSlug);
defocus(versionIdField);
return new VersionGeneralTab(getDriver());
}

public VersionGeneralTab updateVersion() {
log.info("Click Update general settings");
scrollIntoView(waitForWebElement(updateButton));
clickAndCheckErrors(waitForWebElement(updateButton));
return new VersionGeneralTab(getDriver());
}

public String getVersionID() {
return waitForWebElement(versionIdField).getAttribute("value");
}
}
Expand Up @@ -210,4 +210,26 @@ public void changeSourceLinks() throws Exception {
.isEqualTo("http://git.example.com")
.as("The git url is correct");
}

@Feature(summary = "Project slug can be changed and page will redirect to new URL after the change",
tcmsTestPlanIds = 0, tcmsTestCaseIds = 0)
@Test
public void changeProjectSlug() {
ProjectGeneralTab projectGeneralTab = new ProjectWorkFlow()
.goToProjectByName("about fedora")
.gotoSettingsTab()
.gotoSettingsGeneral()
.enterProjectSlug("fedora-reborn")
.updateProject();

projectGeneralTab.reload();
assertThat(projectGeneralTab.getUrl()).contains("/fedora-reborn");
projectGeneralTab = projectGeneralTab
.gotoSettingsTab()
.gotoSettingsGeneral();

assertThat(projectGeneralTab.getProjectId())
.isEqualTo("fedora-reborn")
.as("The project slug is correct");
}
}
@@ -0,0 +1,87 @@
/*
* Copyright 2014, Red Hat, Inc. and individual contributors as indicated by the
* @author tags. See the copyright.txt file in the distribution for a full
* listing of individual contributors.
*
* 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.zanata.feature.projectversion;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.zanata.feature.Feature;
import org.zanata.feature.testharness.TestPlan.DetailedTest;
import org.zanata.feature.testharness.ZanataTestCase;
import org.zanata.page.projectversion.versionsettings.VersionGeneralTab;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.LoginWorkFlow;
import org.zanata.workflow.ProjectWorkFlow;

/**
* /**
* @author Patrick Huang
* <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Category(DetailedTest.class)
public class EditVersionSlugTest extends ZanataTestCase {

@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();

private ZanataRestCaller zanataRestCaller;

@Before
public void before() {
zanataRestCaller = new ZanataRestCaller();
zanataRestCaller.createProjectAndVersion("change-version-slug",
"oldSlug", "file");
}

@Feature(summary = "Project version slug can be changed and page will redirect to new URL",
tcmsTestPlanIds = 0, tcmsTestCaseIds = 0)
@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void changeVersionSlug() throws Exception {
assertThat(new LoginWorkFlow()
.signIn("admin", "admin")
.loggedInAs())
.isEqualTo("admin")
.as("Admin user has logged in");

VersionGeneralTab versionGeneralTab = new ProjectWorkFlow()
.goToProjectByName("change-version-slug")
.gotoVersion("oldSlug")
.gotoSettingsTab()
.gotoSettingsGeneral()
.enterVersionID("newSlug")
.updateVersion();

versionGeneralTab.reload();
assertThat(versionGeneralTab.getUrl()).contains("/newSlug");

versionGeneralTab = versionGeneralTab
.gotoSettingsTab()
.gotoSettingsGeneral();
assertThat(versionGeneralTab.getVersionID())
.isEqualTo("newSlug")
.as("The version slug has been changed");
}
}
Expand Up @@ -42,8 +42,6 @@ public void set(String name, Object value, Document luceneDocument,

addStringField(IndexFieldLabels.PROJECT_FIELD, project.getSlug(),
luceneDocument, luceneOptions);
addStringField(IndexFieldLabels.ITERATION_FIELD, iteration.getSlug(),
luceneDocument, luceneOptions);
addStringField(IndexFieldLabels.DOCUMENT_ID_FIELD, doc.getDocId(),
luceneDocument, luceneOptions);
}
Expand Down
Expand Up @@ -8,7 +8,6 @@
*/
public interface IndexFieldLabels {
public static final String PROJECT_FIELD = "project";
public static final String ITERATION_FIELD = "iteration";
public static final String ENTITY_STATUS = "status";

/**
Expand Down
Expand Up @@ -48,7 +48,7 @@ public abstract class SlugEntityBase extends ModelEntityBase {
private static final long serialVersionUID = -1911540675412928681L;

// TODO PERF @NaturalId(mutable=false) for better criteria caching
@NaturalId
@NaturalId(mutable = true)
@Size(min = 1, max = 40)
@Slug
@NotNull
Expand Down

0 comments on commit 4995a02

Please sign in to comment.