Skip to content

Commit

Permalink
test:proposal service add and view proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhumberstone committed Sep 2, 2024
1 parent a948f37 commit 6fc9d9e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nickhumberstone.xpvoting;

import org.springframework.stereotype.Controller;

@Controller
public class ProposalController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.nickhumberstone.xpvoting;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(ProposalController.class)
class ProposalControllerIT {

@Autowired
MockMvc mvc;

@Test
void should_return_200_for_home_page() throws Exception {
mvc.perform(get("/"))
.andExpect(status().isOk());
}
}
21 changes: 21 additions & 0 deletions src/test/java/com/nickhumberstone/xpvoting/ProposalService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

package com.nickhumberstone.xpvoting;

import java.util.List;
import java.util.ArrayList;

import java.util.Collections;

public class ProposalService {
List<String> proposals = new ArrayList<>();

public List<String> proposals() {
// return proposals;
return Collections.unmodifiableList(proposals);
}

public void addProposal(String proposal) {
proposals.add(proposal);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.nickhumberstone.xpvoting;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

class ProposalServiceTest {
ProposalService service = new ProposalService();

@Test
void should_start_with_no_proposals() {
assertThat(service.proposals()).isEmpty();
}

@Test
void should_be_able_to_add_proposal() {
// first add a proposal to the Proposal Service
service.addProposal("Proposal 1");
// expect our proposal to be in the list
assertThat(service.proposals()).contains("Proposal 1");
}

@Test
void should_be_able_to_add_multiple_proposals() {
service.addProposal("Proposal A");
service.addProposal("Proposal B");
assertThat(service.proposals()).contains("Proposal A", "Proposal B");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ void shouldHaveSubHeading() {
new Page.GetByRoleOptions().setName("Proposed topic titles")))
.isVisible();
}

@Test
void shouldBeAbleToProposeAndViewProposal() {
page.getByLabel("Proposal").fill("XTC is cool");
page.getByRole(AriaRole.BUTTON).click();
assertThat(page.getByRole(AriaRole.LISTITEM).and(page.getByText("XTC is cool"))).isVisible();
}
}

0 comments on commit 6fc9d9e

Please sign in to comment.