-
-
Notifications
You must be signed in to change notification settings - Fork 97
fix: report repository refresh failures and reject busy updates #841
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| { | ||
| "core.min.js": "core.c5bd53363a.min.js", | ||
| "vendor.min.js": "vendor.7f9da8be8e.min.js", | ||
| "core.min.js": "core.3b07189932.min.js", | ||
| "vendor.min.js": "vendor.3036803e29.min.js", | ||
| "mermaid.min.js": "mermaid.f848a72d16.min.js", | ||
| "all.min.css": "all.5fbafcda4e.min.css", | ||
| "markdown.min.js": "markdown.ad7b1d71c3.min.js", | ||
| "pdf.min.js": "pdf.eaa7573247.min.js", | ||
| "notebook.min.js": "notebook.8844e2735f.min.js", | ||
| "org.min.js": "org.f4e2a3f59f.min.js", | ||
| "editor.min.js": "editor.e243722d87.min.js" | ||
| "markdown.min.js": "markdown.44f2e93820.min.js", | ||
| "pdf.min.js": "pdf.0175d53d2f.min.js", | ||
| "notebook.min.js": "notebook.c3144c18ae.min.js", | ||
| "org.min.js": "org.f61f262915.min.js", | ||
| "editor.min.js": "editor.4f142d3adc.min.js" | ||
| } |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| const { expect } = require("chai"); | ||
| const fs = require("fs"); | ||
| const vm = require("vm"); | ||
| const { setImmediate } = require("timers"); | ||
| const source = fs.readFileSync(require("path").join(__dirname, "../public/script/app.js"), "utf8"); | ||
| const actions = source.slice(source.indexOf(" function waitRepoToBeReady("), source.indexOf(" state.itemFilter =")); | ||
|
|
||
| describe("dashboard refresh feedback", () => { | ||
| async function run({ statuses = [], postError, getError } = {}) { | ||
| let toast; | ||
| const item = { _type: "repo", _id: "restore-me", repoId: "restore-me", status: "removed" }; | ||
| const state = { items: [item], addToast: value => { toast = value; } }; | ||
| const pending = []; | ||
| let reloads = 0; | ||
| vm.runInNewContext(actions, { | ||
| state, reactive: value => value, | ||
| http: { | ||
| post: async () => { if (postError) throw postError; return {}; }, | ||
| get: async () => { if (getError) throw getError; return { data: statuses.shift() }; }, | ||
| }, | ||
| timers: { timeout: callback => pending.push(callback) }, | ||
| loadAll: () => { reloads++; }, | ||
| }); | ||
| state.refreshItem(item); | ||
| await new Promise(resolve => setImmediate(resolve)); | ||
| while (pending.length) { | ||
| pending.shift()(); | ||
| await new Promise(resolve => setImmediate(resolve)); | ||
| } | ||
| return { toast, item, reloads }; | ||
| } | ||
|
|
||
| it("reports success after preparation reaches ready", async () => { | ||
| const result = await run({ statuses: [{ status: "preparing" }, { status: "ready" }] }); | ||
| expect(result.toast.title).to.equal("restore-me is refreshed."); | ||
| expect(result.item.status).to.equal("ready"); | ||
| expect(result.reloads).to.equal(0); | ||
| }); | ||
| for (const status of ["error", "removed", "expired"]) { | ||
| it(`reports ${status} as a failed refresh`, async () => { | ||
| const result = await run({ statuses: [{ status, statusMessage: "token_expired" }] }); | ||
| expect(result.toast.title).to.equal("Error during the refresh of restore-me."); | ||
| expect(result.toast.body).to.equal("token_expired"); | ||
| expect(result.item.statusMessage).to.equal("token_expired"); | ||
| expect(result.reloads).to.equal(1); | ||
| }); | ||
| } | ||
| it("explains a terminal status without a status message", async () => { | ||
| const result = await run({ statuses: [{ status: "expired" }] }); | ||
| expect(result.toast.body).to.equal("The repository is expired."); | ||
| }); | ||
| for (const stage of ["postError", "getError"]) { | ||
| it(`shows the API error from ${stage}`, async () => { | ||
| const result = await run({ [stage]: { data: { error: "not_connected" } } }); | ||
| expect(result.toast.title).to.equal("Error during the refresh of restore-me."); | ||
| expect(result.toast.body).to.equal("not_connected"); | ||
| }); | ||
| } | ||
| it("reports a polling network failure", async () => { | ||
| const result = await run({ getError: new Error("Network failure") }); | ||
| expect(result.toast.title).to.equal("Error during the refresh of restore-me."); | ||
| expect(result.toast.body).to.include("Please try again"); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.