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

FIX: Empty param-form should reject submit #309

Merged
merged 2 commits into from
Aug 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ export default class ParamInputForm extends Component {
if (this.form == null) {
throw "No form";
}
this.serializedData = null;
await this.form.submit();
if (this.serializedData == null) {
throw new ParamValidationError("validation_failed");
Expand All @@ -293,7 +294,6 @@ export default class ParamInputForm extends Component {

@action
onSubmit(data) {
this.serializedData = null;
const serializedData = {};
for (const [id, val] of Object.entries(data)) {
serializedData[id] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class GroupReportsShowController extends Controller {
} catch (error) {
if (error.jqXHR?.status === 422 && error.jqXHR.responseJSON) {
this.results = error.jqXHR.responseJSON;
} else if (error instanceof ParamValidationError) {
} else if (!(error instanceof ParamValidationError)) {
popupAjaxError(error);
}
} finally {
Expand Down
32 changes: 32 additions & 0 deletions test/javascripts/components/param-input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,36 @@ module("Data Explorer Plugin | Component | param-input", function (hooks) {
});
}
}

test("empty form will reject submit", async function (assert) {
this.setProperties({
param_info: [
{
identifier: "string",
type: "string",
default: null,
nullable: false,
},
],
initialValues: {},
onRegisterApi: ({ submit }) => {
this.submit = submit;
},
});

await render(hbs`
<ParamInputForm
@initialValues={{this.initialValues}}
@paramInfo={{this.param_info}}
@onRegisterApi={{this.onRegisterApi}}
/>`);

assert.rejects(this.submit());

// After successfully submitting the test once, edit and submit again.
await fillIn(`[name="string"]`, "foo");
await this.submit();
await fillIn(`[name="string"]`, "");
assert.rejects(this.submit());
});
});