Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions src/test/java/use_case/nav_bar/NavbarInteractorTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
package use_case.nav_bar;
Comment thread
Adish-Singh marked this conversation as resolved.

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
Comment thread
Adish-Singh marked this conversation as resolved.
Comment thread
Adish-Singh marked this conversation as resolved.
Comment thread
Adish-Singh marked this conversation as resolved.

/**
* Test class for NavbarInteractor.
* It verifies that the interactor correctly delegates navigation requests
* to the presenter for all available views.
*/
public class NavbarInteractorTests {
/**
* Tests that switchToLogin correctly calls the presenter's switchToLogin method.
*/
@Test
void testSwitchToLogin() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToLogin();

assertEquals("login", presenter.getLastViewSwitched(),
"Presenter should switch to login view.");
}

/**
* Tests that switchToSignUp correctly calls the presenter's switchToSignUp method.
*/
@Test
void testSwitchToSignUp() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToSignUp();

assertEquals("signup", presenter.getLastViewSwitched(),
"Presenter should switch to signup view.");
}

/**
* Tests that switchToCommunity correctly calls the presenter's switchToCommunity method.
*/
@Test
void testSwitchToCommunity() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToCommunity();

assertEquals("community", presenter.getLastViewSwitched(),
"Presenter should switch to community view.");
}

/**
* Tests that switchToGenerateRecipe correctly calls the presenter's switchToGenerateRecipe method.
*/
@Test
void testSwitchToGenerateRecipe() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToGenerateRecipe();

assertEquals("generateRecipe", presenter.getLastViewSwitched(),
"Presenter should switch to generate recipe view.");
}

/**
* Tests that switchToApproveRecipe correctly calls the presenter's switchToApproveRecipe method.
*/
@Test
void testSwitchToApproveRecipe() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToApproveRecipe();

assertEquals("approveRecipe", presenter.getLastViewSwitched(),
"Presenter should switch to approve recipe view.");
}

/**
* Tests that switchToProfile correctly calls the presenter's switchToProfile method.
*/
@Test
void testSwitchToProfile() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToProfile();

assertEquals("profile", presenter.getLastViewSwitched(),
"Presenter should switch to profile view.");
}

/**
* Tests that switchToGroceryList correctly calls the presenter's switchToGroceryList method.
*/
@Test
void testSwitchToGroceryList() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToGroceryList();

assertEquals("groceryList", presenter.getLastViewSwitched(),
"Presenter should switch to grocery list view.");
}

/**
* Tests that switchToMealPlan correctly calls the presenter's switchToMealPlan method.
*/
@Test
void testSwitchToMealPlan() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToMealPlan();

assertEquals("mealPlan", presenter.getLastViewSwitched(),
"Presenter should switch to meal plan view.");
}

/**
* Tests that switchToSearchByIngredients correctly calls the presenter's switchToSearchByIngredients method.
*/
@Test
void testSwitchToSearchByIngredients() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToSearchByIngredients();

assertEquals("searchByIngredients", presenter.getLastViewSwitched(),
"Presenter should switch to search by ingredients view.");
}

/**
* Tests that switchToLikedRecipeList correctly calls the presenter's switchToLikedRecipeList method.
*/
@Test
void testSwitchToLikedRecipeList() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToLikedRecipeList();

assertEquals("likedRecipeList", presenter.getLastViewSwitched(),
"Presenter should switch to liked recipe list view.");
}

/**
* Tests that multiple sequential switch calls work correctly.
* Verifies that the presenter tracks the most recent view switch.
*/
@Test
void testMultipleSwitchCallsInSequence() {
final NavbarMockPresenter presenter = new NavbarMockPresenter();
final NavbarInteractor interactor = new NavbarInteractor(presenter);

interactor.switchToLogin();
assertEquals("login", presenter.getLastViewSwitched(),
"First switch should be to login view.");

interactor.switchToProfile();
assertEquals("profile", presenter.getLastViewSwitched(),
"Second switch should be to profile view.");

interactor.switchToCommunity();
assertEquals("community", presenter.getLastViewSwitched(),
"Third switch should be to community view.");
}
}
70 changes: 70 additions & 0 deletions src/test/java/use_case/nav_bar/NavbarMockPresenter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package use_case.nav_bar;
Comment thread
Adish-Singh marked this conversation as resolved.

import use_case.nav_bar.NavbarOutputBoundary;
Comment thread
Adish-Singh marked this conversation as resolved.

/**
* Mock implementation of NavbarOutputBoundary for testing purposes.
* Tracks which view was last switched to, allowing tests to verify
* that the interactor correctly delegates to the presenter.
*/
public class NavbarMockPresenter implements NavbarOutputBoundary {
private String lastViewSwitched = null;
Comment thread
Adish-Singh marked this conversation as resolved.

@Override
public void switchToLogin() {
this.lastViewSwitched = "login";
}

@Override
public void switchToSignUp() {
this.lastViewSwitched = "signup";
}

@Override
public void switchToCommunity() {
this.lastViewSwitched = "community";
}

@Override
public void switchToGenerateRecipe() {
this.lastViewSwitched = "generateRecipe";
}

@Override
public void switchToApproveRecipe() {
this.lastViewSwitched = "approveRecipe";
}

@Override
public void switchToProfile() {
this.lastViewSwitched = "profile";
}

@Override
public void switchToGroceryList() {
this.lastViewSwitched = "groceryList";
}

@Override
public void switchToMealPlan() {
this.lastViewSwitched = "mealPlan";
}

@Override
public void switchToSearchByIngredients() {
this.lastViewSwitched = "searchByIngredients";
}

@Override
public void switchToLikedRecipeList() {
this.lastViewSwitched = "likedRecipeList";
}

/**
* Gets the last view that was switched to.
* @return the name of the last view switched to, or null if no switch has occurred
*/
public String getLastViewSwitched() {
return lastViewSwitched;
}
}