From 33a2a9b68f610c9c3cd826dba8d4356ccd96b4f2 Mon Sep 17 00:00:00 2001 From: Gabriel Dutra Date: Sat, 29 Feb 2020 08:55:26 -0300 Subject: [PATCH 1/2] Normalize snippets null description to empty string --- client/app/components/query-snippets/QuerySnippetDialog.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/app/components/query-snippets/QuerySnippetDialog.jsx b/client/app/components/query-snippets/QuerySnippetDialog.jsx index 57d0067e54..cb75db6a22 100644 --- a/client/app/components/query-snippets/QuerySnippetDialog.jsx +++ b/client/app/components/query-snippets/QuerySnippetDialog.jsx @@ -1,6 +1,6 @@ import React from "react"; import PropTypes from "prop-types"; -import { get } from "lodash"; +import { get, isNil } from "lodash"; import Button from "antd/lib/button"; import Modal from "antd/lib/modal"; import DynamicForm from "@/components/dynamic-form/DynamicForm"; @@ -28,6 +28,10 @@ class QuerySnippetDialog extends React.Component { const { querySnippet, dialog, onSubmit } = this.props; const querySnippetId = get(querySnippet, "id"); + if (isNil(values.description)) { + values.description = ""; + } + this.setState({ saving: true }); onSubmit(querySnippetId ? { id: querySnippetId, ...values } : values) .then(() => { From efa593936444a7ea3c694a00f7b7763f9ecb4ee3 Mon Sep 17 00:00:00 2001 From: Gabriel Dutra Date: Sat, 29 Feb 2020 09:30:17 -0300 Subject: [PATCH 2/2] Cypress: add create query snippet spec --- client/app/components/AceEditorInput.jsx | 2 +- .../query-snippets/QuerySnippetDialog.jsx | 8 +++++-- .../create_query_snippet_spec.js | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 client/cypress/integration/query-snippets/create_query_snippet_spec.js diff --git a/client/app/components/AceEditorInput.jsx b/client/app/components/AceEditorInput.jsx index eee7e08305..22b45bad73 100644 --- a/client/app/components/AceEditorInput.jsx +++ b/client/app/components/AceEditorInput.jsx @@ -5,7 +5,7 @@ import "./AceEditorInput.less"; function AceEditorInput(props, ref) { return ( -
+
+ form="querySnippetForm" + data-test="SaveQuerySnippetButton"> {isEditing ? "Save" : "Create"} ), - ]}> + ]} + wrapProps={{ + "data-test": "QuerySnippetDialog", + }}> { + beforeEach(() => { + cy.login(); + cy.visit("/query_snippets/new"); + }); + + it("creates a query snippet with an empty description", () => { + // delete existing "example-snippet" + cy.request("GET", "api/query_snippets") + .then(({ body }) => body.filter(snippet => snippet.trigger === "example-snippet")) + .each(snippet => cy.request("DELETE", `api/query_snippets/${snippet.id}`)); + + cy.getByTestId("QuerySnippetDialog").within(() => { + cy.getByTestId("Trigger").type("example-snippet"); + cy.getByTestId("Snippet") + .find(".ace_text-input") + .type("SELECT 1", { force: true }); + }); + + cy.getByTestId("SaveQuerySnippetButton").click(); + }); +});