Skip to content

Commit

Permalink
Focus test for Element
Browse files Browse the repository at this point in the history
  • Loading branch information
tomuli committed Oct 3, 2024
1 parent 05fbb31 commit 23f63f6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions frontend/src/e2e-test/pages/citizen/citizen-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ export default class CitizenMessagesPage {
.assertTextEquals(content)
}

async assertNewMessageButtonIsFocused() {
await this.newMessageButton.assertFocused(true)
}

async assertAriaLiveExistsAndIncludesNotification() {
await this.page
.findByDataQa('notification-container')
Expand Down
1 change: 1 addition & 0 deletions frontend/src/e2e-test/specs/7_messaging/messaging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ describe('Sending and receiving messages', () => {
)
await citizenMessagesPage.assertAriaLiveExistsAndIncludesNotification()
await citizenMessagesPage.assertTimedNotification('Viesti lähetetty')
await citizenMessagesPage.assertNewMessageButtonIsFocused()
})

test('Citizen with shift care child can send attachments', async () => {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/e2e-test/utils/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ export class Element {
async evaluate<R>(fn: (el: HTMLElement | SVGElement) => R): Promise<R> {
return this.locator.evaluate(fn)
}

get focused(): Promise<boolean> {
return this.locator.evaluate((el) => el === document.activeElement)
}
async assertFocused(focused: boolean): Promise<void> {
await waitUntilEqual(() => this.focused, focused)
}
}

export class TextInput extends Element {
Expand Down

0 comments on commit 23f63f6

Please sign in to comment.