Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 11:52:54 +01:00
Update resume on revisit dialog and add test
Dieser Commit ist enthalten in:
Ursprung
1ab2262ca3
Commit
ca9e96ccf5
4 geänderte Dateien mit 67 neuen und 10 gelöschten Zeilen
|
@ -5,6 +5,7 @@ import discourseComputed from "discourse-common/utils/decorators";
|
||||||
import getUrl from "discourse-common/lib/get-url";
|
import getUrl from "discourse-common/lib/get-url";
|
||||||
import CustomWizardField from "./custom-wizard-field";
|
import CustomWizardField from "./custom-wizard-field";
|
||||||
import CustomWizardStep from "./custom-wizard-step";
|
import CustomWizardStep from "./custom-wizard-step";
|
||||||
|
import DiscourseURL from "discourse/lib/url";
|
||||||
|
|
||||||
const CustomWizard = EmberObject.extend({
|
const CustomWizard = EmberObject.extend({
|
||||||
@discourseComputed("steps.length")
|
@discourseComputed("steps.length")
|
||||||
|
@ -34,7 +35,7 @@ CustomWizard.reopenClass({
|
||||||
restart(wizardId) {
|
restart(wizardId) {
|
||||||
ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
|
ajax({ url: `/w/${wizardId}/skip`, type: "PUT" })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.location.href = `/w/${wizardId}`;
|
DiscourseURL.redirectTo(getUrl(`/w/${wizardId}`));
|
||||||
})
|
})
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
},
|
},
|
||||||
|
@ -44,7 +45,7 @@ CustomWizard.reopenClass({
|
||||||
if (result.redirect_on_complete) {
|
if (result.redirect_on_complete) {
|
||||||
url = result.redirect_on_complete;
|
url = result.redirect_on_complete;
|
||||||
}
|
}
|
||||||
window.location.href = getUrl(url);
|
DiscourseURL.redirectTo(getUrl(url));
|
||||||
},
|
},
|
||||||
|
|
||||||
build(wizardJson) {
|
build(wizardJson) {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
|
import { findCustomWizard, updateCachedWizard } from "../models/custom-wizard";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import DiscourseRoute from "discourse/routes/discourse";
|
import DiscourseRoute from "discourse/routes/discourse";
|
||||||
import bootbox from "bootbox";
|
import { inject as service } from "@ember/service";
|
||||||
|
|
||||||
export default DiscourseRoute.extend({
|
export default DiscourseRoute.extend({
|
||||||
|
dialog: service(),
|
||||||
|
|
||||||
titleToken() {
|
titleToken() {
|
||||||
const wizard = this.modelFor("custom-wizard");
|
const wizard = this.modelFor("custom-wizard");
|
||||||
return wizard ? wizard.name || wizard.id : I18n.t("wizard.custom_title");
|
return wizard ? wizard.name || wizard.id : I18n.t("wizard.custom_title");
|
||||||
|
@ -30,7 +32,7 @@ export default DiscourseRoute.extend({
|
||||||
{
|
{
|
||||||
label: I18n.t("wizard.incomplete_submission.restart"),
|
label: I18n.t("wizard.incomplete_submission.restart"),
|
||||||
class: "btn btn-default",
|
class: "btn btn-default",
|
||||||
callback: () => {
|
action: () => {
|
||||||
wizardModel.restart();
|
wizardModel.restart();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -40,11 +42,7 @@ export default DiscourseRoute.extend({
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const options = {
|
this.dialog.dialog({ title, buttons, type: 'confirm' });
|
||||||
onEscape: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
bootbox.dialog(title, buttons, options);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
afterModel(model) {
|
afterModel(model) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { visit } from "@ember/test-helpers";
|
import { click, visit } from "@ember/test-helpers";
|
||||||
import { test } from "qunit";
|
import { test } from "qunit";
|
||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
|
@ -12,9 +12,12 @@ import {
|
||||||
wizardGuest,
|
wizardGuest,
|
||||||
wizardNoUser,
|
wizardNoUser,
|
||||||
wizardNotPermitted,
|
wizardNotPermitted,
|
||||||
|
wizardResumeOnRevisit,
|
||||||
} from "../helpers/wizard";
|
} from "../helpers/wizard";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
acceptance("Wizard | Not logged in", function (needs) {
|
acceptance("Wizard | Not logged in", function (needs) {
|
||||||
needs.pretender((server, helper) => {
|
needs.pretender((server, helper) => {
|
||||||
|
@ -194,3 +197,53 @@ acceptance("Wizard | Guest access", function (needs) {
|
||||||
assert.strictEqual($("body.custom-wizard").length, 0);
|
assert.strictEqual($("body.custom-wizard").length, 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
acceptance("Wizard | Resume on revisit", function (needs) {
|
||||||
|
needs.user();
|
||||||
|
|
||||||
|
test("Shows dialog", async function (assert) {
|
||||||
|
pretender.get("/w/wizard.json", () => {
|
||||||
|
return response(wizardResumeOnRevisit);
|
||||||
|
});
|
||||||
|
|
||||||
|
await visit("/w/wizard");
|
||||||
|
|
||||||
|
assert.strictEqual(count(".dialog-content:visible"), 1);
|
||||||
|
assert.strictEqual(
|
||||||
|
query(".dialog-header h3").textContent.trim(),
|
||||||
|
I18n.t("wizard.incomplete_submission.title", {
|
||||||
|
date: moment(wizardResumeOnRevisit.submission_last_updated_at).format(
|
||||||
|
"MMMM Do YYYY"
|
||||||
|
),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Resumes when resumed", async function (assert) {
|
||||||
|
pretender.get("/w/wizard.json", () => {
|
||||||
|
return response(wizardResumeOnRevisit);
|
||||||
|
});
|
||||||
|
await visit("/w/wizard");
|
||||||
|
await click(".dialog-footer .btn-primary");
|
||||||
|
assert.strictEqual(count(".dialog-content:visible"), 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Restarts when restarted", async function (assert) {
|
||||||
|
sinon.stub(DiscourseURL, "redirectTo");
|
||||||
|
let skips = 0;
|
||||||
|
pretender.get("/w/wizard.json", () => {
|
||||||
|
return response(wizardResumeOnRevisit);
|
||||||
|
});
|
||||||
|
pretender.put("/w/wizard/skip", () => {
|
||||||
|
skips++;
|
||||||
|
return response({});
|
||||||
|
});
|
||||||
|
await visit("/w/wizard");
|
||||||
|
await click(".dialog-footer .btn-default");
|
||||||
|
assert.strictEqual(skips, 1);
|
||||||
|
assert.ok(
|
||||||
|
DiscourseURL.redirectTo.calledWith("/w/wizard"),
|
||||||
|
"resuming wizard works"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -23,6 +23,10 @@ wizard.resume_on_revisit = false;
|
||||||
wizard.submission_last_updated_at = "2022-03-11T20:00:18+01:00";
|
wizard.submission_last_updated_at = "2022-03-11T20:00:18+01:00";
|
||||||
wizard.subscribed = false;
|
wizard.subscribed = false;
|
||||||
|
|
||||||
|
const wizardResumeOnRevisit = cloneJSON(wizard);
|
||||||
|
wizardResumeOnRevisit.start = "step_2";
|
||||||
|
wizardResumeOnRevisit.resume_on_revisit = true;
|
||||||
|
|
||||||
const stepNotPermitted = cloneJSON(wizard);
|
const stepNotPermitted = cloneJSON(wizard);
|
||||||
stepNotPermitted.steps[0].permitted = false;
|
stepNotPermitted.steps[0].permitted = false;
|
||||||
|
|
||||||
|
@ -44,6 +48,7 @@ export {
|
||||||
wizardNotPermitted,
|
wizardNotPermitted,
|
||||||
wizardCompleted,
|
wizardCompleted,
|
||||||
wizardGuest,
|
wizardGuest,
|
||||||
|
wizardResumeOnRevisit,
|
||||||
stepNotPermitted,
|
stepNotPermitted,
|
||||||
allFieldsWizard,
|
allFieldsWizard,
|
||||||
wizard,
|
wizard,
|
||||||
|
|
Laden …
In neuem Issue referenzieren