Skip to content

Commit

Permalink
Merge pull request #39 from ChetanKarwa/Bounty-List/fix-loaded-state
Browse files Browse the repository at this point in the history
Bounty List: Fix loaded state when using filters of languages
  • Loading branch information
elraphty authored Jan 29, 2024
2 parents 1659e8c + 143b82a commit 1cc7208
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/pages/tickets/Tickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function BodyComponent() {
setCurrentItems={setCurrentItems}
page={page}
setPage={setPage}
languageString={languageString}
/>
</div>

Expand All @@ -194,7 +195,6 @@ function BodyComponent() {
minHeight: '32px'
}}
/>

<BountyHeader
selectedWidget={selectedWidget}
scrollValue={scrollValue}
Expand Down Expand Up @@ -237,6 +237,7 @@ function BodyComponent() {
setCurrentItems={setCurrentItems}
page={page}
setPage={setPage}
languageString={languageString}
/>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/pages/tickets/org/OrgTickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function OrgBodyComponent() {
fromBountyPage={true}
selectedWidget={selectedWidget}
loading={loading}
languageString={languageString}
/>
</div>

Expand Down Expand Up @@ -194,6 +195,7 @@ function OrgBodyComponent() {
selectedWidget={selectedWidget}
loading={loading}
org_uuid={uuid}
languageString={languageString}
/>
</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletions src/people/utils/NoResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ const H = styled.div`
letter-spacing: 0px;
color: rgb(60, 63, 65);
`;
function NoResults() {
function NoResults({ loaded = false }: { loaded?: boolean }) {
const { ui } = useStores();
const { searchText } = ui || {};

if (searchText) {
if (searchText || loaded) {
return (
<div
style={{
Expand Down
12 changes: 9 additions & 3 deletions src/people/widgetViews/WidgetSwitchViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ function WidgetSwitchViewer(props: any) {
const [deletePayload, setDeletePayload] = useState<object>({});
const closeModal = () => setShowDeleteModal(false);
const showModal = () => setShowDeleteModal(true);
const { currentItems, setCurrentItems, totalBounties, page: propsPage, setPage } = props;
const {
currentItems,
setCurrentItems,
totalBounties,
page: propsPage,
setPage,
languageString
} = props;

const items = currentItems ?? 0;
const bountiesTotal = totalBounties ?? 0;
Expand Down Expand Up @@ -236,14 +243,13 @@ function WidgetSwitchViewer(props: any) {
);
})
) : (
<NoResults />
<NoResults loaded={!!languageString} />
);
const showLoadMore = bountiesTotal > items && activeList.length >= queryLimit;
return (
<>
{listItems}
<Spacer key={'spacer2'} />

{showDeleteModal && (
<DeleteTicketModal closeModal={closeModal} confirmDelete={confirmDelete} />
)}
Expand Down
49 changes: 40 additions & 9 deletions src/people/widgetViews/__tests__/WidgetSwitchViewer.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
import WidgetViewer from '../WidgetSwitchViewer';
import { uiStore } from '../../../store/ui';
// import crypto from 'crypto';
// import moment from 'moment';
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { useStores } from 'store';
import WidgetSwitchViewer from '../WidgetSwitchViewer';

beforeAll(() => {});
jest.mock('hooks', () => ({
useIsMobile: jest.fn()
}));

afterAll(() => {});
jest.mock('store', () => ({
useStores: jest.fn()
}));

describe('testing helpers', () => {
test('test', () => {
expect(true).toBe(true);
describe('WidgetSwitchViewer Component', () => {
beforeEach(() => {
jest.clearAllMocks();
});

test('should display No results when there are no active list items with filter of languages', () => {
// Mock return value for the store hook
(useStores as jest.Mock).mockReturnValue({
main: {
peopleBounties: [],
peopleOffers: [],
peoplePosts: []
}
});

// Render the component with a selected widget and empty lists
render(
<WidgetSwitchViewer
selectedWidget="wanted"
currentItems={0}
totalBounties={0}
languageString="Typescript"
/>
);

// Assert that <NoResults /> is present in the document
expect(screen.getByText(/No results/i)).toBeInTheDocument();
});

// Additional tests for different conditions can be added here
});

0 comments on commit 1cc7208

Please sign in to comment.