Skip to content

Commit 5a1bfb0

Browse files
Addressing PR review comments
1 parent 9267b58 commit 5a1bfb0

File tree

1 file changed

+130
-10
lines changed

1 file changed

+130
-10
lines changed

docs/RepositoryGuide.md

Lines changed: 130 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,21 @@ Please refer to the list below for all available POMs in this repository.
179179
To use a POM in a test, instantiate the page object and call its methods:
180180

181181
```python
182-
from pages.login.login_page import LoginPage
183-
184-
def test_user_can_login(page):
185-
login_page = LoginPage(page)
186-
login_page.navigate()
187-
login_page.login("[email protected]", "securepassword")
188-
assert login_page.is_logged_in()
182+
from pages.screening_subject_search.subject_screening_search_page import (
183+
SubjectScreeningPage,
184+
SearchAreaSearchOptions,
185+
)
186+
187+
def test_search_user_by_nhs_number(page):
188+
nhs_number = "1234567890"
189+
SubjectScreeningPage(page).click_clear_filters_button()
190+
SubjectScreeningPage(page).click_episodes_filter()
191+
SubjectScreeningPage(page).nhs_number_filter.fill(nhs_number)
192+
SubjectScreeningPage(page).nhs_number_filter.press("Tab")
193+
SubjectScreeningPage(page).select_search_area_option(
194+
SearchAreaSearchOptions.SEARCH_AREA_WHOLE_DATABASE.value
195+
)
196+
SubjectScreeningPage(page).click_search_button()
189197
```
190198

191199
---
@@ -369,6 +377,68 @@ These include:
369377

370378
---
371379

380+
#### When to Use
381+
382+
Use these classes whenever you need to interact with core domain objects or perform database operations in your tests.
383+
For example, when setting up test data, verifying database state after UI actions, or retrieving specific attributes for assertions.
384+
385+
#### Why Use
386+
387+
- They encapsulate business logic and data access, making tests cleaner and easier to maintain.
388+
- They provide a consistent interface for interacting with the system under test.
389+
- Repositories abstract away SQL/database details, allowing you to focus on test logic.
390+
391+
#### How to Use
392+
393+
- Instantiate the class or repository in your test.
394+
- Call the relevant methods to fetch, create, update, or verify data.
395+
396+
Example usage in a test:
397+
398+
```python
399+
from classes.repositories.subject_repository import SubjectRepository
400+
from classes.person.person import Person
401+
402+
def test_subject_exists_in_db():
403+
repo = SubjectRepository()
404+
nhs_number = "1234567890"
405+
assert repo.find_by_nhs_number(nhs_number)
406+
407+
def test_person_attributes():
408+
person = Person(name="John Doe", dob="1980-01-01")
409+
assert person.name == "John Doe"
410+
```
411+
412+
You can also use repositories to set up test data before running UI tests, or to verify that changes made in the UI are reflected in the database.
413+
414+
---
415+
416+
#### Why Use Repositories?
417+
418+
Repositories are used to abstract and encapsulate all database access and query logic for a specific domain (e.g., subjects, episodes, users).<br>
419+
This pattern helps keep your test code clean, maintainable, and focused on business logic rather than SQL or data access details.
420+
By using repositories, you can:
421+
422+
- Centralise and reuse query logic across tests.
423+
- Reduce duplication and improve maintainability.
424+
425+
---
426+
427+
#### Example: Using a Repository in a Test
428+
429+
```python
430+
from classes.repositories.subject_repository import SubjectRepository
431+
432+
def test_subject_exists_in_db():
433+
repo = SubjectRepository()
434+
nhs_number = "1234567890"
435+
assert repo.find_by_nhs_number(nhs_number)
436+
```
437+
438+
You can also use repositories to fetch or update domain objects, set up test data, or verify database state after UI actions.
439+
440+
---
441+
372442
### Class Descriptions
373443

374444
- **address/**: Models address data and types.
@@ -423,9 +493,59 @@ These include:
423493

424494
### Common Patterns
425495

426-
- **Repository Pattern**: Used for DB access and data management (e.g., `SubjectRepository`, `PersonRepository`).
427-
- **Factory Pattern**: Used in data creation utilities for generating test data.
428-
- **Singleton Pattern**: Used for configuration or shared resources (where applicable).
496+
- **Repository Pattern**
497+
Used for DB access and data management (e.g., `SubjectRepository`, `PersonRepository`).
498+
499+
**Example:**
500+
501+
```python
502+
from classes.repositories.subject_repository import SubjectRepository
503+
504+
repo = SubjectRepository()
505+
subject = repo.find_by_nhs_number("1234567890")
506+
```
507+
508+
**Benefits:**
509+
510+
- Centralizes data access logic
511+
- Makes tests and business logic independent of database details
512+
- Improves maintainability and testability
513+
514+
- **Factory Pattern**
515+
Used in data creation utilities for generating test data.
516+
517+
**Example:**
518+
519+
```python
520+
from classes.data.data_creation import DataFactory
521+
522+
test_subject = DataFactory.create_subject(age=45, status="Active")
523+
```
524+
525+
**Benefits:**
526+
527+
- Simplifies creation of complex objects
528+
- Promotes reuse and consistency in test data setup
529+
- Makes it easy to vary object attributes for different test scenarios
530+
531+
- **Singleton Pattern**
532+
533+
Used for configuration or shared resources (where applicable).
534+
535+
**Example:**
536+
537+
```python
538+
from utils.load_properties import PropertiesLoader
539+
540+
config = PropertiesLoader.get_instance()
541+
value = config.get("some_property")
542+
```
543+
544+
**Benefits:**
545+
546+
- Ensures a single, shared instance for configuration or resources
547+
- Reduces memory usage and avoids conflicting state
548+
- Makes global settings easy to access and update
429549

430550
---
431551

0 commit comments

Comments
 (0)