-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
5,282 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,73 @@ | ||
import {useState} from 'react' | ||
import {useEffect, useState} from 'react' | ||
import reactLogo from './assets/react.svg' | ||
import viteLogo from '/vite.svg' | ||
import './App.css' | ||
|
||
function App() { | ||
const [count, setCount] = useState(0) | ||
import './App.scss' | ||
import {useNavigate} from "react-router-dom"; | ||
import {useAppStore} from "./stores/AppStore.js"; | ||
import {configuration, csrf, me} from "./api/index.js"; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<a href="https://vite.dev" target="_blank"> | ||
<img src={viteLogo} className="logo" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank"> | ||
<img src={reactLogo} className="logo react" alt="React logo" /> | ||
</a> | ||
</div> | ||
<h1>Vite + React</h1> | ||
<div className="card"> | ||
<button onClick={() => setCount((count) => count + 1)}> | ||
count is {count} | ||
</button> | ||
<p> | ||
Edit <code>src/App.jsx</code> and save to test HMR | ||
</p> | ||
</div> | ||
<p className="read-the-docs"> | ||
Click on the Vite and React logos to learn more | ||
</p> | ||
</> | ||
) | ||
} | ||
export const App = () => { | ||
|
||
const [loading, setLoading] = useState(true); | ||
const navigate = useNavigate(); | ||
const {user} = useAppStore(state => state); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
csrf().then(token => { | ||
useAppStore.setState(() => ({csrfToken: token.token})); | ||
configuration() | ||
.then(res => { | ||
useAppStore.setState(() => ({config: res})); | ||
if (!res.authenticated) { | ||
if (!res.name) { | ||
const direction = window.location.pathname + window.location.search; | ||
localStorage.setItem("location", direction); | ||
} else if (!isEmpty(res.missingAttributes)) { | ||
setLoading(false); | ||
navigate("/missingAttributes"); | ||
return; | ||
} | ||
const pathname = localStorage.getItem("location") || window.location.pathname; | ||
const isInvitationAcceptFlow = window.location.pathname.startsWith("/invitation/accept"); | ||
if (res.name && !pathname.startsWith("/invitation/accept") && !isInvitationAcceptFlow) { | ||
setLoading(false); | ||
navigate("/deadend"); | ||
} else if (pathname === "/" || pathname.startsWith("/login") || pathname.startsWith("/invitation/accept") || isInvitationAcceptFlow) { | ||
setLoading(false); | ||
navigate(isInvitationAcceptFlow ? (window.location.pathname + window.location.search) : pathname); | ||
} else { | ||
//Bookmarked URL's trigger a direct login and skip the landing page | ||
login(res); | ||
} | ||
} else { | ||
me() | ||
.then(res => { | ||
useAppStore.setState(() => ({user: res, authenticated: true})); | ||
setLoading(false); | ||
const location = localStorage.getItem("location") || window.location.pathname + window.location.search; | ||
const newLocation = location.startsWith("/login") ? "/home" : location; | ||
localStorage.removeItem("location"); | ||
navigate(newLocation); | ||
}); | ||
} | ||
}) | ||
.catch(() => { | ||
setLoading(false); | ||
navigate("/deadend"); | ||
}) | ||
}) | ||
}, [reload, impersonator]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
export default App | ||
if (loading) { | ||
return <Loader/> | ||
} | ||
|
||
|
||
return ( | ||
<> | ||
<span>TODO</span> | ||
<span>Routes -> with login</span> | ||
</> | ||
) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import en from "../../locale/en"; | ||
import nl from "../../locale/nl"; | ||
|
||
expect.extend({ | ||
toContainKey(translation, key) { | ||
return { | ||
message: () => `Expected ${key} to be present in ${JSON.stringify(translation)}`, | ||
pass: (translation !== undefined && translation[key] !== undefined) | ||
}; | ||
}, | ||
}); | ||
|
||
test("All translations exists in all bundles", () => { | ||
const contains = (translation, translationToVerify, keyCollection, parents) => { | ||
Object.keys(translation).forEach(key => { | ||
expect(translationToVerify).toContainKey(key); | ||
const value = translation[key]; | ||
keyCollection.push(parents + key); | ||
if (typeof value === "object") { | ||
contains(value, translationToVerify[key], keyCollection, parents + key + ".") | ||
} | ||
}); | ||
}; | ||
const keyCollectionEN = []; | ||
contains(en, nl, keyCollectionEN, ''); | ||
const keyCollectionNL = []; | ||
contains(nl, en, keyCollectionNL, ''); | ||
const positionalMismatches = keyCollectionEN.filter((item, index) => keyCollectionNL[index] !== item); | ||
expect(positionalMismatches).toEqual([]) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {useAppStore} from "../../stores/AppStore"; | ||
|
||
test("Store outside functional component", () => { | ||
const csrfToken = useAppStore.getState().csrfToken; | ||
expect(csrfToken).toBeNull(); | ||
|
||
useAppStore.setState({csrfToken: "test"}); | ||
|
||
const updatedCsrfToken = useAppStore.getState().csrfToken; | ||
expect(updatedCsrfToken).toEqual("test"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {mergeProvidersProvisioningsRoles, reduceApplicationFromUserRoles} from "../../utils/Manage"; | ||
import applications from "./applications.json"; | ||
import roles from "./roles.json"; | ||
import userRoles from "./userRoles.json"; | ||
|
||
test("mergeProvidersProvisioningsRoles", () => { | ||
const results = mergeProvidersProvisioningsRoles(applications.providers, applications.provisionings, roles); | ||
expect(results.length).toEqual(6); | ||
}); | ||
|
||
test("reduceApplicationFromUserRoles", () => { | ||
const results = reduceApplicationFromUserRoles(userRoles, "en"); | ||
const applicationNames = results.map(app => app.applicationName); | ||
//Sorting alphabetically on applicationName | ||
expect(applicationNames).toEqual([ | ||
"Calendar EN (SURF bv)", | ||
"Research EN (SURF bv)", | ||
"Research EN (SURF bv)", | ||
"Wiki EN (SURF bv)", | ||
"Wiki EN (SURF bv)", | ||
"Wiki EN (SURF bv)" | ||
]); | ||
const roleNames = results | ||
.filter(app => app.applicationName.startsWith("Wiki")) | ||
.map(app => app.roleName); | ||
//Sub-sorting alphabetically on roleName | ||
expect(roleNames).toEqual([ | ||
"Wiki 1 Role", | ||
"Wiki 2 Role", | ||
"Wiki Another Role (3) - Calendar (1)" | ||
]); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {defaultPagination, paginationQueryParams} from "../../utils/Pagination"; | ||
|
||
test("paginationQueryParams defaults", () => { | ||
const page = defaultPagination("desc", "DESC"); | ||
const queryParams = paginationQueryParams(page, {custom: "val"}); | ||
expect(queryParams).toEqual("custom=val&pageNumber=0&pageSize=10&sort=desc&sortDirection=DESC&"); | ||
}); | ||
|
||
test("paginationQueryParams empty", () => { | ||
const queryParams = paginationQueryParams({}); | ||
expect(queryParams).toEqual(""); | ||
}); |
Oops, something went wrong.