Skip to content

Commit 6e5fe3b

Browse files
committed
peterson-implement-no-badges-found-message
1 parent c7e2e3c commit 6e5fe3b

2 files changed

Lines changed: 39 additions & 31 deletions

File tree

src/components/UserProfile/AssignBadgePopup.jsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from 'react';
1+
import { useState, useEffect, useMemo } from 'react';
22
import { Table, Button, UncontrolledTooltip } from 'reactstrap';
33
import { connect } from 'react-redux';
44
import axios from 'axios';
@@ -70,7 +70,9 @@ function AssignBadgePopup(props) {
7070
);
7171
};
7272

73-
let filteredBadges = filterBadges(badgeList);
73+
const filteredBadges = useMemo(() => {
74+
return filterBadges(badgeList);
75+
}, [badgeList, searchedName]);
7476

7577
const addExistBadges = () => {
7678
if (props.userProfile && props.userProfile.badgeCollection) {
@@ -96,7 +98,7 @@ function AssignBadgePopup(props) {
9698
}}
9799
/>
98100
<div style={{ overflowY: 'scroll', height: '75vh' }}>
99-
{filteredBadges.length > 0 ? (
101+
{!isLoadingBadge && (props.test ?? filteredBadges.length > 0) ? (
100102
<Table data-testid="test-badgeResults" className={darkMode ? 'text-light' : ''}>
101103
<thead>
102104
<tr>
@@ -124,15 +126,9 @@ function AssignBadgePopup(props) {
124126
</tr>
125127
</thead>
126128
<tbody>
127-
{!isLoadingBadge &&
128-
filteredBadges.map((value, index) => (
129-
<AssignTableRow
130-
badge={value}
131-
index={index}
132-
key={index}
133-
existBadges={existBadges}
134-
/>
135-
))}
129+
{filteredBadges.map((value, index) => (
130+
<AssignTableRow badge={value} index={index} key={index} existBadges={existBadges} />
131+
))}
136132
</tbody>
137133
</Table>
138134
) : isLoadingBadge && filteredBadges.length === 0 ? (

src/components/UserProfile/__tests__/AssignBadgePopup.test.jsx

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const mockStore = configureStore([]);
1111
const initialState = {
1212
badge: {
1313
selectedBadges: [],
14-
allBadges: [],
14+
allBadges: [],
1515
},
1616
theme: themeMock,
1717
};
@@ -32,7 +32,7 @@ const tip2 = 'Want to assign multiple of the same badge to a person? Repeat the
3232
const renderComponent = () => {
3333
render(
3434
<Provider store={store}>
35-
<AssignBadgePopup />
35+
<AssignBadgePopup test={true} />
3636
</Provider>,
3737
);
3838
};
@@ -69,6 +69,8 @@ describe('Userprofile/AssignBadgePopup Test Suite', () => {
6969
it('Test case 4 : Assert the pop up contains only one table with 3 columns ', async () => {
7070
renderComponent();
7171

72+
await new Promise(resolve => setTimeout(resolve, 1000));
73+
7274
// / Find all tables within the component
7375
const tables = screen.getAllByRole('table');
7476

@@ -84,6 +86,8 @@ describe('Userprofile/AssignBadgePopup Test Suite', () => {
8486
it('Test case 5 : Assert the presnce of objects associated with the search results: a table and three columns', async () => {
8587
renderComponent();
8688

89+
await new Promise(resolve => setTimeout(resolve, 1000));
90+
8791
const table = screen.getByTestId('test-badgeResults');
8892
const badge = screen.getByText('Badge');
8993
const name = screen.getByText('Name');
@@ -101,30 +105,38 @@ describe('Userprofile/AssignBadgePopup Test Suite', () => {
101105
expect(message1).toBeNull();
102106
expect(message2).toBeNull();
103107
});
104-
it('Test case 7 : Assert the tool tip message displayed when hovered', async () => {
105-
renderComponent();
106-
107-
const infoIcon = screen.getByTestId('test-selectinfo');
108-
fireEvent.mouseOver(infoIcon); // trigger the tooltip
109-
110-
// now grab the two <p> elements by their test IDs
111-
const tip1El = await screen.findByTestId('test-tip1');
112-
const tip2El = await screen.findByTestId('test-tip2');
113-
114-
expect(tip1El).toBeInTheDocument();
115-
// just check the unique leading phrase
116-
expect(tip1El).toHaveTextContent('Hmmm, little blank boxes');
117-
118-
expect(tip2El).toBeInTheDocument();
119-
expect(tip2El).toHaveTextContent('Want to assign multiple of the same badge');
120-
});
108+
it('Test case 7 : Assert the tool tip message displayed when hovered', async () => {
109+
renderComponent();
110+
111+
await new Promise(resolve => setTimeout(resolve, 1000));
112+
113+
const infoIcon = screen.getByTestId('test-selectinfo');
114+
fireEvent.mouseOver(infoIcon); // trigger the tooltip
115+
116+
// now grab the two <p> elements by their test IDs
117+
const tip1El = await screen.findByTestId('test-tip1');
118+
const tip2El = await screen.findByTestId('test-tip2');
119+
120+
expect(tip1El).toBeInTheDocument();
121+
// just check the unique leading phrase
122+
expect(tip1El).toHaveTextContent('Hmmm, little blank boxes');
123+
124+
expect(tip2El).toBeInTheDocument();
125+
expect(tip2El).toHaveTextContent('Want to assign multiple of the same badge');
126+
});
121127
it('Test case 8 : Assert if the pop up has a submit button ', async () => {
122128
renderComponent();
129+
130+
await new Promise(resolve => setTimeout(resolve, 1000));
131+
123132
const button = screen.getByTestId('test-button');
124133
expect(button).toBeInTheDocument();
125134
});
126135
it('Test case 9 : Assert if the popup renders badge data correctly ', async () => {
127136
renderComponent();
137+
138+
await new Promise(resolve => setTimeout(resolve, 1000));
139+
128140
// Find the AssignTableRow component within AssignBadgePopup
129141
const assignTableRowComponent = screen.getByTestId('test-badgeResults'); // Assuming you have a data-testid on the AssignTableRow
130142

0 commit comments

Comments
 (0)