-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test to ensure permissions are active without login
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 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
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
87 changes: 87 additions & 0 deletions
87
src/test/java/de/focusshift/zeiterfassung/ui/PermissionUIIT.java
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,87 @@ | ||
package de.focusshift.zeiterfassung.ui; | ||
|
||
import com.microsoft.playwright.Page; | ||
import com.microsoft.playwright.Response; | ||
import de.focusshift.zeiterfassung.TestKeycloakContainer; | ||
import de.focusshift.zeiterfassung.TestPostgreSQLContainer; | ||
import de.focusshift.zeiterfassung.ui.extension.UiTest; | ||
import de.focusshift.zeiterfassung.ui.pages.LoginPage; | ||
import de.focusshift.zeiterfassung.ui.pages.NavigationPage; | ||
import de.focusshift.zeiterfassung.ui.pages.UsersPage; | ||
import de.focusshift.zeiterfassung.ui.pages.users.UserPermissionsPage; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
@Testcontainers | ||
@UiTest | ||
class PermissionUIIT { | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@Container | ||
private static final TestPostgreSQLContainer postgre = new TestPostgreSQLContainer(); | ||
@Container | ||
private static final TestKeycloakContainer keycloak = new TestKeycloakContainer(); | ||
|
||
@DynamicPropertySource | ||
static void containerProperties(DynamicPropertyRegistry registry) { | ||
postgre.configureSpringDataSource(registry); | ||
keycloak.configureSpringDataSource(registry); | ||
} | ||
|
||
@Test | ||
void ensurePermissionsAreImmediatelyActiveWithoutNewLogin(Page boss_page) { | ||
|
||
final NavigationPage boss_navigationPage = new NavigationPage(boss_page); | ||
final UsersPage boss_usersPage = new UsersPage(boss_page); | ||
final UserPermissionsPage boss_userPermissionsPage = new UserPermissionsPage(boss_page); | ||
|
||
final String user_username = "Klaus Müller"; | ||
final Page user_page = boss_page.context().browser().newContext().newPage(); | ||
final NavigationPage user_navigationPage = new NavigationPage(user_page); | ||
|
||
login("boss", "secret", boss_page); | ||
|
||
login("user", "secret", user_page); | ||
assertThat(user_navigationPage.usersLink()).not().isAttached(); | ||
|
||
// Boss: add permission to user | ||
boss_navigationPage.goToUsersPage(); | ||
boss_usersPage.selectPerson(user_username); | ||
boss_usersPage.goToPermissionsSettings(); | ||
assertThat(boss_userPermissionsPage.getAllowedToEditPermissionsCheckbox()).not().isChecked(); | ||
boss_userPermissionsPage.getAllowedToEditPermissionsCheckbox().click(); | ||
boss_userPermissionsPage.submit(); | ||
|
||
// User: navigation should be updated | ||
user_page.waitForResponse(Response::ok, user_page::reload); | ||
assertThat(user_navigationPage.usersLink()).isAttached(); | ||
|
||
// Boss: remove permission from user | ||
assertThat(boss_userPermissionsPage.getAllowedToEditPermissionsCheckbox()).isChecked(); | ||
boss_userPermissionsPage.getAllowedToEditPermissionsCheckbox().click(); | ||
boss_userPermissionsPage.submit(); | ||
|
||
// User: navigation should be updated | ||
user_page.waitForResponse(Response::ok, user_page::reload); | ||
assertThat(user_navigationPage.usersLink()).not().isAttached(); | ||
|
||
user_navigationPage.logout(); | ||
boss_navigationPage.logout(); | ||
} | ||
|
||
private void login(String username, String password, Page page) { | ||
page.navigate("http://localhost:" + port + "/oauth2/authorization/keycloak"); | ||
new LoginPage(page).login(new LoginPage.Credentials(username, password)); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/test/java/de/focusshift/zeiterfassung/ui/pages/users/UserPermissionsPage.java
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,26 @@ | ||
package de.focusshift.zeiterfassung.ui.pages.users; | ||
|
||
import com.microsoft.playwright.Locator; | ||
import com.microsoft.playwright.Page; | ||
import com.microsoft.playwright.Response; | ||
|
||
import static com.microsoft.playwright.options.LoadState.DOMCONTENTLOADED; | ||
|
||
public class UserPermissionsPage { | ||
|
||
private final Page page; | ||
|
||
public UserPermissionsPage(Page page) { | ||
this.page = page; | ||
} | ||
|
||
public Locator getAllowedToEditPermissionsCheckbox() { | ||
return page.locator("[data-test-id=permissions-edit-all-checkbox]"); | ||
} | ||
|
||
public void submit() { | ||
final Locator submitButton = page.locator("[data-test-id=permissions-submit-button]"); | ||
page.waitForResponse(Response::ok, submitButton::click); | ||
page.waitForLoadState(DOMCONTENTLOADED); | ||
} | ||
} |