From f4891a47a17cdcd35751867153f73350c90a8f72 Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Tue, 15 Aug 2023 09:59:49 -0700 Subject: [PATCH] Fix to feeds view in profiles (#1171) * Fix load of feeds tab * Add e2e test for profile feeds --- __e2e__/mock-server.ts | 4 ++++ __e2e__/tests/profile-screen.test.ts | 8 +++++++- jest/test-pds.ts | 27 ++++++++++++++++++++++++++- src/state/models/ui/profile.ts | 23 ++++++++--------------- src/view/com/feeds/CustomFeed.tsx | 1 + 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/__e2e__/mock-server.ts b/__e2e__/mock-server.ts index 0a97dbcd..44d33bc3 100644 --- a/__e2e__/mock-server.ts +++ b/__e2e__/mock-server.ts @@ -53,6 +53,10 @@ async function main() { await server.mocker.users[user].agent.post({text: 'Post'}) } } + if ('feeds' in url.query) { + console.log('Generating mock feed') + await server.mocker.createFeed('alice') + } if ('thread' in url.query) { console.log('Generating mock posts') const res = await server.mocker.users.bob.agent.post({ diff --git a/__e2e__/tests/profile-screen.test.ts b/__e2e__/tests/profile-screen.test.ts index 7d2b5c36..59b7326b 100644 --- a/__e2e__/tests/profile-screen.test.ts +++ b/__e2e__/tests/profile-screen.test.ts @@ -5,7 +5,7 @@ import {openApp, login, createServer, sleep} from '../util' describe('Profile screen', () => { let service: string beforeAll(async () => { - service = await createServer('?users&posts') + service = await createServer('?users&posts&feeds') await openApp({ permissions: {notifications: 'YES', medialibrary: 'YES', photos: 'YES'}, }) @@ -17,6 +17,12 @@ describe('Profile screen', () => { await element(by.id('bottomBarProfileBtn')).tap() }) + it('Can see feeds', async () => { + await element(by.id('selector-3')).tap() + await expect(element(by.id('feed-alices feed'))).toBeVisible() + await element(by.id('selector-0')).tap() + }) + it('Open and close edit profile modal', async () => { await element(by.id('profileHeaderEditProfileButton')).tap() await expect(element(by.id('editProfileModal'))).toBeVisible() diff --git a/jest/test-pds.ts b/jest/test-pds.ts index 48b73e84..0c9d946f 100644 --- a/jest/test-pds.ts +++ b/jest/test-pds.ts @@ -2,7 +2,7 @@ import net from 'net' import path from 'path' import fs from 'fs' import {TestPds as DevEnvTestPDS, TestNetworkNoAppView} from '@atproto/dev-env' -import {BskyAgent} from '@atproto/api' +import {AtUri, BskyAgent} from '@atproto/api' export interface TestUser { email: string @@ -212,6 +212,31 @@ class Mocker { return await agent.like(uri, cid) } + async createFeed(user: string) { + const agent = this.users[user]?.agent + if (!agent) { + throw new Error(`Not a user: ${user}`) + } + const fg1Uri = AtUri.make( + this.users[user].did, + 'app.bsky.feed.generator', + 'alice-favs', + ) + const avatarRes = await agent.api.com.atproto.repo.uploadBlob(this.pic, { + encoding: 'image/png', + }) + return await agent.api.app.bsky.feed.generator.create( + {repo: this.users[user].did, rkey: fg1Uri.rkey}, + { + did: 'did:web:fake.com', + displayName: 'alices feed', + description: 'all my fav stuff', + avatar: avatarRes.data.blob, + createdAt: new Date().toISOString(), + }, + ) + } + async createInvite(forAccount: string) { const agent = new BskyAgent({service: this.agent.service}) await agent.api.com.atproto.server.createInviteCode( diff --git a/src/state/models/ui/profile.ts b/src/state/models/ui/profile.ts index a8c8ec0a..9dae09ec 100644 --- a/src/state/models/ui/profile.ts +++ b/src/state/models/ui/profile.ts @@ -114,32 +114,25 @@ export class ProfileUiModel { }, ]) } else { - // not loading, no error, show content if ( this.selectedView === Sections.PostsNoReplies || this.selectedView === Sections.PostsWithReplies || - this.selectedView === Sections.PostsWithMedia || - this.selectedView === Sections.CustomAlgorithms + this.selectedView === Sections.PostsWithMedia ) { if (this.feed.hasContent) { - if (this.selectedView === Sections.CustomAlgorithms) { - arr = this.algos.feeds - } else if ( - this.selectedView === Sections.PostsNoReplies || - this.selectedView === Sections.PostsWithReplies || - this.selectedView === Sections.PostsWithMedia - ) { - arr = this.feed.slices.slice() - } else { - // posts with replies is also default - arr = this.feed.slices.slice() - } + arr = this.feed.slices.slice() if (!this.feed.hasMore) { arr = arr.concat([ProfileUiModel.END_ITEM]) } } else if (this.feed.isEmpty) { arr = arr.concat([ProfileUiModel.EMPTY_ITEM]) } + } else if (this.selectedView === Sections.CustomAlgorithms) { + if (this.algos.hasContent) { + arr = this.algos.feeds + } else if (this.algos.isEmpty) { + arr = arr.concat([ProfileUiModel.EMPTY_ITEM]) + } } else if (this.selectedView === Sections.Lists) { if (this.lists.hasContent) { arr = this.lists.lists diff --git a/src/view/com/feeds/CustomFeed.tsx b/src/view/com/feeds/CustomFeed.tsx index 79f1dd74..264c2d98 100644 --- a/src/view/com/feeds/CustomFeed.tsx +++ b/src/view/com/feeds/CustomFeed.tsx @@ -69,6 +69,7 @@ export const CustomFeed = observer( return ( {