-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example and test for useWhoReactedToPublication
- Loading branch information
Showing
9 changed files
with
174 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
examples/web/src/publications/UseWhoReactedToPublication.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { publicationId, useWhoReactedToPublication } from '@lens-protocol/react'; | ||
|
||
import { ErrorMessage } from '../components/error/ErrorMessage'; | ||
import { Loading } from '../components/loading/Loading'; | ||
import { useInfiniteScroll } from '../hooks/useInfiniteScroll'; | ||
import { ProfileCard } from '../profiles/components/ProfileCard'; | ||
|
||
export function UseWhoReactedToPublication() { | ||
const { | ||
data: reactions, | ||
error, | ||
loading, | ||
hasMore, | ||
observeRef, | ||
} = useInfiniteScroll( | ||
useWhoReactedToPublication({ | ||
for: publicationId('0x04-0x0b'), | ||
}), | ||
); | ||
|
||
if (loading) return <Loading />; | ||
|
||
if (error) return <ErrorMessage error={error} />; | ||
|
||
return ( | ||
<div> | ||
<h1> | ||
<code>useWhoReactedToPublication</code> | ||
</h1> | ||
<div> | ||
{reactions.map((p) => ( | ||
<div key={p.profile.id}> | ||
<ProfileCard profile={p.profile} /> | ||
<div> | ||
{p.reactions.map((r) => ( | ||
<div key={r.reactionAt}> | ||
{r.reaction} at {r.reactionAt} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
))} | ||
|
||
{hasMore && <p ref={observeRef}>Loading more...</p>} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './PublicationsPage'; | ||
export * from './UsePublication'; | ||
export * from './UsePublications'; | ||
export * from './UseWhoReactedToPublication'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/react/src/publication/__tests__/useWhoReactedToPublication.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
mockProfileWhoReactedResultFragment, | ||
mockWhoReactedToPublicationResponse, | ||
} from '@lens-protocol/api-bindings/mocks'; | ||
import { mockPublicationId } from '@lens-protocol/domain/mocks'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
import { setupHookTestScenario } from '../../__helpers__/setupHookTestScenario'; | ||
import { | ||
UseWhoReactedToPublicationArgs, | ||
useWhoReactedToPublication, | ||
} from '../useWhoReactedToPublication'; | ||
|
||
describe(`Given the ${useWhoReactedToPublication.name} hook`, () => { | ||
const publicationId = mockPublicationId(); | ||
const profileReactions = [mockProfileWhoReactedResultFragment()]; | ||
const expectations = profileReactions.map(({ profile, reactions }) => ({ | ||
profileId: profile.id, | ||
reactions, | ||
})); | ||
|
||
describe('when the query returns data successfully', () => { | ||
it('should settle with the profiles', async () => { | ||
const args: UseWhoReactedToPublicationArgs = { | ||
for: publicationId, | ||
}; | ||
|
||
const { renderHook } = setupHookTestScenario([ | ||
mockWhoReactedToPublicationResponse({ | ||
variables: { | ||
...args, | ||
}, | ||
items: profileReactions, | ||
}), | ||
]); | ||
|
||
const { result } = renderHook(() => useWhoReactedToPublication(args)); | ||
|
||
await waitFor(() => expect(result.current.loading).toBeFalsy()); | ||
expect(result.current.data).toMatchObject(expectations); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters