Skip to content

Commit

Permalink
Various e2e test fixes (#3284)
Browse files Browse the repository at this point in the history
* Just use the first picture every time

* Add missing testIDs

* Various test fixes

* Use simplified link fetcher for e2e

* Disable tests for now-n

* Update test-env creation
  • Loading branch information
pfrazee authored Mar 20, 2024
1 parent a90566d commit 54f424d
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 19 deletions.
4 changes: 2 additions & 2 deletions __e2e__/tests/curate-lists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Curate lists', () => {
await element(by.text('Edit list details')).tap()
await expect(element(by.id('createOrEditListModal'))).toBeVisible()
await element(by.id('changeAvatarBtn')).tap()
await element(by.text('Library')).tap()
await element(by.text('Upload from Library')).tap()
await sleep(3e3)
await element(by.id('saveBtn')).tap()
await expect(element(by.id('createOrEditListModal'))).not.toBeVisible()
Expand All @@ -81,7 +81,7 @@ describe('Curate lists', () => {
await element(by.text('Edit list details')).tap()
await expect(element(by.id('createOrEditListModal'))).toBeVisible()
await element(by.id('changeAvatarBtn')).tap()
await element(by.text('Remove')).tap()
await element(by.text('Remove Avatar')).tap()
await element(by.id('saveBtn')).tap()
await expect(element(by.id('createOrEditListModal'))).not.toBeVisible()
await expect(element(by.id('userAvatarFallback'))).toExist()
Expand Down
2 changes: 1 addition & 1 deletion __e2e__/tests/home-screen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Home screen', () => {

it('Can go to feeds page using feeds button in tab bar', async () => {
await element(by.id('homeScreenFeedTabs-Feeds ✨')).tap()
await expect(element(by.text('Discover new feeds'))).toBeVisible()
await expect(element(by.text('Discover New Feeds'))).toBeVisible()
})

it('Feeds button disappears after pinning a feed', async () => {
Expand Down
8 changes: 4 additions & 4 deletions __e2e__/tests/profile-screen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ describe('Profile screen', () => {
await element(by.id('profileHeaderEditProfileButton')).tap()
await expect(element(by.id('editProfileModal'))).toBeVisible()
await element(by.id('changeBannerBtn')).tap()
await element(by.text('Library')).tap()
await element(by.text('Upload from Library')).tap()
await sleep(3e3)
await element(by.id('changeAvatarBtn')).tap()
await element(by.text('Library')).tap()
await element(by.text('Upload from Library')).tap()
await sleep(3e3)
await element(by.id('editProfileSaveBtn')).tap()
await expect(element(by.id('editProfileModal'))).not.toBeVisible()
Expand All @@ -87,9 +87,9 @@ describe('Profile screen', () => {
await element(by.id('profileHeaderEditProfileButton')).tap()
await expect(element(by.id('editProfileModal'))).toBeVisible()
await element(by.id('changeBannerBtn')).tap()
await element(by.text('Remove')).tap()
await element(by.text('Remove Banner')).tap()
await element(by.id('changeAvatarBtn')).tap()
await element(by.text('Remove')).tap()
await element(by.text('Remove Avatar')).tap()
await element(by.id('editProfileSaveBtn')).tap()
await expect(element(by.id('editProfileModal'))).not.toBeVisible()
await expect(element(by.id('userBannerFallback'))).toExist()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Create account', () => {
})

it('I can create a new account with text verification', async () => {
console.log('SERVICE IS', service)
await element(by.id('e2eOpenLoggedOutView')).tap()

await element(by.id('createAccountButton')).tap()
Expand All @@ -28,17 +29,18 @@ describe('Create account', () => {
await device.takeScreenshot('4- entered account details')
await element(by.id('nextBtn')).tap()

await element(by.id('handleInput')).typeText('text-verification-test')
await device.takeScreenshot('5- entered handle')
await element(by.id('nextBtn')).tap()

await element(by.id('phoneInput')).typeText('8042221111')
await element(by.id('requestCodeBtn')).tap()
await device.takeScreenshot('5- requested code')
await device.takeScreenshot('6- requested code')

await element(by.id('codeInput')).typeText('000000')
await device.takeScreenshot('6- entered code')
await device.takeScreenshot('7- entered code')
await element(by.id('nextBtn')).tap()

await element(by.id('handleInput')).typeText('text-verification-test')
await device.takeScreenshot('7- entered handle')

await element(by.id('nextBtn')).tap()

await expect(element(by.id('onboardingInterests'))).toBeVisible()
Expand Down
36 changes: 33 additions & 3 deletions jest/test-pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function createServer(
const phoneParams = phoneRequired
? {
phoneVerificationRequired: true,
phoneVerificationProvider: 'twilio',
twilioAccountSid: 'ACXXXXXXX',
twilioAuthToken: 'AUTH',
twilioServiceSid: 'VAXXXXXXXX',
Expand All @@ -95,6 +96,35 @@ export async function createServer(
})
mockTwilio(testNet.pds)

// add the test mod authority
if (!phoneRequired) {
const agent = new BskyAgent({service: pdsUrl})
const res = await agent.api.com.atproto.server.createAccount({
email: '[email protected]',
handle: 'mod-authority.test',
password: 'hunter2',
})
agent.api.setHeader('Authorization', `Bearer ${res.data.accessJwt}`)
await agent.api.app.bsky.actor.profile.create(
{repo: res.data.did},
{
displayName: 'Dev-env Moderation',
description: `The pretend version of mod.bsky.app`,
},
)

await agent.api.app.bsky.labeler.service.create(
{repo: res.data.did, rkey: 'self'},
{
policies: {
labelValues: ['!hide', '!warn'],
labelValueDefinitions: [],
},
createdAt: new Date().toISOString(),
},
)
}

const pic = fs.readFileSync(
path.join(__dirname, '..', 'assets', 'default-avatar.png'),
)
Expand Down Expand Up @@ -455,13 +485,13 @@ async function getPort(start = 3000) {
}

export const mockTwilio = (pds: TestPds) => {
if (!pds.ctx.twilio) return
if (!pds.ctx.phoneVerifier) return

pds.ctx.twilio.sendCode = async (_number: string) => {
pds.ctx.phoneVerifier.sendCode = async (_number: string) => {
// do nothing
}

pds.ctx.twilio.verifyCode = async (_number: string, code: string) => {
pds.ctx.phoneVerifier.verifyCode = async (_number: string, code: string) => {
return code === '000000'
}
}
3 changes: 1 addition & 2 deletions src/lib/media/picker.e2e.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import RNFS from 'react-native-fs'
import {CropperOptions} from './types'
import {compressIfNeeded} from './manip'

let _imageCounter = 0
async function getFile() {
let files = await RNFS.readDir(
RNFS.LibraryDirectoryPath.split('/')
Expand All @@ -12,7 +11,7 @@ async function getFile() {
.join('/'),
)
files = files.filter(file => file.path.endsWith('.JPG'))
const file = files[_imageCounter++ % files.length]
const file = files[0]
return await compressIfNeeded({
path: file.path,
mime: 'image/jpeg',
Expand Down
45 changes: 45 additions & 0 deletions src/view/com/composer/useExternalLinkFetch.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {useState, useEffect} from 'react'
import * as apilib from 'lib/api/index'
import {getLinkMeta} from 'lib/link-meta/link-meta'
import {ComposerOpts} from 'state/shell/composer'
import {getAgent} from '#/state/session'

export function useExternalLinkFetch({}: {
setQuote: (opts: ComposerOpts['quote']) => void
}) {
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
undefined,
)

useEffect(() => {
let aborted = false
const cleanup = () => {
aborted = true
}
if (!extLink) {
return cleanup
}
if (!extLink.meta) {
getLinkMeta(getAgent(), extLink.uri).then(meta => {
if (aborted) {
return
}
setExtLink({
uri: extLink.uri,
isLoading: !!meta.image,
meta,
})
})
return cleanup
}
if (extLink.isLoading) {
setExtLink({
...extLink,
isLoading: false, // done
})
}
return cleanup
}, [extLink])

return {extLink, setExtLink}
}
5 changes: 4 additions & 1 deletion src/view/com/util/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,10 @@ let EditableUserAvatar = ({
<Menu.Root>
<Menu.Trigger label={_(msg`Edit avatar`)}>
{({props}) => (
<TouchableOpacity {...props} activeOpacity={0.8}>
<TouchableOpacity
{...props}
activeOpacity={0.8}
testID="changeAvatarBtn">
{avatar ? (
<HighPriorityImage
testID="userAvatarImage"
Expand Down
5 changes: 4 additions & 1 deletion src/view/com/util/UserBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export function UserBanner({
<Menu.Root>
<Menu.Trigger label={_(msg`Edit avatar`)}>
{({props}) => (
<TouchableOpacity {...props} activeOpacity={0.8}>
<TouchableOpacity
{...props}
activeOpacity={0.8}
testID="changeBannerBtn">
{banner ? (
<Image
testID="userBannerImage"
Expand Down

0 comments on commit 54f424d

Please sign in to comment.