-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add simple notifications test, add page objects for test #27096
Changes from 24 commits
567c991
89b6f49
f0e999c
4a1f27d
37268cd
049afbb
a717b01
7b98884
c9869bd
2e25f51
7bf5969
d7129ea
c1bdb49
8e40790
f8b2c81
f1cf41a
ce892c5
4423794
0d821e2
8714172
c7f7fb2
84e6b68
aa86704
914d372
57f4446
15ab081
3b01e86
8420d5b
63de77a
09e9f2b
8cf86a7
63aa7c1
c50fb47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Driver } from '../../webdriver/driver'; | ||
import FirstTimeTurnOnNotificationsModal from '../pages/notifications/first-time-turn-on-modal'; | ||
import HeaderNavbar from '../pages/header-navbar'; | ||
|
||
/** | ||
* This function enables the notifications through the header options menu from the home page | ||
* | ||
* Note: this flow focuses on the journey of a user who is enabling this feature for the first time | ||
* | ||
* @param driver - The webdriver instance. | ||
*/ | ||
export const enableNotificationsFirstTime = async ( | ||
driver: Driver, | ||
): Promise<void> => { | ||
console.log(`Start enable notifications from home screen`); | ||
const header = new HeaderNavbar(driver); | ||
await header.goToNotifiationsList(); | ||
|
||
const turnOnNotificationsModal = new FirstTimeTurnOnNotificationsModal( | ||
driver, | ||
); | ||
await turnOnNotificationsModal.check_pageIsLoaded(); | ||
await turnOnNotificationsModal.clickTurnOnNotifications(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Driver } from '../../webdriver/driver'; | ||
|
||
class AccountOptionsMenu { | ||
private driver: Driver; | ||
|
||
private readonly notificationsMenuItem = | ||
'[data-testid="notifications-menu-item"]'; | ||
|
||
constructor(driver: Driver) { | ||
this.driver = driver; | ||
} | ||
|
||
async clickNotificationsMenuItem(): Promise<void> { | ||
await this.driver.clickElement(this.notificationsMenuItem); | ||
} | ||
} | ||
|
||
export default AccountOptionsMenu; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
import { Driver } from '../../webdriver/driver'; | ||
import AccountOptionsMenu from './account-options-menu'; | ||
|
||
class HeaderNavbar { | ||
private driver: Driver; | ||
|
||
private accountMenuButton: string; | ||
|
||
private accountOptionMenu: string; | ||
private accountOptionsMenuButton: string; | ||
|
||
private lockMetaMaskButton: string; | ||
|
||
private accountOptionsMenu: AccountOptionsMenu; | ||
|
||
constructor(driver: Driver) { | ||
this.driver = driver; | ||
this.accountMenuButton = '[data-testid="account-menu-icon"]'; | ||
this.accountOptionMenu = '[data-testid="account-options-menu-button"]'; | ||
this.lockMetaMaskButton = '[data-testid="global-menu-lock"]'; | ||
this.accountMenuButton = '[data-testid="account-menu-icon"]'; | ||
this.accountOptionsMenuButton = | ||
'[data-testid="account-options-menu-button"]'; | ||
this.accountOptionsMenu = new AccountOptionsMenu(driver); | ||
} | ||
|
||
async openAccountMenu(): Promise<void> { | ||
await this.driver.clickElement(this.accountMenuButton); | ||
} | ||
|
||
async openAccountOptionsMenu(): Promise<void> { | ||
await this.driver.clickElement(this.accountOptionsMenuButton); | ||
} | ||
|
||
async lockMetaMask(): Promise<void> { | ||
await this.driver.clickElement(this.accountOptionMenu); | ||
await this.openAccountOptionsMenu(); | ||
await this.driver.clickElement(this.lockMetaMaskButton); | ||
} | ||
|
||
async goToNotifiationsList(): Promise<void> { | ||
this.openAccountOptionsMenu(); | ||
this.accountOptionsMenu.clickNotificationsMenuItem(); | ||
} | ||
} | ||
|
||
export default HeaderNavbar; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { strict as assert } from 'assert'; | |
import { Driver } from '../../webdriver/driver'; | ||
import { DEFAULT_GANACHE_ETH_BALANCE_DEC } from '../../constants'; | ||
import HeaderNavbar from './header-navbar'; | ||
import AccountOptionsMenu from './account-options-menu'; | ||
|
||
class HomePage { | ||
private driver: Driver; | ||
|
@@ -24,9 +25,12 @@ class HomePage { | |
|
||
public headerNavbar: HeaderNavbar; | ||
|
||
public accountOptionsMenu: AccountOptionsMenu; | ||
|
||
constructor(driver: Driver) { | ||
this.driver = driver; | ||
this.headerNavbar = new HeaderNavbar(driver); | ||
this.accountOptionsMenu = new AccountOptionsMenu(driver); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we will not create |
||
this.sendButton = '[data-testid="eth-overview-send"]'; | ||
this.activityTab = '[data-testid="account-overview__activity-tab"]'; | ||
this.tokensTab = '[data-testid="account-overview__asset-tab"]'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Driver } from '../../../webdriver/driver'; | ||
|
||
class FirstTimeTurnOnNotificationsModal { | ||
private driver: Driver; | ||
|
||
private readonly turnOnButton = | ||
'[data-testid="turn-on-notifications-button"]'; | ||
|
||
constructor(driver: Driver) { | ||
this.driver = driver; | ||
} | ||
|
||
async check_pageIsLoaded(): Promise<void> { | ||
try { | ||
await this.driver.waitForSelector(this.turnOnButton); | ||
} catch (e) { | ||
console.log( | ||
'Timeout while waiting for TurnOnNotificationsModal to be loaded', | ||
e, | ||
); | ||
throw e; | ||
} | ||
console.log('TurnOnNotificationsModal is loaded'); | ||
} | ||
|
||
async clickTurnOnNotifications(): Promise<void> { | ||
await this.driver.clickElement(this.turnOnButton); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
} | ||
|
||
export default FirstTimeTurnOnNotificationsModal; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Driver } from '../../../webdriver/driver'; | ||
|
||
class NotificationsListPage { | ||
private driver: Driver; | ||
|
||
private readonly backButton = '[data-testid="back-button"]'; | ||
|
||
private readonly notificationsSettingsButton = | ||
'[data-testid="notifications-settings-button"]'; | ||
|
||
private readonly noNotificationsReceivedPlaceholder = | ||
'[data-testid="notifications-list-placeholder"]'; | ||
|
||
constructor(driver: Driver) { | ||
this.driver = driver; | ||
} | ||
|
||
async check_pageIsLoaded(): Promise<void> { | ||
try { | ||
await this.driver.waitForMultipleSelectors([ | ||
this.backButton, | ||
this.notificationsSettingsButton, | ||
]); | ||
} catch (e) { | ||
console.log( | ||
'Timeout while waiting for notifications list page to be loaded', | ||
e, | ||
); | ||
throw e; | ||
} | ||
console.log('Notifications list page is loaded'); | ||
} | ||
|
||
async check_noNotificationsReceived(): Promise<void> { | ||
chloeYue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
await this.driver.waitForSelector( | ||
this.noNotificationsReceivedPlaceholder, | ||
); | ||
} catch (e) { | ||
console.log( | ||
'Timed out while waiting for the empty notifications list placeholder to be displayed', | ||
e, | ||
); | ||
} | ||
console.log('Notifications list is empty as expected'); | ||
} | ||
} | ||
|
||
export default NotificationsListPage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { | ||
withFixtures, | ||
logInWithBalanceValidation, | ||
defaultGanacheOptions, | ||
} from '../../helpers'; | ||
import { enableNotificationsFirstTime } from '../../page-objects/flows/enable-notifications'; | ||
import FixtureBuilder from '../../fixture-builder'; | ||
import NotificationsListPage from '../../page-objects/pages/notifications/notifications-list'; | ||
import { mockNotificationServices } from './mocks'; | ||
|
||
describe('Notifications', function () { | ||
describe('from inside MetaMask', function () { | ||
it('enables notifications for the first time', async function () { | ||
await withFixtures( | ||
{ | ||
fixtures: new FixtureBuilder().build(), | ||
ganacheOptions: defaultGanacheOptions, | ||
title: this.test?.fullTitle(), | ||
testSpecificMock: mockNotificationServices, | ||
}, | ||
async ({ driver, ganacheServer }) => { | ||
await logInWithBalanceValidation(driver, ganacheServer); | ||
await enableNotificationsFirstTime(driver); | ||
|
||
// should land on notifications list | ||
const notificationsListPage = new NotificationsListPage(driver); | ||
await notificationsListPage.check_pageIsLoaded(); | ||
await notificationsListPage.check_noNotificationsReceived(); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this implementation, for notifications, we use
clickNotificationsMenuItem
in theAccountOptionsMenu
page, but we clicklockMetaMaskButton
using the selectors in theheader-navbar
page directly. However, thenotificationsMenuItem
and thelockMetaMaskButton
are on the same modal, which creates inconsistency. I suggest that we don't create a new page class forAccountOptionsMenu
because it only has a few buttons without complex interactions onAccountOptionsMenu
. We can just add thenotificationsMenuItem
selector in theheader-navbar
page and click on it directly here. This provides an easier implementation.