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 Accountability Surveys - Smoke tests #3997

Merged
merged 12 commits into from
Jul 9, 2024
131 changes: 131 additions & 0 deletions backend/selenium_tests/accountability/test_surveys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from django.db import transaction

import pytest
from helpers.fixtures import get_program_with_dct_type_and_name
from page_object.accountability.surveys import AccountabilitySurveys
from page_object.accountability.surveys_details import AccountabilitySurveysDetails

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.accountability.fixtures import SurveyFactory
from hct_mis_api.apps.accountability.models import Survey
from hct_mis_api.apps.core.models import BusinessArea, DataCollectingType
from hct_mis_api.apps.household.fixtures import create_household_and_individuals
from hct_mis_api.apps.household.models import REFUGEE, Household
from hct_mis_api.apps.program.models import Program
from hct_mis_api.apps.targeting.fixtures import (
TargetingCriteriaFactory,
TargetPopulationFactory,
)

pytestmark = pytest.mark.django_db(transaction=True)


@pytest.fixture
def test_program() -> Program:
return get_program_with_dct_type_and_name("Test Program", "NORM", DataCollectingType.Type.STANDARD)


@pytest.fixture
def add_household() -> Household:
program = Program.objects.first()
with transaction.atomic():
household, individuals = create_household_and_individuals(
household_data={"business_area": program.business_area, "program": program, "residence_status": REFUGEE},
individuals_data=[
{"business_area": program.business_area, "observed_disability": []},
],
)
return household


@pytest.fixture
def add_accountability_surveys_message() -> Survey:
targeting_criteria = TargetingCriteriaFactory()

target_population = TargetPopulationFactory(
created_by=User.objects.first(),
targeting_criteria=targeting_criteria,
business_area=BusinessArea.objects.first(),
)
return SurveyFactory(
title="Test survey",
category="MANUAL",
unicef_id="SUR-24-0005",
target_population=target_population,
created_by=User.objects.first(),
)


@pytest.mark.usefixtures("login")
class TestSmokeAccountabilitySurveys:
def test_smoke_accountability_surveys(
self,
test_program: Program,
add_accountability_surveys_message: Survey,
pageAccountabilitySurveys: AccountabilitySurveys,
) -> None:
pageAccountabilitySurveys.selectGlobalProgramFilter("Test Program").click()
pageAccountabilitySurveys.getNavAccountability().click()
pageAccountabilitySurveys.getNavSurveys().click()

assert "Surveys" in pageAccountabilitySurveys.getPageHeaderTitle().text
assert "NEW SURVEY" in pageAccountabilitySurveys.getButtonNewSurvey().text
assert "Search" in pageAccountabilitySurveys.getFiltersSearch().text
assert "Target Population" in pageAccountabilitySurveys.getTargetPopulationInput().text
assert "Created by" in pageAccountabilitySurveys.getFiltersCreatedByAutocomplete().text
assert "Created by" in pageAccountabilitySurveys.getCreatedByInput().text
assert "From" in pageAccountabilitySurveys.getFiltersCreationDateFrom().text
assert "To" in pageAccountabilitySurveys.getFiltersCreationDateTo().text
assert "CLEAR" in pageAccountabilitySurveys.getButtonFiltersClear().text
assert "APPLY" in pageAccountabilitySurveys.getButtonFiltersApply().text
assert "Surveys List" in pageAccountabilitySurveys.getTableTitle().text
assert "Survey ID" in pageAccountabilitySurveys.getTableLabel()[0].text
assert "Survey Title" in pageAccountabilitySurveys.getTableLabel()[1].text
assert "Category" in pageAccountabilitySurveys.getTableLabel()[2].text
assert "Number of Recipients" in pageAccountabilitySurveys.getTableLabel()[3].text
assert "Created by" in pageAccountabilitySurveys.getTableLabel()[4].text
assert "Creation Date" in pageAccountabilitySurveys.getTableLabel()[5].text
assert "10 1–1 of 1" in pageAccountabilitySurveys.getTablePagination().text.replace("\n", " ")
assert 1 == len(pageAccountabilitySurveys.getRows())
assert "SUR-24-0005" in pageAccountabilitySurveys.getRows()[0].text
assert "Test survey" in pageAccountabilitySurveys.getRows()[0].text

