Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
akdasa committed Dec 18, 2023
1 parent 425846a commit 52df03d
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 33 deletions.
5 changes: 5 additions & 0 deletions components/library/LibraryPage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Page } from '@playwright/test'
import { testId } from '@utils/testId'
import { VerseDetailsPage } from './VerseDetailsPage'


export class LibraryPage {
constructor(private readonly page: Page) {}

get verseDetails() {
return new VerseDetailsPage(this.page)
}

get searchbar() {
return this.page.getByPlaceholder('Search')
}
Expand Down
4 changes: 1 addition & 3 deletions components/shared/Application.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InboxDeckPage, ReviewDeckPage } from '@components/decks'
import { LibraryPage, VerseDetailsPage } from '@components/library'
import { LibraryPage } from '@components/library'
import { TabsBar } from '@components/shared'
import { TutorialOverlay } from '@components/tutorial'
import { Page } from '@playwright/test'
Expand All @@ -15,7 +15,6 @@ export interface ApplicationParams {

export class Application {
public readonly library: LibraryPage
public readonly verseDetails: VerseDetailsPage
public readonly tabs: TabsBar
public readonly inboxDeck: InboxDeckPage
public readonly reviewDeck: ReviewDeckPage
Expand All @@ -25,7 +24,6 @@ export class Application {
public readonly page: Page
) {
this.library = new LibraryPage(page)
this.verseDetails = new VerseDetailsPage(page)
this.inboxDeck = new InboxDeckPage(page)
this.tabs = new TabsBar(page)
this.reviewDeck = new ReviewDeckPage(page)
Expand Down
4 changes: 2 additions & 2 deletions scenarios/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Application } from "@components/shared"

export async function addVerseToInbox(app: Application, verse: string) {
await app.library.verse(verse).click()
await app.verseDetails.addButton.click()
await app.verseDetails.addButton.waitFor({ state: 'detached' })
await app.library.verseDetails.addButton.click()
await app.library.verseDetails.addButton.waitFor({ state: 'detached' })
}
50 changes: 41 additions & 9 deletions tests/inbox/InboxDeck.SwipeCards.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,80 @@ test.describe('Inbox Deck › Swipe Cards', () => {
await app.tabs.inboxTab.click()
})


/**
* Swiping a card left should put a card at the end of the inbox deck
*/
test('Swipe card left', async () => {
await app.inboxDeck.swipeCardLeft()

await expect(app.inboxDeck.getCard('BG 1.1', 'Text')).toHaveAttribute('data-index', '0')
await expect(app.inboxDeck.getCard('BG 1.1', 'Translation')).toHaveAttribute('data-index', '1')
await expect(app.tabs.inboxBadge).toContainText('2')
await expect(app.inboxDeck.getCard('BG 1.1', 'Text'))
.toHaveAttribute('data-index', '0')
await expect(app.inboxDeck.getCard('BG 1.1', 'Translation'))
.toHaveAttribute('data-index', '1')
await expect(app.tabs.inboxBadge) // No card removed from the inbox
.toContainText('2')
})

test('Cycle swipe card left', async () => {

/**
* Changing cards in the inbox deck must be looped
*/
test('Swipe cards in the loop', async () => {
await app.inboxDeck.swipeCardLeft()
await app.inboxDeck.swipeCardLeft()

await expect(app.inboxDeck.getCard('BG 1.1', 'Translation')).toHaveAttribute('data-index', '0')
await expect(app.inboxDeck.getCard('BG 1.1', 'Text')).toHaveAttribute('data-index', '1')
await expect(app.inboxDeck.getCard('BG 1.1', 'Translation'))
.toHaveAttribute('data-index', '0')
await expect(app.inboxDeck.getCard('BG 1.1', 'Text'))
.toHaveAttribute('data-index', '1')
})


/**
* Swiping a card up should remove a card from the inbox deck
*/
test('Swipe card up', async () => {
await app.inboxDeck.swipeCardUp()

await expect(app.tabs.inboxBadge).toContainText('1')
})

test('Review badge', async () => {

/**
* If the card has been memorized, a “Review” badge should appear
* next to the verse number in the library
*/
test('Memorize card', async () => {
await app.inboxDeck.swipeCardUp()
await app.tabs.libraryTab.click()
await expect(app.library.verseBadge('BG 1.1')).toHaveText('Review')
})

test('Swipe all cards up', async () => {

/**
* If user memorized all cards then:
* 1. The badge with the number of cards in the inbox deck should disappear
* 2. The "Inbox is empty" message should be visible
*/
test('Memorize all cards', async () => {
await app.inboxDeck.swipeCardUp()
await app.inboxDeck.swipeCardUp()

await expect(app.inboxDeck.inboxEmpty).toBeVisible()
await expect(app.tabs.inboxBadge).toBeHidden()
})


/**
* To swipe the card up, the user needs to move it a sufficient distance
*/
test('Move card up', async () => {
const distances = [40, 60, 120]

for (const distance of distances) {
await app.inboxDeck.swipeCardUp(distance, 25)
await expect(app.tabs.inboxBadge).toContainText('2')
await expect(app.tabs.inboxBadge).toContainText('2') // No, the card is not swiped up yet
}
})
})
3 changes: 3 additions & 0 deletions tests/inbox/InboxDeck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ test.describe('Inbox Deck', () => {
await app.open()
})

/**
* "Inbox is empty" message should be visible when there are cards in the inbox.
*/
test('Inbox is empty', async () => {
await app.tabs.inboxTab.click()
await expect(app.tabs.inboxEmpty).toBeVisible()
Expand Down
12 changes: 4 additions & 8 deletions tests/library/AddVerseToInbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,30 @@ test.describe('Library › Add verse to Inbox', () => {
await app.open()
})

test.afterEach(async ({ page }) => {
await page.close()
})


/* -------------------------------------------------------------------------- */
/* Tests */
/* -------------------------------------------------------------------------- */

test('Add verse to the Inbox deck', async () => {
await app.library.verse('BG 1.1').click()
await app.verseDetails.addButton.click()
await app.library.verseDetails.addButton.click()

await expect(app.library.verseBadge('BG 1.1')).toContainText('Inbox')
await expect(app.tabs.inboxBadge).toContainText('2')
})

test('Add button is disabled if verse has already been added', async () => {
await app.library.verse('BG 1.1').click()
await app.verseDetails.addButton.click()
await app.library.verseDetails.addButton.click()
await app.library.verse('BG 1.1').click()

await expect(app.verseDetails.addButton).toBeDisabled()
await expect(app.library.verseDetails.addButton).toBeDisabled()
})

test('Back returns to app.library', async () => {
await app.library.verse('BG 1.1').click()
await app.verseDetails.backButton.click()
await app.library.verseDetails.backButton.click()

await expect(app.library.searchbar).toBeVisible()
})
Expand Down
4 changes: 0 additions & 4 deletions tests/library/SearchVerses.Language.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ test.describe('Library › Search › Change language', () => {
await changeLanguage(app, 'Русский')
})

test.afterEach(async ({ page }) => {
page.close()
})


/* -------------------------------------------------------------------------- */
/* Tests */
Expand Down
5 changes: 0 additions & 5 deletions tests/library/SearchVerses.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ test.describe('Library › Search', () => {
await app.open()
})

test.afterEach(async ({ page }) => {
page.close()
})


/* -------------------------------------------------------------------------- */
/* Tests */
/* -------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion tests/tutorial/Tutorial.Full.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test.describe('Tutorial :: Full', () => {

await app.tutorial.card(2).waitFor()
await app.library.verse("BG 1.1").click()
await app.verseDetails.addButton.click()
await app.library.verseDetails.addButton.click()
await app.tabs.inboxTab.click()

await app.tutorial.card(6).waitFor()
Expand Down
2 changes: 1 addition & 1 deletion tests/tutorial/Tutorial.Library.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ test.describe('Tutorial :: Library', () => {
*/
test('Do not allow to open any verse but BG 1.1', async () => {
await app.library.verse("BG 2.13").click()
await expect(app.verseDetails.addButton).not.toBeVisible()
await expect(app.library.verseDetails.addButton).not.toBeVisible()
})
})

0 comments on commit 52df03d

Please sign in to comment.