about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-08-15 09:59:49 -0700
committerGitHub <noreply@github.com>2023-08-15 09:59:49 -0700
commitf4891a47a17cdcd35751867153f73350c90a8f72 (patch)
tree97d1a20437470ff1718561b3ec28e18865607c64
parenta3af2a2b850f5561d5a0b9504e0b6ea9aca07cb7 (diff)
downloadvoidsky-f4891a47a17cdcd35751867153f73350c90a8f72.tar.zst
Fix to feeds view in profiles (#1171)
* Fix load of feeds tab

* Add e2e test for profile feeds
-rw-r--r--__e2e__/mock-server.ts4
-rw-r--r--__e2e__/tests/profile-screen.test.ts8
-rw-r--r--jest/test-pds.ts27
-rw-r--r--src/state/models/ui/profile.ts23
-rw-r--r--src/view/com/feeds/CustomFeed.tsx1
5 files changed, 46 insertions, 17 deletions
diff --git a/__e2e__/mock-server.ts b/__e2e__/mock-server.ts
index 0a97dbcd2..44d33bc32 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 7d2b5c363..59b7326b6 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 48b73e848..0c9d946fc 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 a8c8ec0a0..9dae09ec5 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 79f1dd74d..264c2d982 100644
--- a/src/view/com/feeds/CustomFeed.tsx
+++ b/src/view/com/feeds/CustomFeed.tsx
@@ -69,6 +69,7 @@ export const CustomFeed = observer(
 
     return (
       <TouchableOpacity
+        testID={`feed-${item.displayName}`}
         accessibilityRole="button"
         style={[styles.container, pal.border, style]}
         onPress={() => {