def test_smoke_accountability_surveys_details(
self,
test_program: Program,
add_accountability_surveys_message: Survey,
add_household: Household,
pageAccountabilitySurveys: AccountabilitySurveys,
pageAccountabilitySurveysDetails: AccountabilitySurveysDetails,
) -> None:
add_accountability_surveys_message.recipients.set([Household.objects.first()])
pageAccountabilitySurveys.selectGlobalProgramFilter("Test Program").click()
pageAccountabilitySurveys.getNavAccountability().click()
pageAccountabilitySurveys.getNavSurveys().click()
pageAccountabilitySurveys.getRows()[0].click()

assert "SUR-24-0005" in pageAccountabilitySurveysDetails.getPageHeaderTitle().text
assert "Survey with manual process" in pageAccountabilitySurveysDetails.getLabelCategory().text
assert "Test survey" in pageAccountabilitySurveysDetails.getLabelSurveyTitle().text
created_by = add_accountability_surveys_message.created_by
assert (
f"{created_by.first_name} {created_by.last_name}"
in pageAccountabilitySurveysDetails.getLabelCreatedBy().text
)
assert (
add_accountability_surveys_message.created_at.strftime("%-d %b %Y")
in pageAccountabilitySurveysDetails.getLabelDateCreated().text
)
assert "Test Program" in pageAccountabilitySurveysDetails.getLabelProgramme().text
assert "Household Id" in pageAccountabilitySurveysDetails.getHouseholdId().text
assert "Status" in pageAccountabilitySurveysDetails.getStatus().text
assert "Head of Household" in pageAccountabilitySurveysDetails.getHouseholdHeadName().text
assert "Household Size" in pageAccountabilitySurveysDetails.getHouseholdSize().text
assert "Administrative Level 2" in pageAccountabilitySurveysDetails.getHouseholdLocation().text
assert "Residence Status" in pageAccountabilitySurveysDetails.getHouseholdResidenceStatus().text
assert "Registration Date" in pageAccountabilitySurveysDetails.getHouseholdRegistrationDate().text
assert "Rows per page: 10 1–1 of 1" in pageAccountabilitySurveysDetails.getTablePagination().text.replace(
"\n", " "
)
assert 1 == len(pageAccountabilitySurveys.getRows())
assert "HH-0" in pageAccountabilitySurveys.getRows()[0].text
12 changes: 12 additions & 0 deletions backend/selenium_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from page_object.accountability.comunication_details import (
AccountabilityCommunicationDetails,
)
from page_object.accountability.surveys import AccountabilitySurveys
from page_object.accountability.surveys_details import AccountabilitySurveysDetails
from page_object.admin_panel.admin_panel import AdminPanel
from page_object.filters import Filters
from page_object.grievance.details_feedback_page import FeedbackDetailsPage
Expand Down Expand Up @@ -324,6 +326,16 @@ def pageNewPaymentPlan(request: FixtureRequest, browser: Chrome) -> NewPaymentPl
yield NewPaymentPlan(browser)


@pytest.fixture
def pageAccountabilitySurveys(request: FixtureRequest, browser: Chrome) -> AccountabilitySurveys:
yield AccountabilitySurveys(browser)


@pytest.fixture
def pageAccountabilitySurveysDetails(request: FixtureRequest, browser: Chrome) -> AccountabilitySurveysDetails:
yield AccountabilitySurveysDetails(browser)


@pytest.fixture
def pageAccountabilityCommunication(request: FixtureRequest, browser: Chrome) -> AccountabilityCommunication:
yield AccountabilityCommunication(browser)
Expand Down
95 changes: 81 additions & 14 deletions backend/selenium_tests/page_object/accountability/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@
from selenium.webdriver.remote.webelement import WebElement


