Skip to content

Commit 7813dc9

Browse files
authored
Merge pull request #97 from SolidLabResearch/fix/90
Fix/90
2 parents 8b53d88 + 8279be5 commit 7813dc9

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Added
11+
- Added 'Unauthorized' to the fetch status (#90)
1112

1213
### Changed
1314
- On empty query result, show clear message (#86)

cypress/e2e/fetch-status.cy.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ describe("Fetch Status", () => {
1515

1616
// Check if the correct icons appear
1717
cy.get('[aria-label="Authentication required"]').should("exist");
18-
cy.get('[aria-label="Fetch failed"]').should("exist");
18+
cy.get('[aria-label="Unauthorized"]').should("exist");
1919

2020
cy.get('[aria-label="No authentication required"]').should("exist");
21-
cy.get('[aria-label="Fetch was succesful"]').should("exist");
21+
cy.get('[aria-label="Fetch was successful"]').should("exist");
2222

2323

2424
// Checking that a non-authorized book is not appearing
@@ -60,13 +60,36 @@ describe("Fetch Status", () => {
6060
// Check if the correct icons appear
6161
cy.get('[aria-label="Authentication required"]').should("exist");
6262
cy.get('[aria-label="Fetch Failed"]').should("not.exist");
63+
cy.get('[aria-label="Unauthorized"]').should("not.exist");
6364

6465
cy.get('[aria-label="No authentication required"]').should("exist");
65-
cy.get('[aria-label="Fetch was succesful"]').should("exist");
66+
cy.get('[aria-label="Fetch was successful"]').should("exist");
6667

6768
// Checking that you see authorized books
6869
cy.contains("It Ends With Us");
6970
cy.contains("Too Late");
7071
});
7172

73+
it("Failed to fetch data", () => {
74+
75+
cy.visit("/");
76+
77+
// Go immediately to query
78+
cy.contains("My favourite musicians").click();
79+
80+
// Check if the good and bad sources appear
81+
cy.get('[aria-label="Sources info"]').click();
82+
83+
// First fetch should be a success
84+
cy.contains("http://localhost:8080/example/favourite-musicians");
85+
cy.get('[aria-label="No authentication required"]').should("exist");
86+
cy.get('[aria-label="Unauthorized"]').should("not.exist");
87+
cy.get('[aria-label="Fetch was successful"]').should("exist");
88+
89+
// the bad source should fail to fetch
90+
cy.contains("http://www.example.com/fetch-failure-but-query-success");
91+
cy.get('[aria-label="Fetch failed"]').should("exist");
92+
93+
});
94+
7295
})

cypress/e2e/sources-info.cy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Sources info", () => {
1616
cy.contains("Finished in:");
1717
cy.get('[aria-label="Sources info"]').click();
1818

19-
cy.get('[aria-label="Fetch was succesful"]').should("exist");
19+
cy.get('[aria-label="Fetch was successful"]').should("exist");
2020
});
2121

2222
it("Fetch status on cached source - see https://github.com/SolidLabResearch/generic-data-viewer-react-admin/issues/59", () => {
@@ -26,13 +26,13 @@ describe("Sources info", () => {
2626
cy.contains("Finished in:");
2727
cy.get('[aria-label="Sources info"]').click();
2828

29-
cy.get('[aria-label="Fetch was succesful"]').should("exist");
29+
cy.get('[aria-label="Fetch was successful"]').should("exist");
3030

3131
cy.contains("Components and their materials").click();
3232
cy.contains("Finished in:");
3333
cy.get('[aria-label="Sources info"]').click();
3434

35-
cy.get('[aria-label="Fetch was succesful"]').should("exist");
35+
cy.get('[aria-label="Fetch was successful"]').should("exist");
3636
cy.get('[aria-label="Fetch failed"]').should("not.exist");
3737
});
3838

src/components/ActionBar/SourceFetchStatusIcon/SourceFetchStatusIcon.jsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CheckIcon from '@mui/icons-material/Check';
22
import CancelIcon from "@mui/icons-material/Cancel";
3+
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
34
import { Tooltip } from "@mui/material";
45
import PropTypes from "prop-types";
56
import { Component } from "react";
@@ -16,14 +17,23 @@ function SourceFetchStatusIcon({ context, source, proxyUrl }) {
1617
if (context.useProxy) {
1718
actualSource = `${proxyUrl}${source}`;
1819
}
19-
const status = context.fetchSuccess[actualSource];
20-
if (status) {
20+
const status = context.fetchStatusNumber[actualSource];
21+
22+
if (context.fetchSuccess[actualSource]) {
2123
return (
22-
<Tooltip title="Fetch was succesful">
24+
<Tooltip title="Fetch was successful">
2325
<CheckIcon size="small" />
2426
</Tooltip>
2527
);
26-
} else {
28+
}
29+
else if (status == 401 || status == 403){
30+
return (
31+
<Tooltip title="Unauthorized">
32+
<RemoveCircleOutlineIcon size="small" />
33+
</Tooltip>
34+
);
35+
}
36+
else {
2737
return (
2838
<Tooltip title="Fetch failed">
2939
<CancelIcon size="small" />

src/dataProvider/SparqlDataProvider.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ function generateContext(context) {
207207

208208
if (!context.fetchSuccess) {
209209
context.fetchSuccess = {};
210+
context.fetchStatusNumber = {};
210211
// avoid faulty fetch status for sources cached in Comunica
211212
for (const source of context.sources) {
212213
context.fetchSuccess[source] = true;
@@ -239,13 +240,15 @@ function statusFetch(customFetch, context) {
239240
try{
240241
const response = await customFetch(arg);
241242
context.fetchSuccess[arg] = response.ok;
243+
context.fetchStatusNumber[arg] = response.status;
242244
return response;
243245
}
244246
catch(error){
245247
context.fetchSuccess[arg] = false;
246248
throw error;
247249
}
248250
}
251+
249252
return wrappedFetchFunction;
250253
}
251254

0 commit comments

Comments
 (0)