-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #431 from systemli/add-message-pagination
⚡️ Add Infinite Scroll to MessageList
- Loading branch information
Showing
6 changed files
with
201 additions
and
25 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import React from 'react' | ||
import sign from 'jwt-encode' | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { render, screen } from '@testing-library/react' | ||
import { MemoryRouter, Route, Routes } from 'react-router' | ||
import { AuthProvider } from '../components/useAuth' | ||
import TickerView from './TickerView' | ||
import ProtectedRoute from '../components/ProtectedRoute' | ||
|
||
describe('TickerView', function () { | ||
const jwt = sign( | ||
{ | ||
id: 1, | ||
email: '[email protected]', | ||
roles: ['user'], | ||
exp: new Date().getTime() / 1000 + 600, | ||
}, | ||
'secret' | ||
) | ||
|
||
const tickerResponse = JSON.stringify({ | ||
data: { | ||
ticker: { | ||
id: 1, | ||
creation_time: new Date(), | ||
domain: 'localhost', | ||
title: 'Ticker Title', | ||
description: 'Description', | ||
active: true, | ||
information: {}, | ||
mastodon: {}, | ||
twitter: {}, | ||
telegram: {}, | ||
location: {}, | ||
}, | ||
}, | ||
}) | ||
const messagesResponse = JSON.stringify({ | ||
data: { | ||
messages: [ | ||
{ | ||
id: 1, | ||
ticker: 1, | ||
text: 'Message', | ||
creation_time: new Date(), | ||
geo_information: '{"type":"FeatureCollection","features":[]}', | ||
attachments: [], | ||
}, | ||
], | ||
}, | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.spyOn(window.localStorage.__proto__, 'getItem').mockReturnValue(jwt) | ||
fetchMock.resetMocks() | ||
}) | ||
|
||
function setup() { | ||
const client = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}) | ||
return render( | ||
<QueryClientProvider client={client}> | ||
<MemoryRouter initialEntries={['/ticker/1']}> | ||
<AuthProvider> | ||
<Routes> | ||
<Route | ||
element={<ProtectedRoute outlet={<TickerView />} role="user" />} | ||
path="/ticker/:tickerId" | ||
/> | ||
</Routes> | ||
</AuthProvider> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
) | ||
} | ||
|
||
test('renders a ticker with messages', async function () { | ||
fetchMock.mockIf(/^http:\/\/localhost:8080\/.*$/, (request: Request) => { | ||
if (request.url.endsWith('/admin/tickers/1')) { | ||
return Promise.resolve(tickerResponse) | ||
} | ||
if (request.url.endsWith('/admin/tickers/1/messages?limit=10')) { | ||
return Promise.resolve(messagesResponse) | ||
} | ||
|
||
return Promise.resolve( | ||
JSON.stringify({ | ||
data: [], | ||
status: 'error', | ||
error: 'error message', | ||
}) | ||
) | ||
}) | ||
|
||
setup() | ||
|
||
// Loader for the Ticker | ||
expect(screen.getByText(/loading/i)).toBeInTheDocument() | ||
expect(await screen.findByText('Ticker Title')).toBeInTheDocument() | ||
|
||
// Loader for the Messages | ||
expect(screen.getByText(/loading/i)).toBeInTheDocument() | ||
screen.debug() | ||
expect(await screen.findByText('Message')).toBeInTheDocument() | ||
}) | ||
}) |