class SurveysPage(BaseComponents):
class AccountabilitySurveys(BaseComponents):
# Locators
titlePage = 'h5[data-cy="page-header-title"]'
pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
buttonNewSurvey = 'button[data-cy="button-new-survey"]'
filtersSearch = 'div[data-cy="filters-search"]'
filtersTargetPopulationAutocomplete = 'div[data-cy="filters-target-population-autocomplete"]'
targetPopulationInput = 'div[data-cy="Target Population-input"]'
filtersCreatedByAutocomplete = 'div[data-cy="filters-created-by-autocomplete"]'
createdByInput = 'div[data-cy="Created by-input"]'
filtersCreationDateFrom = 'div[data-cy="filters-creation-date-from"]'
filtersCreationDateTo = 'div[data-cy="filters-creation-date-to"]'
buttonFiltersClear = 'button[data-cy="button-filters-clear"]'
buttonFiltersApply = 'button[data-cy="button-filters-apply"]'
tableTitle = 'h6[data-cy="table-title"]'
tableLabel = 'span[data-cy="table-label"]'
tablePagination = 'div[data-cy="table-pagination"]'
menuItemRapidPro = 'li[data-cy="menu-item-rapid-pro"]'
menuItemRapidProText = 'div[data-cy="menu-item-rapid-pro-text"]'
menuItemSmsText = 'li[data-cy="menu-item-sms-text"]'
menuItemManual = 'li[data-cy="menu-item-manual"]'
menuItemManualText = 'div[data-cy="menu-item-manual-text"]'
rows = 'tr[role="checkbox"]'
buttonApply = 'button[data-cy="button-filters-apply"]'
buttonClear = 'button[data-cy="button-filters-clear"]'

# Texts
textTitlePage = "Surveys"
Expand All @@ -16,17 +33,67 @@ class SurveysPage(BaseComponents):
textTabCreatedBy = "Created by"

# Elements
def getTitlePage(self) -> WebElement:
return self.wait_for(self.titlePage)
def getPageHeaderContainer(self) -> WebElement:
return self.wait_for(self.pageHeaderContainer)

def getMessageID(self) -> WebElement:
return self.wait_for(self.tabColumnLabel).eq(0)
def getPageHeaderTitle(self) -> WebElement:
return self.wait_for(self.pageHeaderTitle)

def getApply(self) -> WebElement:
return self.wait_for(self.buttonApply)
def getButtonNewSurvey(self) -> WebElement:
return self.wait_for(self.buttonNewSurvey)

def getClear(self) -> WebElement:
return self.wait_for(self.buttonClear)
def getFiltersSearch(self) -> WebElement:
return self.wait_for(self.filtersSearch)

def getTargetPopulationsRows(self) -> WebElement:
return self.wait_for(self.rows)
def getFiltersTargetPopulationAutocomplete(self) -> WebElement:
return self.wait_for(self.filtersTargetPopulationAutocomplete)

def getTargetPopulationInput(self) -> WebElement:
return self.wait_for(self.targetPopulationInput)

def getFiltersCreatedByAutocomplete(self) -> WebElement:
return self.wait_for(self.filtersCreatedByAutocomplete)

def getCreatedByInput(self) -> WebElement:
return self.wait_for(self.createdByInput)

def getFiltersCreationDateFrom(self) -> WebElement:
return self.wait_for(self.filtersCreationDateFrom)

def getFiltersCreationDateTo(self) -> WebElement:
return self.wait_for(self.filtersCreationDateTo)

def getButtonFiltersClear(self) -> WebElement:
return self.wait_for(self.buttonFiltersClear)

def getButtonFiltersApply(self) -> WebElement:
return self.wait_for(self.buttonFiltersApply)

def getTableTitle(self) -> WebElement:
return self.wait_for(self.tableTitle)

