Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenium: Payment Verification tests #4318

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/frontend/src/components/payments/CreateVerificationPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ export const CreateVerificationPlan = ({
variant="fullWidth"
aria-label="full width tabs example"
>
<Tab label={t('FULL LIST')} />
<Tab label={t('RANDOM SAMPLING')} />
<Tab data-cy="tab-full-list" label={t('FULL LIST')} />
<Tab data-cy="tab-random-sampling" label={t('RANDOM SAMPLING')} />
</StyledTabs>
</TabsContainer>
<TabPanel value={selectedTab} index={0}>
Expand Down Expand Up @@ -340,10 +340,11 @@ export const CreateVerificationPlan = ({
name="verificationChannel"
label={t('Verification Channel')}
style={{ flexDirection: 'row' }}
data-cy="checkbox-verification-channel"
choices={[
{ value: 'RAPIDPRO', name: 'RAPIDPRO' },
{ value: 'XLSX', name: 'XLSX' },
{ value: 'MANUAL', name: 'MANUAL' },
{ value: 'RAPIDPRO', name: 'RAPIDPRO', dataCy: 'radio-rapidpro' },
{ value: 'XLSX', name: 'XLSX', dataCy: 'radio-xlsx' },
{ value: 'MANUAL', name: 'MANUAL', dataCy: 'radio-manual' },
]}
component={FormikRadioGroup}
alignItems="center"
Expand Down Expand Up @@ -480,9 +481,9 @@ export const CreateVerificationPlan = ({
style={{ flexDirection: 'row' }}
alignItems="center"
choices={[
{ value: 'RAPIDPRO', name: 'RAPIDPRO' },
{ value: 'XLSX', name: 'XLSX' },
{ value: 'MANUAL', name: 'MANUAL' },
{ value: 'RAPIDPRO', name: 'RAPIDPRO', dataCy: 'radio-rapidpro' },
{ value: 'XLSX', name: 'XLSX', dataCy: 'radio-xlsx' },
{ value: 'MANUAL', name: 'MANUAL', dataCy: 'radio-manual' },
]}
component={FormikRadioGroup}
/>
Expand All @@ -508,7 +509,7 @@ export const CreateVerificationPlan = ({
</DialogContent>
<DialogFooter>
<DialogActions>
<Button onClick={() => setOpen(false)}>CANCEL</Button>
<Button data-cy="button-cancel" onClick={() => setOpen(false)}>CANCEL</Button>
<LoadingButton
loading={loading}
type="submit"
Expand Down
12 changes: 6 additions & 6 deletions src/frontend/src/components/payments/EditVerificationPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@ export const EditVerificationPlan = ({
label={t('Verification Channel')}
style={{ flexDirection: 'row', alignItems: 'center' }}
choices={[
{ value: 'RAPIDPRO', name: 'RAPIDPRO' },
{ value: 'XLSX', name: 'XLSX' },
{ value: 'MANUAL', name: 'MANUAL' },
{ value: 'RAPIDPRO', name: 'RAPIDPRO', dataCy: 'radio-rapidpro' },
{ value: 'XLSX', name: 'XLSX', dataCy: 'radio-xlsx' },
{ value: 'MANUAL', name: 'MANUAL', dataCy: 'radio-manual' },
]}
component={FormikRadioGroup}
alignItems="center"
Expand Down Expand Up @@ -500,9 +500,9 @@ export const EditVerificationPlan = ({
}}
alignItems="center"
choices={[
{ value: 'RAPIDPRO', name: 'RAPIDPRO' },
{ value: 'XLSX', name: 'XLSX' },
{ value: 'MANUAL', name: 'MANUAL' },
{ value: 'RAPIDPRO', name: 'RAPIDPRO', dataCy: 'radio-rapidpro' },
{ value: 'XLSX', name: 'XLSX', dataCy: 'radio-xlsx' },
{ value: 'MANUAL', name: 'MANUAL', dataCy: 'radio-manual' },
]}
component={FormikRadioGroup}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function VerificationPlanDetails({
<Container>
<Box display="flex" alignItems="center" justifyContent="space-between">
<Title>
<Typography variant="h6">
<Typography data-cy={`verification-plan-${verificationPlan.unicefId}`} variant="h6">
{t('Verification Plan')} #{verificationPlan.unicefId}
<AdminButton adminUrl={verificationPlan.adminUrl} sx={{ ml: 2 }}/>
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ export function FormikRadioGroup({
value: string;
optionLabel?: string | React.ReactElement;
name: string;
dataCy?: string;
}) => (
<Box p={2} mb={2} key={each.value}>
<Box display="flex" alignItems={alignItems}>
<Radio
color="primary"
value={each.value}
checked={field.value === each.value}
data-cy={each?.dataCy}
/>
{withGreyBox ? (
<GreyBox p={2}>
Expand Down
2 changes: 2 additions & 0 deletions tests/selenium/page_object/payment_module/payment_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ def getTablePagination(self) -> WebElement:
return self.wait_for(self.tablePagination)

def getRows(self) -> [WebElement]:
self.wait_for(self.rows)
return self.get_elements(self.rows)

def getRow(self, number: int) -> WebElement:
self.wait_for(self.rows)
try:
sleep(0.5)
return self.get_elements(self.rows)[number]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ class PaymentVerification(BaseComponents):
cashPlanTableRow = 'tr[data-cy="cash-plan-table-row"]'
statusContainer = 'div[data-cy="status-container"]'
tablePagination = 'div[data-cy="table-pagination"]'
buttonNewPlan = 'button[data-cy="button-new-plan"]'

tabFullList = 'button[data-cy="tab-full-list"]'
tabRandomSampling = 'button[data-cy="tab-random-sampling"]'
selectExcludedadminareasfull = 'div[data-cy="select-excludedAdminAreasFull"]'
checkboxVerificationChannel = 'div[data-cy="checkbox-verification-channel"]'
sliderConfidenceInterval = 'span[data-cy="slider-confidence-interval"]'
sliderMarginOfError = 'span[data-cy="slider-margin-of-error"]'
inputAdmincheckbox = 'span[data-cy="input-adminCheckbox"]'
inputAgecheckbox = 'span[data-cy="input-ageCheckbox"]'
inputSexcheckbox = 'span[data-cy="input-sexCheckbox"]'
dialogActionsContainer = 'div[data-cy="dialog-actions-container"]'
buttonCancel = 'button[data-cy="button-cancel"]'
buttonSubmit = 'button[data-cy="button-submit"]'
radioRapidpro = 'span[data-cy="radio-rapidpro"]'
radioXlsx = 'span[data-cy="radio-xlsx"]'
radioManual = 'span[data-cy="radio-manual"]'
radioVerificationChannel = 'span[data-cy="radio-{}"]'

def getPageHeaderContainer(self) -> WebElement:
return self.wait_for(self.pageHeaderContainer)
Expand Down Expand Up @@ -89,3 +107,54 @@ def getStatusContainer(self) -> WebElement:

def getTablePagination(self) -> WebElement:
return self.wait_for(self.tablePagination)

def getButtonNewPlan(self) -> WebElement:
return self.wait_for(self.buttonNewPlan)

def getTabFullList(self) -> WebElement:
return self.wait_for(self.tabFullList)

def getTabRandomSampling(self) -> WebElement:
return self.wait_for(self.tabRandomSampling)

def getSelectExcludedadminareasfull(self) -> WebElement:
return self.wait_for(self.selectExcludedadminareasfull)

def getCheckboxVerificationChannel(self) -> WebElement:
return self.wait_for(self.checkboxVerificationChannel)

def getRadioRapidpro(self) -> WebElement:
return self.wait_for(self.radioRapidpro)

def getRadioXlsx(self) -> WebElement:
return self.wait_for(self.radioXlsx)

def getRadioManual(self) -> WebElement:
return self.wait_for(self.radioManual)

def getRadioVerificationChannel(self, name: str) -> WebElement:
return self.wait_for(self.radioVerificationChannel.format(name))

def getSliderConfidenceInterval(self) -> WebElement:
return self.wait_for(self.sliderConfidenceInterval)

def getSliderMarginOfError(self) -> WebElement:
return self.wait_for(self.sliderMarginOfError)

def getInputAdmincheckbox(self) -> WebElement:
return self.wait_for(self.inputAdmincheckbox)

def getInputAgecheckbox(self) -> WebElement:
return self.wait_for(self.inputAgecheckbox)

def getInputSexcheckbox(self) -> WebElement:
return self.wait_for(self.inputSexcheckbox)

def getDialogActionsContainer(self) -> WebElement:
return self.wait_for(self.dialogActionsContainer)

def getButtonCancel(self) -> WebElement:
return self.wait_for(self.buttonCancel)

def getButtonSubmit(self) -> WebElement:
return self.wait_for(self.buttonSubmit)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PaymentVerificationDetails(BaseComponents):
labelizedFieldContainerSummaryNumberOfPlans = 'div[data-cy="labelized-field-container-summary-number-of-plans"]'
labelNumberOfVerificationPlans = 'div[data-cy="label-Number of Verification Plans"]'
buttonDeletePlan = 'button[data-cy="button-delete-plan"]'
verificationPlan = 'h6[data-cy="verification-plan-{}"]'
verificationPlanPrefix = 'h6[data-cy^="verification-plan"]'
buttonActivatePlan = 'button[data-cy="button-activate-plan"]'
verificationPlanStatus = 'div[data-cy="verification-plan-status"]'
labelSampling = 'div[data-cy="label-SAMPLING"]'
Expand Down Expand Up @@ -117,6 +119,15 @@ def getLabelNumberOfVerificationPlans(self) -> WebElement:
def getButtonDeletePlan(self) -> WebElement:
return self.wait_for(self.buttonDeletePlan)

def deleteVerificationPlanByNumber(self, number: int) -> None:
self.get_elements(self.buttonDeletePlan)[number].click()

def getVerificationPlanName(self, name: str) -> WebElement:
return self.wait_for(self.verificationPlan.format(name))

def getVerificationPlanPrefix(self) -> [WebElement]:
return self.get_elements(self.verificationPlanPrefix)

def getButtonActivatePlan(self) -> WebElement:
return self.wait_for(self.buttonActivatePlan)

Expand Down
62 changes: 56 additions & 6 deletions tests/selenium/payment_module/test_payment_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def social_worker_program() -> Program:
def create_program(name: str = "Test Program", dct_type: str = DataCollectingType.Type.STANDARD) -> Program:
BusinessArea.objects.filter(slug="afghanistan").update(is_payment_plan_applicable=True)
dct = DataCollectingTypeFactory(type=dct_type)
return ProgramFactory(
yield ProgramFactory(
name=name,
programme_code="1234",
start_date=datetime.now() - relativedelta(months=1),
Expand Down Expand Up @@ -185,8 +185,52 @@ def create_payment_plan_lock_social_worker(social_worker_program: Program) -> Pa


@pytest.fixture
def create_payment_plan_open() -> PaymentPlan:
yield PaymentPlanFactory(status=PaymentPlan.Status.OPEN)
def create_payment_plan_open(social_worker_program: Program) -> PaymentPlan:
program_cycle = ProgramCycleFactory(
program=social_worker_program,
title="Cycle for PaymentPlan",
status=ProgramCycle.ACTIVE,
start_date=datetime.now() + relativedelta(days=10),
end_date=datetime.now() + relativedelta(days=15),
)

payment_plan = PaymentPlanFactory(
status=PaymentPlan.Status.PREPARING,
is_follow_up=False,
program=social_worker_program,
program_cycle=program_cycle,
business_area=social_worker_program.business_area,
dispersion_start_date=datetime.now().date(),
)
hoh1 = IndividualFactory(household=None)
household_1 = HouseholdFactory(
id="3d7087be-e8f8-478d-9ca2-4ca6d5e96f51", unicef_id="HH-17-0000.3340", head_of_household=hoh1, size=2
)
IndividualFactory(
household=household_1,
program=social_worker_program,
sex="MALE",
birth_date=factory.Faker("date_of_birth", tzinfo=utc, minimum_age=11, maximum_age=16),
)
PaymentFactory(parent=payment_plan, household=household_1, excluded=False, currency="PLN")

payment_plan.update_population_count_fields()
payment_plan.update_money_fields()

payment_plan.status_open()
payment_plan.save(update_fields=("status",))

PaymentPlanFactory(
status=PaymentPlan.Status.LOCKED,
program=social_worker_program,
program_cycle=program_cycle,
business_area=social_worker_program.business_area,
dispersion_start_date=datetime.now().date(),
is_follow_up=True,
source_payment_plan=payment_plan,
)

yield payment_plan


def payment_plan_create(program: Program, status: str = PaymentPlan.Status.LOCKED) -> PaymentPlan:
Expand Down Expand Up @@ -614,7 +658,6 @@ def test_payment_plan_save_exclude(

assert "6" in pagePaymentModuleDetails.getLabelTargetedIndividuals().text

@pytest.mark.skip("Fix problem with fixtures")
def test_payment_plan_delete(
self,
create_payment_plan_open: PaymentPlan,
Expand All @@ -625,12 +668,19 @@ def test_payment_plan_delete(
pagePaymentModule.selectGlobalProgramFilter("Test Program")
pagePaymentModule.getNavPaymentModule().click()
pagePaymentModule.getNavPaymentPlans().click()
payment_plan = pagePaymentModule.getRow(0).text
pagePaymentModule.getRow(0).click()
pagePaymentModule.getRows()
for i in range(len(pagePaymentModule.getRows())):
if "OPEN" in pagePaymentModule.getRow(i).text:
payment_plan = pagePaymentModule.getRow(i).text
pagePaymentModule.getRow(i).click()
break
else:
raise AssertionError("No payment plan has Open status")
pagePaymentModuleDetails.getDeleteButton().click()
pagePaymentModuleDetails.getButtonSubmit().click()
pagePaymentModule.getRow(0)
assert payment_plan not in pagePaymentModule.getRow(0).text
assert "LOCKED" in pagePaymentModule.getRow(0).text

def test_payment_plan_creation_error(
self,
Expand Down
Loading
Loading