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: Grievance Dashboard - happy path #4003

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from datetime import timedelta

from django.utils import timezone

import pytest
from page_object.grievance.details_grievance_page import GrievanceDetailsPage
from page_object.grievance.grievance_dashboard import GrievanceDashboard
from page_object.grievance.grievance_tickets import GrievanceTickets

from hct_mis_api.apps.account.models import User
from hct_mis_api.apps.core.models import BusinessArea
Expand Down Expand Up @@ -42,10 +48,40 @@ def add_grievances() -> None:
GrievanceTicket._meta.get_field("created_at").auto_now_add = True


@pytest.fixture
def grievances() -> [GrievanceTicket]:
GrievanceTicket._meta.get_field("created_at").auto_now_add = False
GrievanceTicket._meta.get_field("updated_at").auto_now = False
grievances = list()
grievances.append(
generate_grievance(
created_at=str(timezone.now() - timedelta(days=20)),
updated_at=str(timezone.now()),
status=GrievanceTicket.STATUS_NEW,
)
)
grievances.append(
generate_grievance(
created_at=str(timezone.now() - timedelta(days=40)),
status=GrievanceTicket.STATUS_NEW,
)
)
grievances.append(
generate_grievance(
created_at=str(timezone.now() - timedelta(days=60)),
status=GrievanceTicket.STATUS_NEW,
category=GrievanceTicket.CATEGORY_NEEDS_ADJUDICATION,
)
)
GrievanceTicket._meta.get_field("created_at").auto_now_add = True
GrievanceTicket._meta.get_field("updated_at").auto_now = True
return grievances


