-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ProviderType admin interface.
- Loading branch information
Frank Duncan
committed
Jul 24, 2018
1 parent
9eb058c
commit d2fd69d
Showing
8 changed files
with
369 additions
and
2 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
...ess-process/src/test/groovy/gov/medicaid/services/impl/ProviderTypeServiceBeanTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../src/test/java/gov/medicaid/features/service_admin/steps/ProviderTypeStepDefinitions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...tion-tests/src/test/java/gov/medicaid/features/service_admin/steps/ProviderTypeSteps.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...egration-tests/src/test/java/gov/medicaid/features/service_admin/ui/ProviderTypePage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.