pleroma/app/soapbox/features/groups/components/__tests__/pending-group-rows.test.tsx

105 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-03-08 10:22:10 -08:00
import React from 'react';
import { VirtuosoMockContext } from 'react-virtuoso';
import { __stub } from 'soapbox/api';
2023-06-20 15:48:57 -07:00
import { buildAccount } from 'soapbox/jest/factory';
2023-03-08 10:22:10 -08:00
import { render, screen, waitFor } from 'soapbox/jest/test-helpers';
2023-06-20 15:48:57 -07:00
import { normalizeGroup, normalizeGroupRelationship, normalizeInstance } from 'soapbox/normalizers';
2023-03-08 10:22:10 -08:00
import PendingGroupsRow from '../pending-groups-row';
const userId = '1';
let store: any = {
me: userId,
2023-06-20 15:48:57 -07:00
accounts: {
[userId]: buildAccount({
2023-03-08 10:22:10 -08:00
id: userId,
acct: 'justin-username',
display_name: 'Justin L',
avatar: 'test.jpg',
2023-06-20 15:48:57 -07:00
source: {
chats_onboarded: false,
},
2023-03-08 10:22:10 -08:00
}),
2023-06-20 15:48:57 -07:00
},
2023-03-08 10:22:10 -08:00
};
const renderApp = (store: any) => (
render(
<VirtuosoMockContext.Provider value={{ viewportHeight: 300, itemHeight: 100 }}>
<PendingGroupsRow />
</VirtuosoMockContext.Provider>,
undefined,
store,
)
);
describe('<PendingGroupRows />', () => {
describe('without the feature', () => {
beforeEach(() => {
store = {
...store,
instance: normalizeInstance({
version: '2.7.2 (compatible; Pleroma 2.3.0)',
}),
};
});
it('should not render', () => {
renderApp(store);
2023-03-20 19:31:07 -07:00
expect(screen.queryAllByTestId('pending-items-row')).toHaveLength(0);
2023-03-08 10:22:10 -08:00
});
});
describe('with the feature', () => {
beforeEach(() => {
store = {
...store,
instance: normalizeInstance({
version: '3.4.1 (compatible; TruthSocial 1.0.0)',
software: 'TRUTHSOCIAL',
}),
};
});
describe('without pending group requests', () => {
beforeEach(() => {
__stub((mock) => {
mock.onGet('/api/v1/groups?pending=true').reply(200, []);
});
});
it('should not render', () => {
renderApp(store);
2023-03-20 19:31:07 -07:00
expect(screen.queryAllByTestId('pending-items-row')).toHaveLength(0);
2023-03-08 10:22:10 -08:00
});
});
describe('with pending group requests', () => {
beforeEach(() => {
__stub((mock) => {
mock.onGet('/api/v1/groups').reply(200, [
normalizeGroup({
display_name: 'Group',
id: '1',
}),
]);
mock.onGet('/api/v1/groups/relationships?id[]=1').reply(200, [
normalizeGroupRelationship({
id: '1',
}),
]);
});
});
it('should render the row', async () => {
renderApp(store);
await waitFor(() => {
2023-03-20 19:31:07 -07:00
expect(screen.queryAllByTestId('pending-items-row')).toHaveLength(1);
2023-03-08 10:22:10 -08:00
});
});
});
});
});