Skip to content

Commit

Permalink
Refacoring
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuJLund committed May 5, 2024
1 parent 2dcee9c commit fd3af20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,26 @@ public class VaadinCreateUI extends UI implements EventBusListener, HasI18N {
protected void init(VaadinRequest request) {
getPage().setTitle("Vaadin Create 23'");
if (!getAccessControl().isUserSignedIn()) {
setContent(new LoginView(getAccessControl(), e -> {
target = getInitialTarget();
logger.info("Initial target '{}'", target);
Utils.sessionFixation();
getPage().reload();
showAppLayout();
}));
showLoginView();
} else {
target = getInitialTarget();
showAppLayout();
}
eventBus.registerEventBusListener(this);
}

private void showLoginView() {
setContent(new LoginView(getAccessControl(), e -> onLogin()));
}

private void onLogin() {
target = getInitialTarget();
logger.info("Initial target '{}'", target);
Utils.sessionFixation();
getPage().reload();
showAppLayout();
}

private String getInitialTarget() {
if (getPage().getUriFragment() == null) {
return AboutView.VIEW_NAME;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.vaadin.tatu.vaadincreate;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import org.vaadin.tatu.vaadincreate.crud.BookGrid;
import org.vaadin.tatu.vaadincreate.crud.FakeGrid;
import org.vaadin.tatu.vaadincreate.i18n.DefaultI18NProvider;
import org.vaadin.tatu.vaadincreate.i18n.I18NProvider;
import org.vaadin.tatu.vaadincreate.login.LanguageSelect;

import com.vaadin.server.VaadinSession;
import com.vaadin.testbench.uiunittest.UIUnitTest;

import com.vaadin.ui.Button;
Expand All @@ -20,13 +21,15 @@
public abstract class AbstractUITest extends UIUnitTest {

protected void login() {
var sessionId = VaadinSession.getCurrent().getSession().getId();
test($(TextField.class).id("login-username-field")).setValue("Admin");
test($(PasswordField.class).id("login-password-field"))
.setValue("admin");
test($(LanguageSelect.class).first())
.clickItem(DefaultI18NProvider.LOCALE_EN);
test($(Button.class).id("login-button")).click();

assertNotEquals(sessionId,
VaadinSession.getCurrent().getSession().getId());
}

protected void logout() {
Expand Down

0 comments on commit fd3af20

Please sign in to comment.