Commit b2e9a936 authored by Lauri Himanen's avatar Lauri Himanen Committed by Mohammad Nakhaee
Browse files

Resolve "The Files tab inside an upload throws a JS error"

parent c8b14d99
......@@ -179,9 +179,6 @@ export async function expectInputRange(quantity, loaded, histogram, anchored, mi
* @param {object} root The root element to perform the search on.
*/
export async function expectInputPeriodicTable(quantity, loaded, elements, root = screen) {
// Test header
await expectInputHeader(quantity)
// Test that all elements are displayed
elementData.elements.forEach(element => {
const name = root.getByText(element.symbol)
......@@ -194,6 +191,9 @@ export async function expectInputPeriodicTable(quantity, loaded, elements, root
})
expect(screen.getByRole('checkbox')).toBeInTheDocument()
// Test header
await expectInputHeader(quantity)
// Test that only available elements are clickable after API response.
await expectInputPeriodicTableItems(elements)
}
......
......@@ -16,10 +16,13 @@
* limitations under the License.
*/
import { createTheme } from '@material-ui/core'
import { urlAbs } from './utils'
window.nomadEnv = window.nomadEnv || {}
export const version = window.nomadEnv.version
export const appBase = window.nomadEnv.appBase.replace(/\/$/, '')
// Ensure that appBase is a correct absolute url that uses the same protocol as
// the page in which this script is loaded.
export const appBase = urlAbs(window.nomadEnv.appBase.replace(/\/$/, ''))
// export const apiBase = 'http://nomad-lab.eu/prod/rae/api'
export const apiBase = `${appBase}/api`
export const northBase = window.nomadEnv.northBase
......
......@@ -1057,3 +1057,26 @@ export function urlEncodePath(path) {
export function urlDecodePath(urlPath) {
return urlPath.split('/').map(decodeURIComponent).join('/')
}
/**
* Used to normalized the given URL into an absolute form which starts with
* protocol, host and port.
*
* @param {*} url The url to convert
* @param {*} base The URL base address. Contains the protocol, host and port. Defaults to
* current window origin.
* @param {*} protocol The desired protocol. By default the protocol in 'base'
* is used.
* @returns Absolute url as a string
*/
export function urlAbs(url, base = window.location.origin, protocol) {
let absUrl = new URL(url, base).href
// Convert protocol if one is given
if (protocol) {
const oldProtocol = absUrl.split('//', 1)[0]
absUrl = `${protocol}${absUrl.slice(oldProtocol.length)}`
}
return absUrl
}
......@@ -24,7 +24,8 @@ import {
resolveNomadUrl,
normalizeNomadUrl,
refType,
refRelativeTo
refRelativeTo,
urlAbs
} from './utils'
import { apiBase } from './config'
......@@ -523,3 +524,13 @@ test.each([
expect(resolvedUrl.isExternal).toBe(expectedResult.isExternal || false)
expect(normalizeNomadUrl(resolvedUrl)).toBe(expectedResult.normalizedUrl)
})
test.each([
['already absolute', 'https://nomad-lab.eu/test', 'https://nomad-lab.eu/test', 'https://nomad-lab.eu'],
['root path', '/test', 'https://nomad-lab.eu/test', 'https://nomad-lab.eu'],
['relative path', '../test', 'https://nomad-lab.eu/test', 'https://nomad-lab.eu/folder'],
['protocol change', '/test', 'http://nomad-lab.eu/test', 'https://nomad-lab.eu', 'http:'],
['non-http protocol', 'ssh://nomad-lab.eu/test', 'ssh://nomad-lab.eu/test', 'ssh://nomad-lab.eu']
])('absolute url creation: %s ', (id, input, output, base, protocol = undefined) => {
expect(urlAbs(input, base, protocol)).toBe(output)
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment