generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
164 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,12 +41,15 @@ public InsertSampleDataService(PlayerService playerService, QuestionService ques | |
@Transactional | ||
@EventListener(ApplicationReadyEvent.class) // Uncomment this line to insert sample data on startup | ||
public void insertSampleQuestions() throws InterruptedException, IOException { | ||
if (!playerService.getUserByEmail("[email protected]").isPresent()) { | ||
if (playerService.getUserByEmail("[email protected]").isEmpty()) { | ||
PlayerDto player = new PlayerDto(); | ||
player.setEmail("[email protected]"); | ||
player.setUsername("test"); | ||
player.setPassword("test"); | ||
player.setRoles(new String[]{"ROLE_USER"}); | ||
if (Arrays.asList(environment.getActiveProfiles()).contains("test")) | ||
player.setRoles(new String[]{"ROLE_USER", "ROLE_ADMIN"}); | ||
else | ||
player.setRoles(new String[]{"ROLE_USER"}); | ||
playerService.generateApiKey(playerService.addNewPlayer(player)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.uniovi.steps; | ||
|
||
import com.uniovi.Wiq_IntegrationTests; | ||
import com.uniovi.util.PropertiesExtractor; | ||
import com.uniovi.util.SeleniumUtils; | ||
import io.cucumber.java.en.And; | ||
import io.cucumber.java.en.Then; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import java.util.List; | ||
|
||
public class AdminTasksStep extends Wiq_IntegrationTests { | ||
@Then("I should see the admin zone button") | ||
public void iShouldSeeTheAdminZoneButton() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElements(driver, By.cssSelector("a.btn.btn-primary[href='/player/admin']"), 5); | ||
Assertions.assertEquals(1, elems.size()); | ||
} | ||
|
||
@And("I enter the admin zone") | ||
public void iEnterTheAdminZone() { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElements(driver, By.cssSelector("a.btn.btn-primary[href='/player/admin']"), 5); | ||
elems.get(0).click(); | ||
} | ||
|
||
@And("I should see the message {string}") | ||
public void iShouldSeeTheAdminZone(String message) { | ||
SeleniumUtils.waitLoadElementsBy(driver, "text", p.getString(message, PropertiesExtractor.getSPANISH()), 5); | ||
} | ||
|
||
@Then("I click {string} button") | ||
public void iClickButton(String text) { | ||
List<WebElement> elems; | ||
if (!text.contains(".")) { | ||
elems = SeleniumUtils.waitLoadElementsBy(driver, "id", text, 5); | ||
} else { | ||
elems = SeleniumUtils.waitLoadElementsBy(driver, "free", "//button[contains(text(),'" + p.getString(text, PropertiesExtractor.getSPANISH()) + "')]", 5); | ||
} | ||
elems.get(0).click(); | ||
} | ||
|
||
@And("I should see the modal dialog {string}") | ||
public void iShouldSeeTheModalDialog(String title) { | ||
SeleniumUtils.waitLoadElementsBy(driver, "text", p.getString(title, PropertiesExtractor.getSPANISH()), 5); | ||
} | ||
|
||
@And("I fill in the new password {string}") | ||
public void iFillInTheNewPassword(String pass) { | ||
WebElement password = driver.findElement(By.id("changePasswordInput")); | ||
password.click(); | ||
password.clear(); | ||
password.sendKeys(pass); | ||
} | ||
|
||
@And("I wait until modal dialog is closed") | ||
public void iWaitUntilModalDialogIsClosed() { | ||
SeleniumUtils.waitInvisibleElement(driver, By.id("changePasswordAdminModal"), 5); | ||
SeleniumUtils.waitInvisibleElement(driver, By.cssSelector(".modal-backdrop.fade"), 5); | ||
} | ||
|
||
@Then("I fill in the new role {string}") | ||
public void iFillInTheNewRole(String role) { | ||
WebElement password = driver.findElement(By.id("newRole")); | ||
password.click(); | ||
password.clear(); | ||
password.sendKeys(role); | ||
} | ||
|
||
@And("I see the text {string}") | ||
public void iSeeTheText(String text) { | ||
SeleniumUtils.waitLoadElementsBy(driver, "text", text, 5); | ||
} | ||
|
||
@And("I click {string} button for user {string}") | ||
public void iClickButtonForUser(String btn, String user) { | ||
List<WebElement> elems = SeleniumUtils.waitLoadElements(driver, By.cssSelector("button[data-bs-username='"+ user +"']"), 5).stream() | ||
.filter(e -> e.getText().equals(p.getString(btn, PropertiesExtractor.getSPANISH()))).toList(); | ||
elems.get(0).click(); | ||
} | ||
|
||
@Then("I should not see the text {string}") | ||
public void iShouldNotSeeTheText(String text) { | ||
SeleniumUtils.waitInvisibleElement(driver, By.xpath("//*[contains(text(),'" + text + "')]"), 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
Feature: I do admin tasks | ||
Scenario: I can see the admin tasks | ||
Given I am in the home page | ||
When I click the login button | ||
And I fill in the form with valid data email: "test" password: "test" | ||
And I press the login button | ||
Then I should see the admin zone button | ||
And I enter the admin zone | ||
And I should see the message "navbar.section.admin" | ||
|
||
Scenario: I change user password | ||
Given I am in the home page | ||
When I click the login button | ||
And I fill in the form with valid data email: "test" password: "test" | ||
And I press the login button | ||
And I enter the admin zone | ||
And I should see the message "navbar.section.admin" | ||
And I click "user.details" button | ||
And I click "admin.changepassword" button | ||
And I should see the modal dialog "modal.password.title" | ||
And I fill in the new password "1234" | ||
And I click "changePasswordConfirm" button | ||
Then I wait until modal dialog is closed | ||
And I logout | ||
And I fill in the form with valid data email: "test" password: "1234" | ||
And I press the login button | ||
And I should see the admin zone button | ||
|
||
Scenario: I add a role to user | ||
Given I am in the home page | ||
When I click the login button | ||
And I fill in the form with valid data email: "test" password: "test" | ||
And I press the login button | ||
And I enter the admin zone | ||
And I should see the message "navbar.section.admin" | ||
And I click "user.details" button | ||
And I click "admin.changeroles" button | ||
And I should see the modal dialog "admin.roles.change" | ||
Then I fill in the new role "ROLE_CUCUMBER" | ||
And I click "changeRolesConfirm" button | ||
And I wait until modal dialog is closed | ||
And I see the text "ROLE_CUCUMBER" | ||
|
||
Scenario: A user signs up and I delete it | ||
Given I am not registered or logged in | ||
And I am on the register page | ||
When I fill in the form with valid data username: "user1" email: "[email protected]" password: "password" password_confirmation: "password" | ||
And I press the register button | ||
Then I should see the profile page | ||
And I logout | ||
And I fill in the form with valid data email: "test" password: "test" | ||
And I press the login button | ||
And I enter the admin zone | ||
And I should see the message "navbar.section.admin" | ||
When I click "user.details" button for user "user1" | ||
And I click "admin.user.delete" button for user "user1" | ||
And I should see the modal dialog "admin.user.delete.title" | ||
And I click "deleteModalConfirm" button | ||
Then I should not see the text "user1" |