aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/webui/PantryItemTest.java
blob: 71948b804d07cd3371026432d5830c86b6e877bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package webui;

import org.junit.jupiter.api.Test;

import static com.microsoft.playwright.assertions.PlaywrightAssertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import com.microsoft.playwright.Locator;

import dev.submelon.model.PantryItem;
import io.quarkiverse.quinoa.testing.QuinoaTestProfiles;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import webui.pages.IndexPage;
import webui.pages.components.AddItemComponent;

@QuarkusTest
@TestProfile(QuinoaTestProfiles.Enable.class)
public class PantryItemTest extends ApplicationTest {

    private static PantryItem[] testItems = new PantryItem[] {
        PantryItem.builder()
                .name("Flour")
                .description("White unbleached")
                .quantity(12.4d)
                .quantityUnitType("cups")
                .build(),
        PantryItem.builder()
                .name("Ponzu Sauce")
                .quantity(4d)
                .quantityUnitType("oz")
                .build()
    };

    @Test
    public void testLanding() {
        // Arrange
        final IndexPage page = new IndexPage(context.newPage());

        // Act
        page.loadAndVerifyPage(indexLocation);

        // Assert
        page.checkItemTableIsEmpty();

        // Check add item button is visible and enabled
        Locator addButton = page.getAddItemButton();
        assertThat(addButton).isVisible();
        assertThat(addButton).isEnabled();
    }

    @Test
    public void testAddItemCancel() {
        // Arrange
        final PantryItem testItem = testItems[0];
        final IndexPage page = new IndexPage(context.newPage());

        // Act
        page.loadAndVerifyPage(indexLocation);
        page.checkItemTableIsEmpty();

        AddItemComponent addItem = AddItemComponent.open(page);
        addItem.enterPantryItem(testItem);
        addItem.cancel();

        // Assert
        page.checkItemTableIsEmpty();
    }

    @Test
    public void testAddItemSubmit() {
        // Arrange
        final PantryItem testItem = testItems[0];
        final IndexPage page = new IndexPage(context.newPage());

        // Act
        page.loadAndVerifyPage(indexLocation);
        page.checkItemTableIsEmpty();

        AddItemComponent addItem = AddItemComponent.open(page);
        addItem.enterPantryItem(testItem);
        addItem.submit();

        // Assert
        page.validateAddItemNotification(testItem);

        List<Locator> items = page.getCurrentItems(1);
        assertEquals(1, items.size());

        Locator newItem = items.get(0);
        assertThat(newItem).containsText(testItem.getName());
        assertThat(newItem).containsText(testItem.getDescription());
        assertThat(newItem).containsText(testItem.getQuantity().toString());
        assertThat(newItem).containsText(testItem.getQuantityUnitType());
    }

}