Skip to content

Commit

Permalink
Added Cucumber and JUnit 5 tests to the smoketests
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Oct 20, 2024
1 parent e3da38c commit 7643efb
Showing 1 changed file with 16 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter;
import net.serenitybdd.demos.todos.screenplay.questions.CurrentFilter;
import net.serenitybdd.demos.todos.screenplay.questions.TheItems;
import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItem;
import net.serenitybdd.demos.todos.screenplay.tasks.CompleteItems;
import net.serenitybdd.demos.todos.screenplay.tasks.FilterItems;
import net.serenitybdd.demos.todos.screenplay.tasks.Start;
import net.serenitybdd.junit5.SerenityJUnit5Extension;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand All @@ -22,9 +20,9 @@
import java.util.Arrays;
import java.util.List;

import static net.serenitybdd.demos.todos.screenplay.model.TodoStatusFilter.*;
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;

@ExtendWith(SerenityJUnit5Extension.class)
public class FilteringTodos {
Expand All @@ -41,59 +39,42 @@ public void jamesCanBrowseTheWeb() {

@ParameterizedTest
@CsvSource({
// initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedNotDisplayedItems, expectedSelectedFilter
"'Walk the dog;Put out the garbage', 'Walk the dog', 'Completed', 'Walk the dog', 'Put out the garbage', 'Completed'",
"'Walk the dog;Put out the garbage', 'Walk the dog', 'Active', 'Put out the garbage', 'Walk the dog', 'Active'",
"'Walk the dog;Put out the garbage', 'Walk the dog', 'All', 'Walk the dog;Put out the garbage', '', 'All'"
// initialTodos, itemsToComplete, filtersToApply, expectedDisplayedItems, expectedSelectedFilter
"Walk the dog;Put out the garbage, Walk the dog, Completed, Walk the dog, Completed",
"Walk the dog;Put out the garbage, Walk the dog, Active, Put out the garbage, Active",
"Walk the dog;Put out the garbage, Walk the dog, All, Walk the dog;Put out the garbage, All"
})
public void should_be_able_to_filter_todos(
String initialTodosStr,
String itemsToCompleteStr,
String initialTodos,
String itemsToComplete,
String filterToApply,
String expectedDisplayedItemsStr,
String expectedNotDisplayedItemsStr,
String expectedSelectedFilterStr
String expectedDisplayedItems,
String expectedSelectedFilter
) {
// Parse the CSV string parameters into lists
List<String> initialTodos = parseStringToList(initialTodosStr);
List<String> itemsToComplete = parseStringToList(itemsToCompleteStr);
List<String> expectedDisplayedItems = parseStringToList(expectedDisplayedItemsStr);
List<String> expectedNotDisplayedItems = parseStringToList(expectedNotDisplayedItemsStr);
TodoStatusFilter expectedSelectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilterStr);
TodoStatusFilter expectedFilter = TodoStatusFilter.valueOf(expectedSelectedFilter);

// Given
givenThat(james).wasAbleTo(Start.withATodoListContaining(initialTodos));
givenThat(james).wasAbleTo(Start.withATodoListContaining(asList(initialTodos)));

// When
james.attemptsTo(
CompleteItems.called(itemsToComplete),
CompleteItems.called(asList(itemsToComplete)),
FilterItems.toShow(TodoStatusFilter.valueOf(filterToApply))
);

// Then
then(james).should(
seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems.toArray(new String[0]))),
seeThat(CurrentFilter.selected(), is(expectedSelectedFilter))
seeThat(TheItems.displayed(), hasItems(expectedDisplayedItems)),
seeThat(CurrentFilter.selected(), is(expectedFilter))
);
if (!expectedNotDisplayedItems.isEmpty()) {
and(james).should(seeThat(TheItems.displayed(), not(hasItems(expectedNotDisplayedItems.toArray(new String[0])))));
}
}

// Helper method to parse semicolon-separated strings into lists
private List<String> parseStringToList(String str) {
private List<String> asList(String str) {
if (str == null || str.trim().isEmpty()) {
return new ArrayList<>();
}
return Arrays.asList(str.split(";"));
}

// Helper method to parse filter names into TodoStatusFilter enum instances
private List<TodoStatusFilter> parseFilters(List<String> filterNames) {
List<TodoStatusFilter> filters = new ArrayList<>();
for (String name : filterNames) {
filters.add(TodoStatusFilter.valueOf(name));
}
return filters;
}
}

0 comments on commit 7643efb

Please sign in to comment.