@conorheffron/ironoc-frontend 9.1.8 → 9.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -35,7 +35,8 @@ const RepoIssues = () => {
|
|
|
35
35
|
|
|
36
36
|
const [repoIssueList, setRepoIssueList] = useState([]);
|
|
37
37
|
const [isLoading, setIsLoading] = useState(true);
|
|
38
|
-
const [
|
|
38
|
+
const [usernameValue, setUsernameValue] = useState(id);
|
|
39
|
+
const [repoValue, setRepoValue] = useState(repo);
|
|
39
40
|
|
|
40
41
|
useEffect(() => {
|
|
41
42
|
const fetchIssues = async () => {
|
|
@@ -44,20 +45,27 @@ const RepoIssues = () => {
|
|
|
44
45
|
const body = await response.json();
|
|
45
46
|
setRepoIssueList(body);
|
|
46
47
|
}
|
|
48
|
+
setUsernameValue(id);
|
|
49
|
+
setRepoValue(repo);
|
|
47
50
|
setIsLoading(false);
|
|
48
51
|
};
|
|
49
52
|
fetchIssues();
|
|
50
53
|
}, [id, repo]);
|
|
51
54
|
|
|
52
|
-
const
|
|
55
|
+
const handleUsernameChange = (event) => setUsernameValue(event.target.value);
|
|
56
|
+
|
|
57
|
+
const handleRepoChange = (event) => setRepoValue(event.target.value);
|
|
53
58
|
|
|
54
59
|
const onSubmit = (event) => {
|
|
55
60
|
event.preventDefault();
|
|
56
|
-
|
|
61
|
+
const searchUsername = usernameValue.trim() || id;
|
|
62
|
+
const searchRepo = repoValue.trim() || repo;
|
|
63
|
+
|
|
64
|
+
navigate(`/issues/${searchUsername}/${searchRepo}`, {
|
|
57
65
|
replace: true,
|
|
58
66
|
state: {
|
|
59
|
-
id:
|
|
60
|
-
repo:
|
|
67
|
+
id: searchUsername,
|
|
68
|
+
repo: searchRepo,
|
|
61
69
|
},
|
|
62
70
|
});
|
|
63
71
|
navigate(0);
|
|
@@ -183,13 +191,19 @@ const RepoIssues = () => {
|
|
|
183
191
|
<Container fluid={true}>
|
|
184
192
|
<br />
|
|
185
193
|
<InputGroup className="mb-3">
|
|
194
|
+
<Form.Control
|
|
195
|
+
placeholder="Enter GitHub User ID... Example: conorheffron"
|
|
196
|
+
aria-label="Enter GitHub User ID..."
|
|
197
|
+
type="text"
|
|
198
|
+
value={usernameValue}
|
|
199
|
+
onChange={handleUsernameChange}
|
|
200
|
+
/>
|
|
186
201
|
<Form.Control
|
|
187
202
|
placeholder="Enter Project Name... Example: ironoc-db"
|
|
188
203
|
aria-label="Enter Project Name..."
|
|
189
|
-
aria-describedby="basic-addon2"
|
|
190
204
|
type="text"
|
|
191
|
-
value={
|
|
192
|
-
onChange={
|
|
205
|
+
value={repoValue}
|
|
206
|
+
onChange={handleRepoChange}
|
|
193
207
|
/>
|
|
194
208
|
<Button
|
|
195
209
|
variant="outline-secondary"
|
|
@@ -164,17 +164,41 @@ describe('RepoIssues', () => {
|
|
|
164
164
|
window.fetch = global.fetch;
|
|
165
165
|
render(<RepoIssues />);
|
|
166
166
|
await waitFor(() => expect(screen.queryByTestId('spinner')).not.toBeInTheDocument());
|
|
167
|
-
const
|
|
167
|
+
const usernameInput = screen.getByRole('textbox', { name: /Enter GitHub User ID/i });
|
|
168
|
+
const repoInput = screen.getByRole('textbox', { name: /Enter Project Name/i });
|
|
168
169
|
const button = screen.getByText(/Search Issues/i);
|
|
169
|
-
fireEvent.change(
|
|
170
|
+
fireEvent.change(usernameInput, { target: { value: 'other-user' } });
|
|
171
|
+
fireEvent.change(repoInput, { target: { value: 'newrepo' } });
|
|
170
172
|
fireEvent.click(button);
|
|
171
|
-
expect(mockNavigate).toHaveBeenCalledWith('/issues/user/newrepo', {
|
|
173
|
+
expect(mockNavigate).toHaveBeenCalledWith('/issues/other-user/newrepo', {
|
|
172
174
|
replace: true,
|
|
173
175
|
state: {
|
|
174
|
-
id: 'user',
|
|
176
|
+
id: 'other-user',
|
|
175
177
|
repo: 'newrepo',
|
|
176
178
|
},
|
|
177
179
|
});
|
|
178
180
|
expect(mockNavigate).toHaveBeenCalledWith(0);
|
|
179
181
|
});
|
|
182
|
+
|
|
183
|
+
it('uses current route values when search fields are blank', async () => {
|
|
184
|
+
useParams.mockReturnValue({ id: 'user', repo: 'repo' });
|
|
185
|
+
global.fetch = jest.fn(() => Promise.resolve({ json: () => Promise.resolve([]) }));
|
|
186
|
+
window.fetch = global.fetch;
|
|
187
|
+
render(<RepoIssues />);
|
|
188
|
+
await waitFor(() => expect(screen.queryByTestId('spinner')).not.toBeInTheDocument());
|
|
189
|
+
const usernameInput = screen.getByRole('textbox', { name: /Enter GitHub User ID/i });
|
|
190
|
+
const repoInput = screen.getByRole('textbox', { name: /Enter Project Name/i });
|
|
191
|
+
const button = screen.getByText(/Search Issues/i);
|
|
192
|
+
fireEvent.change(usernameInput, { target: { value: '' } });
|
|
193
|
+
fireEvent.change(repoInput, { target: { value: '' } });
|
|
194
|
+
fireEvent.click(button);
|
|
195
|
+
expect(mockNavigate).toHaveBeenCalledWith('/issues/user/repo', {
|
|
196
|
+
replace: true,
|
|
197
|
+
state: {
|
|
198
|
+
id: 'user',
|
|
199
|
+
repo: 'repo',
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
expect(mockNavigate).toHaveBeenCalledWith(0);
|
|
203
|
+
});
|
|
180
204
|
});
|