diff --git a/e2e-testing.md b/e2e-testing.md index e74dcaf..c8b6c1a 100644 --- a/e2e-testing.md +++ b/e2e-testing.md @@ -22,8 +22,9 @@ - [4.1 One assertion per one test step method](#41-one-assertion-per-one-test-step-method) - [4.2 Use expect for assertions](#42-use-expect-for-assertions) - [5\. Files naming](#3-files-naming) - - [5.1. Name test files without should at the beggining](#51-name-test-files-without-should-at-the-beggining) - + - [5.1. Name test files without should at the beginning](#51-name-test-files-without-should-at-the-beggining) +- [6\. Class methods with conditional logic](#6-class-methods-with-conditional-logic) + - [6.1. Use ternary operator for conditional logic ](#61-use-ternary-operator-for-conditional-logic) 1\. Factory classes -------------- @@ -517,3 +518,43 @@ To make file name shorter, try to avoid using the `should` word at the beginning - `shouldBeAbleToEditOwnUserProfile` > `editOwnUserProfile` - `shouldBeAbleToChangeTheCourse` > `courseChanging` - `shouldUpdateUsername` > `updateUsername` + +6\. Class methods with conditional logic +-------------- + +#### 6.1. Use ternary operator for conditional logic + +Use ternary operator for conditional logic instead of if-else statement because it's more concise and readable. + +```typescript +// ❌ not recommended +export class CourseViewPage extends LMSEditorBasePage { + async assertModuleListItemIsVisible(name?: string): Promise { + await test.step('Assert module list item is visible', async () => { + if (name) { + const moduleListItem = this.listItem.filter({hasText: name}); + + await expect(moduleListItem).toBeVisible(); + + return; + } + + await expect(this.listItem).toBeVisible(); + }); + } +} + +// ✅ recommended +export class CourseViewPage extends LMSEditorBasePage { + async assertModuleListItemIsVisible(name?: string): Promise { + await test.step('Assert module list item is visible', async () => { + const moduleListItem = name + ? this.listItem.filter({hasText: name}) + : this.listItem; + + await expect(moduleListItem).toBeVisible(); + }); + } +} + +```