def generate_grievance(
unicef_id: str,
unicef_id: str = "GRV-0000001",
status: int = GrievanceTicket.STATUS_NEW,
category: int = GrievanceTicket.CATEGORY_POSITIVE_FEEDBACK,
category: int = GrievanceTicket.CATEGORY_REFERRAL,
created_by: User | None = None,
assigned_to: User | None = None,
business_area: BusinessArea | None = None,
Expand All @@ -54,11 +90,11 @@ def generate_grievance(
household_unicef_id: str = "HH-20-0000.0001",
updated_at: str = "2023-09-27T11:26:33.846Z",
created_at: str = "2022-04-30T09:54:07.827000",
) -> None:
) -> GrievanceTicket:
created_by = User.objects.first() if created_by is None else created_by
assigned_to = User.objects.first() if assigned_to is None else assigned_to
business_area = BusinessArea.objects.filter(slug="afghanistan").first() if business_area is None else business_area
GrievanceTicket.objects.create(
grievance_ticket = GrievanceTicket.objects.create(
**{
"business_area": business_area,
"unicef_id": unicef_id,
Expand All @@ -77,6 +113,14 @@ def generate_grievance(
}
)

from hct_mis_api.apps.grievance.models import TicketReferralDetails

TicketReferralDetails.objects.create(
ticket=grievance_ticket,
)

return grievance_ticket


@pytest.mark.usefixtures("login")
class TestSmokeGrievanceDashboard:
Expand Down Expand Up @@ -105,3 +149,49 @@ def test_smoke_grievance_dashboard(
"365 days" in pageGrievanceDashboard.getLabelizedFieldContainerTicketsAverageResolutionUserGenerated().text
)
GrievanceTicket._meta.get_field("updated_at").auto_now = True

def test_grievance_dashboard_happy_path(
self,
active_program: Program,
grievances: [GrievanceTicket],
pageGrievanceDashboard: GrievanceDashboard,
pageGrievanceTickets: GrievanceTickets,
pageGrievanceDetailsPage: GrievanceDetailsPage,
) -> None:
pageGrievanceTickets.getNavGrievance().click()
pageGrievanceDashboard.getNavGrievanceDashboard().click()
assert "Grievance Dashboard" in pageGrievanceDashboard.getPageHeaderTitle().text
assert "3" in pageGrievanceDashboard.getTotalNumberOfTicketsTopNumber().text
assert "1" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfTicketsSystemGenerated().text
assert "2" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfTicketsUserGenerated().text
assert "0" in pageGrievanceDashboard.getTotalNumberOfClosedTicketsTopNumber().text
assert "0" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfClosedTicketsSystemGenerated().text
assert "0" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfClosedTicketsUserGenerated().text
assert "0 days" in pageGrievanceDashboard.getTicketsAverageResolutionTopNumber().text
assert (
"0 days" in pageGrievanceDashboard.getLabelizedFieldContainerTicketsAverageResolutionSystemGenerated().text
)
assert "0 days" in pageGrievanceDashboard.getLabelizedFieldContainerTicketsAverageResolutionUserGenerated().text

pageGrievanceTickets.getNavGrievance().click()
pageGrievanceTickets.getTicketListRow()[0].click()
pageGrievanceDetailsPage.getButtonAssignToMe().click()
pageGrievanceDetailsPage.getButtonSetInProgress().click()
pageGrievanceDetailsPage.getButtonCloseTicket().click()
pageGrievanceTickets.getButtonConfirm().click()
pageGrievanceTickets.getNavGrievance().click()
pageGrievanceTickets.getNavGrievance().click()
pageGrievanceDashboard.getNavGrievanceDashboard().click()
assert "3" in pageGrievanceDashboard.getTotalNumberOfTicketsTopNumber().text
assert "1" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfTicketsSystemGenerated().text
assert "2" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfTicketsUserGenerated().text
assert "0" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfClosedTicketsSystemGenerated().text
assert "1" in pageGrievanceDashboard.getLabelizedFieldContainerTotalNumberOfClosedTicketsUserGenerated().text
assert "20.00 days" in pageGrievanceDashboard.getTicketsAverageResolutionTopNumber().text
assert (
"0 days" in pageGrievanceDashboard.getLabelizedFieldContainerTicketsAverageResolutionSystemGenerated().text
)
assert (
"20 days" in pageGrievanceDashboard.getLabelizedFieldContainerTicketsAverageResolutionUserGenerated().text
)
assert "1" in pageGrievanceDashboard.getTotalNumberOfClosedTicketsTopNumber().text
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ def getPageHeaderContainer(self) -> WebElement:
def getTitle(self) -> WebElement:
return self.wait_for(self.title)

def getButtonCloseTicket(self) -> WebElement:
return self.wait_for(self.buttonCloseTicket)

def getButtonAssignToMe(self) -> WebElement:
return self.wait_for(self.buttonAssignToMe)

def getButtonCloseTicket(self) -> WebElement:
return self.wait_for(self.buttonCloseTicket)
def getButtonSetInProgress(self) -> WebElement:
return self.wait_for(self.buttonSetInProgress)

def getButtonSendBack(self) -> WebElement:
return self.wait_for(self.buttonSendBack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GrievanceTickets(BaseComponents):
familyName = 'li[data-value="full_name"]'
tabSystemGenerated = 'button[data-cy="tab-SYSTEM-GENERATED"]'
tabUserGenerated = 'button[data-cy="tab-USER-GENERATED"]'
buttonCloseTicket = 'button[data-cy="button-close-ticket"]'
buttonConfirm = 'button[data-cy="button-confirm"]'
creationDateFromFilter = 'div[data-cy="filters-creation-date-from"]'
creationDateToFilter = 'div[data-cy="filters-creation-date-to"]'
statusFilter = 'div[data-cy="filters-status"]'
Expand Down Expand Up @@ -210,3 +212,9 @@ def getButtonSetUrgency(self) -> WebElement:

def getButtonAddNote(self) -> WebElement:
return self.wait_for(self.buttonAddNote)

def getButtonCloseTicket(self) -> WebElement:
return self.wait_for(self.buttonCloseTicket)

def getButtonConfirm(self) -> WebElement:
return self.wait_for(self.buttonConfirm)
Loading