def getTableLabel(self) -> [WebElement]:
self.wait_for(self.tableLabel)
return self.get_elements(self.tableLabel)

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

def getMenuItemRapidPro(self) -> WebElement:
return self.wait_for(self.menuItemRapidPro)

def getMenuItemRapidProText(self) -> WebElement:
return self.wait_for(self.menuItemRapidProText)

def getMenuItemSmsText(self) -> WebElement:
return self.wait_for(self.menuItemSmsText)

def getMenuItemManual(self) -> WebElement:
return self.wait_for(self.menuItemManual)

def getMenuItemManualText(self) -> WebElement:
return self.wait_for(self.menuItemManualText)

def getRows(self) -> [WebElement]:
self.wait_for(self.rows)
return self.get_elements(self.rows)
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from page_object.base_components import BaseComponents
from selenium.webdriver.remote.webelement import WebElement


class AccountabilitySurveysDetails(BaseComponents):
pageHeaderContainer = 'div[data-cy="page-header-container"]'
pageHeaderTitle = 'h5[data-cy="page-header-title"]'
labelCategory = 'div[data-cy="label-Category"]'
labelSurveyTitle = 'div[data-cy="label-Survey Title"]'
labelCreatedBy = 'div[data-cy="label-Created By"]'
labelDateCreated = 'div[data-cy="label-Date Created"]'
labelTargetPopulation = 'div[data-cy="label-Target Population"]'
labelProgramme = 'div[data-cy="label-Programme"]'
tableTitle = 'h6[data-cy="table-title"]'
householdId = 'th[data-cy="household-id"]'
tableLabel = 'span[data-cy="table-label"]'
status = 'th[data-cy="status"]'
householdHeadName = 'th[data-cy="household-head-name"]'
householdSize = 'th[data-cy="household-size"]'
householdLocation = 'th[data-cy="household-location"]'
householdResidenceStatus = 'th[data-cy="household-residence-status"]'
householdRegistrationDate = 'th[data-cy="household-registration-date"]'
tableRow = 'tr[data-cy="table-row"]'
tablePagination = 'div[data-cy="table-pagination"]'
rows = 'tr[role="checkbox"]'

def getPageHeaderContainer(self) -> WebElement:
return self.wait_for(self.pageHeaderContainer)

def getPageHeaderTitle(self) -> WebElement:
return self.wait_for(self.pageHeaderTitle)

def getLabelCategory(self) -> WebElement:
return self.wait_for(self.labelCategory)

def getLabelSurveyTitle(self) -> WebElement:
return self.wait_for(self.labelSurveyTitle)

def getLabelCreatedBy(self) -> WebElement:
return self.wait_for(self.labelCreatedBy)

def getLabelDateCreated(self) -> WebElement:
return self.wait_for(self.labelDateCreated)

def getLabelTargetPopulation(self) -> WebElement:
return self.wait_for(self.labelTargetPopulation)

def getLabelProgramme(self) -> WebElement:
return self.wait_for(self.labelProgramme)

def getTableTitle(self) -> WebElement:
return self.wait_for(self.tableTitle)

def getHouseholdId(self) -> WebElement:
return self.wait_for(self.householdId)

def getTableLabel(self) -> WebElement:
return self.wait_for(self.tableLabel)

def getStatus(self) -> WebElement:
return self.wait_for(self.status)

def getHouseholdHeadName(self) -> WebElement:
return self.wait_for(self.householdHeadName)

def getHouseholdSize(self) -> WebElement:
return self.wait_for(self.householdSize)

def getHouseholdLocation(self) -> WebElement:
return self.wait_for(self.householdLocation)

def getHouseholdResidenceStatus(self) -> WebElement:
return self.wait_for(self.householdResidenceStatus)

def getHouseholdRegistrationDate(self) -> WebElement:
return self.wait_for(self.householdRegistrationDate)

def getTableRow(self) -> WebElement:
return self.wait_for(self.tableRow)

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)
Loading