Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CFE-563 move reload function into testing utils #18

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions demo/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { getNostoWindow } from "../src"
import { reloadNosto } from "../src/testing/testing"

export function bypassLocalhostBlock() {
const interval = setInterval(() => {
if (getNostoWindow() && "reload" in getNostoWindow()) {
const reloadSuccessful = reloadNosto({
site: location.hostname,
searchApiUrl: "https://search.nosto.com/api/",
searchEnabled: false
})
if (reloadSuccessful) {
clearInterval(interval)
getNostoWindow().reload({
site: location.hostname,
searchApiUrl: "https://search.nosto.com/api/",
searchEnabled: false
})
}
}, 100)
}
13 changes: 0 additions & 13 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import { Settings } from "../client/nosto"

/**
* Checks if Nosto is loaded on the page.
*/
export function isNostoLoaded() {
return typeof window.nosto !== "undefined"
}

/**
* Reloads Nosto with the given settings, useful for development purposes.
*
* @param settings Settings to override.
*/
export function reloadNosto(settings: Partial<Settings>) {
if (window.nosto) {
window.nosto.reload(settings)
}
}

/**
* Gets the correctly typed Nosto object.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/testing/reloadNosto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Settings } from "../client/nosto"

/**
* Reloads Nosto with the given settings, useful for development purposes.
* Will not perform a reload if Nosto is not yet ready.
*
* @param settings Settings to override.
* @returns `true` if reload is successful, `false` otherwise.
*/
export function reloadNosto(settings: Partial<Settings>) {
if (window.nosto && "reload" in window.nosto) {
window.nosto.reload(settings)
return true
}
return false
}
1 change: 1 addition & 0 deletions src/testing/testing.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/** @module testing */
export * from "./mockNostojs"
export * from "./reloadNosto"
Loading