Skip to content

Commit

Permalink
Add tests for ProviderType admin interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Duncan committed Jul 24, 2018
1 parent 9eb058c commit d2fd69d
Show file tree
Hide file tree
Showing 8 changed files with 369 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package gov.medicaid.services.impl

import gov.medicaid.entities.AgreementDocument
import gov.medicaid.entities.LicenseType
import gov.medicaid.entities.ProviderTypeSearchCriteria
import gov.medicaid.entities.ProviderType

import gov.medicaid.services.LookupService

import spock.lang.Specification

import javax.persistence.EntityGraph
import javax.persistence.EntityManager
import javax.persistence.TypedQuery
import javax.persistence.Query

class ProviderTypeServiceBeanTest extends Specification {
ProviderTypeServiceBean providerTypeService
EntityManager entityManager
EntityGraph entityGraph

def setup() {
entityGraph = Mock(EntityGraph)
entityManager = Mock(EntityManager)
entityManager.getEntityGraph(_) >> entityGraph
providerTypeService = new ProviderTypeServiceBean()
providerTypeService.em = entityManager
}

def "Find ProviderType List doesn't use EntityGraph"() {
when:
def criteria = new ProviderTypeSearchCriteria()
criteria.setPageNumber(1)
criteria.setPageSize(10)
def query = Mock(Query)
query.getSingleResult() >> 0
query.getResultList() >> []
entityManager.createQuery(_) >> query

def typedQuery = Mock(TypedQuery)
typedQuery.getResultList() >> []
entityManager.createQuery(_, _) >> typedQuery

def searchResult = providerTypeService.search(criteria)
def allResult = providerTypeService.getAllProviderTypes()

then:
0 * entityManager.getEntityGraph(_)
searchResult.items.size == 0
allResult.size == 0
}

def "Get ProviderType searches for Agreements/Licenses"() {
when:
entityManager.find(_, _, _) >> new ProviderType([code: '00'])
def pt = providerTypeService.get('00')

then:
1 * entityManager.getEntityGraph("ProviderType with AgreementDocuments and LicenseTypes")
pt.code == '00'
}

def "Get ProviderType then update"() {
when:
entityManager.find(_, _, _) >> new ProviderType([code: '00'])
def pt = providerTypeService.get('00')

def agreementDocumentQuery = Mock(TypedQuery)
agreementDocumentQuery.setParameter(_, _) >> agreementDocumentQuery
agreementDocumentQuery.getResultList() >> [
new AgreementDocument([id: 1]),
new AgreementDocument([id: 2])
]
entityManager.createQuery(_, AgreementDocument.class) >> agreementDocumentQuery
providerTypeService.updateProviderTypeAgreementSettings(pt, [0, 1] as long[]);

def licenseTypeQuery = Mock(TypedQuery)
licenseTypeQuery.setParameter(_, _) >> licenseTypeQuery
licenseTypeQuery.getResultList() >> [
new LicenseType(),
new LicenseType(),
new LicenseType()
]
entityManager.createQuery(_, LicenseType.class) >> licenseTypeQuery
providerTypeService.updateProviderTypeLicenseSettings(pt, ["0", "1", "2"] as String[]);

def countQuery = Mock(Query)
countQuery.getSingleResult() >> 0
countQuery.setParameter(_, _) >> countQuery
entityManager.createQuery(_) >> countQuery
providerTypeService.updateProviderTypeCanDelete(pt);

then:
pt.agreementDocuments.size() == 2
pt.licenseTypes.size() == 3
pt.canDelete == true
}

def "Create ProviderType generates codes"() {
when:

def providerTypes = []
def lookupService = Mock(LookupService)
providerTypeService.setLookupService(lookupService)
lookupService.findAllLookups(ProviderType.class) >> providerTypes

entityManager.persist(_) >> { args -> providerTypes.add(args[0]) }

providerTypeService.create(new ProviderType())
providerTypeService.create(new ProviderType())
providerTypeService.create(new ProviderType())
providerTypeService.create(new ProviderType())
def code = providerTypeService.create(new ProviderType())

then:
code == 'AE'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public ModelAndView create(@ModelAttribute("providerType") ProviderType provider
return view(providerType);
} else {
FormError error = new FormError();
error.setFieldId("placeholder");
error.setFieldId("providerTypeDescription");

if (blank) {
error.setMessage("Please specify a provider type.");
Expand Down Expand Up @@ -278,7 +278,7 @@ public ModelAndView edit(@ModelAttribute("providerType") ProviderType providerTy

if (typeByDesc != null && !typeByDesc.getCode().equals(providerType.getCode())) {
FormError error = new FormError();
error.setFieldId("placeholder");
error.setFieldId("providerTypeDescription");
error.setMessage("Cannot have a duplicate description: " + providerType.getDescription());

return addCommonElements(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void hasNoServerError() {
assertThat(headerText).isNotEqualTo("Error");
}

public void checkForFormError(String errorClass, String errorText) {
assertThat($(".errorInfo > ." + errorClass).getText())
.contains(errorText);
}

private static Optional<URL> getAxeCoreUrl(WebDriver driver) {
return Optional
.ofNullable(driver.getCurrentUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public void hasNoServerError() {
psmPage.hasNoServerError();
}

@Step
public void checkForFormError(String errorClass, String errorText) {
psmPage.checkForFormError(errorClass, errorText);
}

@Step
public void navigateToRegisterNewAccountPage() {
loginPage.open();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package gov.medicaid.features.service_admin.steps;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;

import gov.medicaid.features.general.steps.GeneralSteps;

import net.thucydides.core.annotations.Steps;

public class ProviderTypeStepDefinitions {
@Steps
ProviderTypeSteps providerTypeSteps;

@Steps
GeneralSteps generalSteps;

@Given("^I create a Provider Type with Description '(.*)'$")
public void i_create_a_Provider_Type_with_Description(String desc) {
generalSteps.clickLinkAssertTitle(".addProviderBtn", "Create Provider Type");
providerTypeSteps.setProviderTypeDescription(desc);
providerTypeSteps.submitProviderType();
}

@Then("^I should see a Provider Type Description error '(.*)'$")
public void i_should_see_an_error(String errorText) {
generalSteps.checkForFormError("providerTypeDescription", errorText);
}

@Given("^I am on the Functions View Provider Type page for '(.*)'$")
public void i_am_on_the_Functions_View_Provider_Type_page_for(String desc) {
providerTypeSteps.viewProviderType(desc);
}

@Then("^I should see a Provider Type with Description '(.*)'$")
public void i_should_see_a_Provider_Type_with_Description(String desc) {
providerTypeSteps.confirmOnViewPage(desc);
}

@Given("^I am on the Functions Edit Provider Type page for '(.*)'$")
public void i_am_on_the_Functions_Edit_Provider_Type_page_for(String desc) {
providerTypeSteps.editProviderType(desc);
}

@Given("^I change the Provider Type Description to '(.*)'$")
public void i_change_the_Provider_Type_Description_to(String newDesc) {
providerTypeSteps.setProviderTypeDescription(newDesc);
}

@Given("^I add Provider Type Agreements and Licenses$")
public void i_add_Provider_Type_Agreements_and_Licenses() {
providerTypeSteps.addProviderTypeAgreementsAndLicenses();
}

@Given("^I submit the Provider Type Edit$")
public void i_submit_the_Provider_Type_Edit() {
providerTypeSteps.submitProviderType();
}

@Given("^I delete the Provider Type '(.*)'$")
public void i_delete_the_Provider_Type(String desc) {
providerTypeSteps.deleteProviderType(desc);
}

@Then("^I should not see a Provider Type with Description '(.*)'$")
public void i_should_not_see_a_Provider_Type_with_Description(String desc) {
providerTypeSteps.confirmNoProviderTypeInList(desc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gov.medicaid.features.service_admin.steps;

import gov.medicaid.features.service_admin.ui.ProviderTypePage;

import net.thucydides.core.annotations.Step;

public class ProviderTypeSteps {
ProviderTypePage providerTypePage;

@Step
public void setProviderTypeDescription(String desc) {
providerTypePage.updateDescriptionInput(desc);
}

@Step
public void submitProviderType() {
providerTypePage.submitSave();
}

@Step
public void confirmOnViewPage(String desc) {
providerTypePage.assertViewing(desc);
}

@Step
public void viewProviderType(String desc) {
providerTypePage.view(desc);
}

@Step
public void editProviderType(String desc) {
providerTypePage.edit(desc);
}

@Step
public void addProviderTypeAgreementsAndLicenses() {
providerTypePage.addAgreementsAndLicenses();
}

@Step
public void confirmNoProviderTypeInList(String desc) {
providerTypePage.noProviderTypeInList(desc);
}

@Step
public void deleteProviderType(String desc) {
providerTypePage.delete(desc);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gov.medicaid.features.service_admin.ui;

import gov.medicaid.features.PsmPage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.Optional;

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

public class ProviderTypePage extends PsmPage {
public void updateDescriptionInput(String desc) {
$("#editProviderTypeProviderType").clear();
$("#editProviderTypeProviderType").sendKeys(desc);
}

public void submitSave() {
click$(".saveProviderTypeBtn");
}

public void assertViewing(String desc) {
assertThat(getTitle()).contains("View Provider Type - Functions (Service Admin)");

Optional<WebElement> descRow = getDriver().findElements(By.cssSelector(".wholeCol"))
.stream()
.filter(div ->
div.findElements(By.cssSelector("label")).size() == 1 &&
"Provider Type".equals(div.findElement(By.cssSelector("label")).getText()))
.findFirst();

assertThat(descRow.isPresent()).isTrue();
assertThat(descRow.get().getText().contains(desc));
}

public void view(String desc) {
getAndAssertProviderTypeRow(desc).findElement(By.cssSelector(".viewProviderLink")).click();
}

public void edit(String desc) {
getAndAssertProviderTypeRow(desc).findElement(By.cssSelector(".editProviderLink")).click();
}

public void noProviderTypeInList(String desc) {
assertThat(getProviderTypeRow(desc)).isEmpty();
}

public void delete(String desc) {
getAndAssertProviderTypeRow(desc).findElement(By.cssSelector(".deleteProviderTypeBtn")).click();

assertThat($("#deleteProviderTypesModal").isDisplayed()).isTrue();

$("#deleteProviderTypesModal .saveBtn").click();
}

public void addAgreementsAndLicenses() {
click$("#remaining_provider_agreement_1");
click$("#remaining_provider_agreement_3");
click$("#addProviderTypeLicense");
}

private WebElement getAndAssertProviderTypeRow(String desc) {
Optional<WebElement> descRow = getProviderTypeRow(desc);
assertThat(descRow.isPresent()).isTrue();
return descRow.get();
}

private Optional<WebElement> getProviderTypeRow(String desc) {
return getDriver().findElements(By.cssSelector("tr"))
.stream()
.filter(div ->
div.findElements(By.cssSelector("td label")).size() > 0 &&
desc.equals(div.findElement(By.cssSelector("td label")).getText()))
.findFirst();
}
}
Loading

0 comments on commit d2fd69d

Please sign in to comment.