Skip to content

Commit a784a06

Browse files
authored
Merge pull request #79 from itk-dev-rpa/feature/case_approval
Added functions for approving, checking and noting cases
2 parents 6107440 + 5cfd507 commit a784a06

File tree

3 files changed

+99
-6
lines changed

3 files changed

+99
-6
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Added functionality for approving, checking approval status and noting cases
13+
1014
## [2.6.1] - 2024-09-04
1115

1216
### Fixed - 2024-09-04

itk_dev_shared_components/eflyt/eflyt_case.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from selenium import webdriver
66
from selenium.webdriver.common.by import By
7+
from selenium.webdriver.common.keys import Keys
78

89

910
@dataclass
@@ -126,3 +127,69 @@ def change_tab(browser: webdriver.Chrome, tab_index: int):
126127

127128
if current_index != tab_index:
128129
browser.execute_script(f"__doPostBack('ctl00$ContentPlaceHolder2$ptFanePerson$ImgJournalMap','{tab_index}')")
130+
131+
132+
def approve_case(browser: webdriver.Chrome):
133+
"""Approve a case, even if blocked by a note."""
134+
change_tab(browser, 0)
135+
136+
deadline_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadline")
137+
deadline_field.clear()
138+
note_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadlineNote")
139+
note_field.clear()
140+
141+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click()
142+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes").click()
143+
144+
approve_persons_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkendAlle")
145+
if not approve_persons_button.is_enabled():
146+
147+
person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons")
148+
rows = person_table.find_elements(By.TAG_NAME, "tr")
149+
rows.pop(0)
150+
151+
for row in rows:
152+
row.find_element(By.XPATH, "td[2]").click()
153+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click()
154+
approve_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes")
155+
if approve_button.is_displayed():
156+
approve_button.click()
157+
else:
158+
approve_persons_button.click()
159+
160+
161+
def check_all_approved(browser: webdriver.Chrome) -> bool:
162+
"""Check all inhabiatants in table have a status 'Godkendt'.
163+
"""
164+
person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons")
165+
rows = person_table.find_elements(By.TAG_NAME, "tr")
166+
rows.pop(0)
167+
168+
for row in rows:
169+
row_status = row.find_element(By.XPATH, "td[6]").text
170+
if row_status != "Godkendt":
171+
return False
172+
return True
173+
174+
175+
def add_note(browser: webdriver.Chrome, message: str):
176+
"""Add a note to a case."""
177+
message = f"{date.today().strftime('%Y-%m-%d')} Besked fra Robot: {message}"
178+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
179+
180+
existing_note = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text
181+
if len(existing_note) > 0:
182+
message = "\n\n" + message
183+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(Keys.CONTROL+Keys.END)
184+
185+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(message)
186+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLongNoteUpdater").click()
187+
188+
189+
def get_note_text(browser: webdriver.Chrome) -> str:
190+
"""Read note text and close the window, returning the value.
191+
"""
192+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
193+
text = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text
194+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLuk").click()
195+
return text

tests/test_eflyt/test_case.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from dotenv import load_dotenv
88
from selenium.webdriver.common.by import By
99

10-
from itk_dev_shared_components.eflyt.eflyt_login import login
11-
from itk_dev_shared_components.eflyt.eflyt_search import open_case
12-
from itk_dev_shared_components.eflyt import eflyt_case
10+
from itk_dev_shared_components.eflyt import eflyt_case, eflyt_login, eflyt_search
1311

1412
load_dotenv()
1513

@@ -21,12 +19,12 @@ class CaseTest(unittest.TestCase):
2119
def setUpClass(cls):
2220
"""Setup test class"""
2321
eflyt_credentials = os.getenv("EFLYT_LOGIN").split(",")
24-
cls.browser = login(eflyt_credentials[0], eflyt_credentials[1])
22+
cls.browser = eflyt_login.login(eflyt_credentials[0], eflyt_credentials[1])
2523

2624
def setUp(self):
2725
"""Go to a clean case state"""
2826
test_case = os.getenv("TEST_CASE")
29-
open_case(self.browser, test_case)
27+
eflyt_search.open_case(self.browser, test_case)
3028

3129
def test_get_beboere(self):
3230
"""Test inhabitant functions"""
@@ -44,7 +42,7 @@ def test_get_beboere(self):
4442
for relation in inhabitant.relations:
4543
self.assertRegex(relation, r"\d{6}-\d{4}")
4644

47-
open_case(self.browser, test_no_inhabitants_case)
45+
eflyt_search.open_case(self.browser, test_no_inhabitants_case)
4846
inhabitants = eflyt_case.get_beboere(self.browser)
4947

5048
self.assertEqual(len(inhabitants), 0, "Some inhabitants found when none was expected")
@@ -74,6 +72,30 @@ def test_get_room_count(self):
7472
self.assertIsInstance(room_count, int, "Room count is not a number")
7573
self.assertGreater(room_count, 0, "Room count is less than 1")
7674

75+
def test_write_note(self):
76+
"""Test writing a note to a case. Check if the note is added and that the existing note is preserved.
77+
"""
78+
existing_note = eflyt_case.get_note_text(self.browser)
79+
80+
note_text = "Test"
81+
eflyt_case.add_note(self.browser, note_text)
82+
83+
new_note = eflyt_case.get_note_text(self.browser)
84+
85+
# Reset note to original text
86+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
87+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").clear()
88+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(existing_note)
89+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLongNoteUpdater").click()
90+
91+
self.assertNotEqual(existing_note, new_note)
92+
self.assertEqual(existing_note, new_note[:len(existing_note)])
93+
self.assertEqual(note_text, new_note[-len(note_text):])
94+
95+
@unittest.skip("No test system available for approving dummy cases.")
96+
def test_approve_case(self):
97+
"""Empty test for approve_case"""
98+
7799

78100
if __name__ == '__main__':
79101
unittest.main()

0 commit comments

Comments
 (0)