From 080f2caf8f41eb2e461192e5ddb0505423a7ac91 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Wed, 4 Dec 2024 08:29:12 -0500 Subject: [PATCH 1/3] test 4604 add form with ifthen and required questions, go test for get progress --- API-tests/database/portal_test_db.sql | 19 ++- API-tests/form_test.go | 225 ++++++++++++++++++++++++++ 2 files changed, 242 insertions(+), 2 deletions(-) diff --git a/API-tests/database/portal_test_db.sql b/API-tests/database/portal_test_db.sql index 9fc3118e4..f99d0d126 100644 --- a/API-tests/database/portal_test_db.sql +++ b/API-tests/database/portal_test_db.sql @@ -123,7 +123,8 @@ INSERT INTO `categories` (`categoryID`, `parentID`, `categoryName`, `categoryDes ('form_ce46b', '', 'Simple form', '', 1, 0, 1, NULL, 1, 0, '', NULL, 1697476029), ('form_f8b95', '', 'Multiple person designated', '', 4, 0, 1, NULL, 1, 0, '', NULL, 1698274593), ('leaf_devconsole', '', 'LEAF Developer Console', '', -2, 0, 0, NULL, 1, 0, '', NULL, 0), -('leaf_secure', '', 'Leaf Secure Certification', '', -1, 0, 0, NULL, 1, 0, '', NULL, 0); +('leaf_secure', '', 'Leaf Secure Certification', '', -1, 0, 0, NULL, 1, 0, '', NULL, 0), +('form_7664a', '', 'IFTHEN display status progress checking', '', 1, 0, 0, NULL, 1, 0, '', NULL, 1733265434); DROP TABLE IF EXISTS `category_count`; CREATE TABLE `category_count` ( @@ -6219,7 +6220,21 @@ INSERT INTO `indicators` (`indicatorID`, `name`, `format`, `description`, `defau (12, 'Single line text', 'text', '', '', NULL, 'form_2d609', NULL, NULL, NULL, NULL, 0, 0, '2023-10-17 14:48:05', 0, 0), (13, 'Single line text', 'text', '', '', NULL, 'form_a9b9f', NULL, NULL, NULL, NULL, 0, 0, '2023-10-17 14:59:56', 0, 0), (14, 'Reviewer 1', 'orgchart_employee', '', '', NULL, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:24', 0, 0), -(15, 'Reviewer 2', 'orgchart_employee', '', '', 14, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:33', 0, 0); +(15, 'Reviewer 2', 'orgchart_employee', '', '', 14, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:33', 0, 0), +(16, 'Section 1', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-03 22:25:44', 0, 0), +(17, 'Section 2', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -127, '2024-12-03 22:25:50', 0, 0), +(18, 'Section 3', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -126, '2024-12-03 22:25:57', 0, 0), +(19, 'dropdown parent', 'dropdown\n\n1\n2\n3', '', '', 16, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:26:19', 0, 0), +(20, 'radio child (show if parent 2)', 'radio\nA\nB\nC', '', '', 19, 'form_7664a', NULL, NULL, '[{\"childIndID\":20,\"parentIndID\":19,\"selectedOp\":\"==\",\"selectedParentValue\":\"2\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"radio\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-03 22:26:43', 0, 0), +(21, 'normal nested currency sub question', 'currency', '', '', 20, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:27:10', 0, 0), +(22, 'normal nested text sub question', 'text', '', '', 20, 'form_7664a', NULL, NULL, NULL, NULL, 1, -127, '2024-12-03 22:28:28', 0, 0), +(23, 'numeric parent', 'number', '', '', 17, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:29:56', 0, 0), +(24, 'orgchart employee child (show if parent >= 42)', 'orgchart_employee', '', '', 23, 'form_7664a', NULL, NULL, '[{\"childIndID\":24,\"parentIndID\":23,\"selectedOp\":\"gte\",\"selectedParentValue\":\"42\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"orgchart_employee\",\"parentFormat\":\"number\"}]', NULL, 1, -128, '2024-12-03 22:30:57', 0, 0), +(25, 'normal nested date sub question', 'date', '', '', 24, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:31:16', 0, 0), +(26, 'normal nested multitext sub question', 'textarea', '', '', 24, 'form_7664a', NULL, NULL, NULL, NULL, 1, -127, '2024-12-03 22:31:40', 0, 0), +(27, 'checkboxes parent', 'checkboxes\nA & B\nC & D\nE & \"F\"', '', '', 18, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:33:14', 0, 0), +(28, 'multiselect child (show if parent E & "F")', 'multiselect\napple\norange\nbanana\npineapple\navocado', '', '', 27, 'form_7664a', NULL, NULL, '[{\"childIndID\":28,\"parentIndID\":27,\"selectedOp\":\"==\",\"selectedParentValue\":\"E & "F"\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"multiselect\",\"parentFormat\":\"checkboxes\"}]', NULL, 1, -128, '2024-12-03 22:36:21', 0, 0), +(29, 'normal nested checkbox child', 'checkbox\ntest', '', '', 28, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:37:14', 0, 0); DROP TABLE IF EXISTS `notes`; CREATE TABLE `notes` ( diff --git a/API-tests/form_test.go b/API-tests/form_test.go index 873b01848..12fa67123 100644 --- a/API-tests/form_test.go +++ b/API-tests/form_test.go @@ -168,3 +168,228 @@ func TestForm_FilterChildkeys(t *testing.T) { t.Errorf("./api/form/9/data/tree?x-filterData=child.name child[4].indicatorID = %v, want = %v", m[0].Child[4].IndicatorID, "undefined") } } + +func TestForm_GetProgress_ReturnValue(t *testing.T) { + /* + Setup form_7664a. 11 required questions with different formats (format influences logic). + 19 controls 20, which has subquestions 21, 22. visible if 19 is '2' + 23 controls 24, which has subquestions 25, 26. visible if 23 is >= '42' + 27 controls 28, which has subquestion 29. visible if 27 includes 'E & "F"' + Format information is noted when data is posted */ + + //create the new request and get the recordID for progress and domodify urls, check intial progress. + postData := url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("numform_7664a", "1") + postData.Set("title", "TestForm_GetProgressChecking") + + res, _ := client.PostForm(RootURL + `api/form/new`, postData) + bodyBytes, _ := io.ReadAll(res.Body) + var response string + json.Unmarshal(bodyBytes, &response) + recordID := string(response) + + urlGetProgress := RootURL + "api/form/" + recordID + "/progress" + urlPostDoModify := RootURL + "api/form/" + recordID + + got, res := httpGet(urlGetProgress) + if !cmp.Equal(res.StatusCode, 200) { + t.Errorf(urlGetProgress + ", Status Code = %v, want = %v", res.StatusCode, 200) + return + } + want := `"0"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + //fill 3 visible required questions with values that keep subquestions hidden + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("19", "1") //dropdown 1,2,3 + res, err := client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"33"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("23", "10") //numeric + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"67"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("27", "A & B") //checkboxes A & B, C & D, E & "F" + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"100"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + + //fill 19 to display 20,21,22 (3/6) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("19", "2") //dropdown 1,2,3 + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"50"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + //fill new visible required questions (4/6, 5/6, 6/6) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("20", "A") //radio A, B, C + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"67"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("21", "2") //currency + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"83"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("22", "test") //single text + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"100"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + + //fill 23 to display 24,25,26 (6/9) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("23", "42") //numeric + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"67"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + //fill new visible required questions (7/9, 8/9, 9/9) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("24", "1") //orgchart employee + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"78"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("25", "12/04/2024") //date + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"89"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("26", "test") //multiline text + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"100"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + //fill 27 to display 28, 29 (9/11) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("27", `E & "F"`) //checkboxes A & B, C & D, E & "F" + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"82"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + //fill new visible required questions (10/11, 11/11) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("28", "apple") //multiselect apple, orange, banana, pineapple, avocado + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"91"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("29", "test") //checkbox, label is 'test' + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"100"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } +} From b1ead147f22579cbf8c16bff286a6edde8c69584 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 9 Dec 2024 09:31:44 -0500 Subject: [PATCH 2/3] LEAF 4604 update form structure and nesting --- API-tests/database/portal_test_db.sql | 27 +++++----- API-tests/form_test.go | 77 ++++++++++++--------------- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/API-tests/database/portal_test_db.sql b/API-tests/database/portal_test_db.sql index f99d0d126..df5530c8d 100644 --- a/API-tests/database/portal_test_db.sql +++ b/API-tests/database/portal_test_db.sql @@ -6221,20 +6221,19 @@ INSERT INTO `indicators` (`indicatorID`, `name`, `format`, `description`, `defau (13, 'Single line text', 'text', '', '', NULL, 'form_a9b9f', NULL, NULL, NULL, NULL, 0, 0, '2023-10-17 14:59:56', 0, 0), (14, 'Reviewer 1', 'orgchart_employee', '', '', NULL, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:24', 0, 0), (15, 'Reviewer 2', 'orgchart_employee', '', '', 14, 'form_f8b95', NULL, NULL, NULL, NULL, 1, 0, '2023-10-25 22:56:33', 0, 0), -(16, 'Section 1', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-03 22:25:44', 0, 0), -(17, 'Section 2', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -127, '2024-12-03 22:25:50', 0, 0), -(18, 'Section 3', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -126, '2024-12-03 22:25:57', 0, 0), -(19, 'dropdown parent', 'dropdown\n\n1\n2\n3', '', '', 16, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:26:19', 0, 0), -(20, 'radio child (show if parent 2)', 'radio\nA\nB\nC', '', '', 19, 'form_7664a', NULL, NULL, '[{\"childIndID\":20,\"parentIndID\":19,\"selectedOp\":\"==\",\"selectedParentValue\":\"2\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"radio\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-03 22:26:43', 0, 0), -(21, 'normal nested currency sub question', 'currency', '', '', 20, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:27:10', 0, 0), -(22, 'normal nested text sub question', 'text', '', '', 20, 'form_7664a', NULL, NULL, NULL, NULL, 1, -127, '2024-12-03 22:28:28', 0, 0), -(23, 'numeric parent', 'number', '', '', 17, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:29:56', 0, 0), -(24, 'orgchart employee child (show if parent >= 42)', 'orgchart_employee', '', '', 23, 'form_7664a', NULL, NULL, '[{\"childIndID\":24,\"parentIndID\":23,\"selectedOp\":\"gte\",\"selectedParentValue\":\"42\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"orgchart_employee\",\"parentFormat\":\"number\"}]', NULL, 1, -128, '2024-12-03 22:30:57', 0, 0), -(25, 'normal nested date sub question', 'date', '', '', 24, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:31:16', 0, 0), -(26, 'normal nested multitext sub question', 'textarea', '', '', 24, 'form_7664a', NULL, NULL, NULL, NULL, 1, -127, '2024-12-03 22:31:40', 0, 0), -(27, 'checkboxes parent', 'checkboxes\nA & B\nC & D\nE & \"F\"', '', '', 18, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:33:14', 0, 0), -(28, 'multiselect child (show if parent E & "F")', 'multiselect\napple\norange\nbanana\npineapple\navocado', '', '', 27, 'form_7664a', NULL, NULL, '[{\"childIndID\":28,\"parentIndID\":27,\"selectedOp\":\"==\",\"selectedParentValue\":\"E & "F"\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"multiselect\",\"parentFormat\":\"checkboxes\"}]', NULL, 1, -128, '2024-12-03 22:36:21', 0, 0), -(29, 'normal nested checkbox child', 'checkbox\ntest', '', '', 28, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-03 22:37:14', 0, 0); +(16, 'Section 1', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-09 13:38:21', 0, 0), +(17, 'dropdown parent', 'dropdown\r\n\r\n1\r\n2\r\n3', '', '', 16, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(18, 'radio child (show if parent 2)', 'radio\r\nA\r\nB\r\nC', '', '', 17, 'form_7664a', '', '', '[{\"childIndID\":18,\"parentIndID\":17,\"selectedOp\":\"==\",\"selectedParentValue\":\"2\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"radio\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(19, 'normal nested currency sub question', 'currency', '', '', 18, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(20, 'normal nested text sub question', 'text', '', '', 19, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(21, 'Section 2', '', '', '', NULL, 'form_7664a', NULL, NULL, NULL, NULL, 0, -127, '2024-12-09 13:38:21', 0, 0), +(22, 'numeric parent', 'number', '', '', 21, 'form_7664a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(23, 'orgchart employee child (show if parent >= 42)', 'orgchart_employee', '', '', 22, 'form_7664a', '', '', '[{\"childIndID\":23,\"parentIndID\":22,\"selectedOp\":\"gte\",\"selectedParentValue\":\"42\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"orgchart_employee\",\"parentFormat\":\"number\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(24, 'normal nested date sub question', 'date', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(25, 'normal nested multitext sub question', 'textarea', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -127, '2024-12-09 13:38:21', 0, 0), +(26, 'checkboxes parent', 'checkboxes\r\nA & B\r\nC & D\r\nE & \"F\"', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -126, '2024-12-09 13:38:21', 0, 0), +(27, 'multiselect child (show if parent E & "F")', 'multiselect\r\napple\r\norange\r\nbanana\r\npineapple\r\navocado', '', '', 26, 'form_7664a', '', '', '[{\"childIndID\":27,\"parentIndID\":26,\"selectedOp\":\"==\",\"selectedParentValue\":\"E & "F"\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"multiselect\",\"parentFormat\":\"checkboxes\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(28, 'normal nested checkbox child', 'checkbox\r\ntest', '', '', 27, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0); DROP TABLE IF EXISTS `notes`; CREATE TABLE `notes` ( diff --git a/API-tests/form_test.go b/API-tests/form_test.go index 12fa67123..775476626 100644 --- a/API-tests/form_test.go +++ b/API-tests/form_test.go @@ -170,11 +170,10 @@ func TestForm_FilterChildkeys(t *testing.T) { } func TestForm_GetProgress_ReturnValue(t *testing.T) { - /* - Setup form_7664a. 11 required questions with different formats (format influences logic). - 19 controls 20, which has subquestions 21, 22. visible if 19 is '2' - 23 controls 24, which has subquestions 25, 26. visible if 23 is >= '42' - 27 controls 28, which has subquestion 29. visible if 27 includes 'E & "F"' + /* Setup form_7664a. 11 required questions with different formats (format influences logic). + 17p controls 18c. 18c has subquestions 19, 20. 18 is visible if 17 is '2' + 22p controls 23c. 23c has subquestions 24, 25, (26p, 27c, 28). 23 is visible if 22 is >= '42' + -26p controls 27c. 27c has subquestion 28. 27 is visible if 26 includes 'E & "F"' Format information is noted when data is posted */ //create the new request and get the recordID for progress and domodify urls, check intial progress. @@ -202,106 +201,104 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { t.Errorf("progress check got = %v, want = %v", got, want) } - //fill 3 visible required questions with values that keep subquestions hidden + //fill 2 visible required questions with values that keep subquestions hidden postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("19", "1") //dropdown 1,2,3 + postData.Set("17", "1") //dropdown 1,2,3 res, err := client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"33"` + want = `"50"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("23", "10") //numeric + postData.Set("22", "10") //numeric res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"67"` + want = `"100"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } + + //fill 17 to display 18,19,20 (2/5) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("27", "A & B") //checkboxes A & B, C & D, E & "F" + postData.Set("17", "2") //dropdown 1,2,3 res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"100"` + want = `"40"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - - //fill 19 to display 20,21,22 (3/6) + //fill new visible required questions (3/5, 4/5, 5/5) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("19", "2") //dropdown 1,2,3 + postData.Set("18", "A") //radio A, B, C res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"50"` + want = `"60"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - - //fill new visible required questions (4/6, 5/6, 6/6) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("20", "A") //radio A, B, C + postData.Set("19", "2") //currency res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"67"` + want = `"80"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("21", "2") //currency + postData.Set("20", "test") //single text res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"83"` + want = `"100"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } + + //fill 22 to display 23,24,25,26 (5/9) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("22", "test") //single text + postData.Set("22", "42") //numeric res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") } got, res = httpGet(urlGetProgress) - want = `"100"` + want = `"56"` if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - - //fill 23 to display 24,25,26 (6/9) + //fill new visible required questions (6/9, 7/9, 8/9, 9/9) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("23", "42") //numeric + postData.Set("23", "1") //orgchart employee res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -311,11 +308,9 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - - //fill new visible required questions (7/9, 8/9, 9/9) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("24", "1") //orgchart employee + postData.Set("24", "12/04/2024") //date res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -325,10 +320,9 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("25", "12/04/2024") //date + postData.Set("25", "test") //multiline text res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -338,10 +332,9 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("26", "test") //multiline text + postData.Set("26", "A & B") //checkboxes A & B, C & D, E & "F" res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -352,10 +345,11 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { t.Errorf("progress check got = %v, want = %v", got, want) } - //fill 27 to display 28, 29 (9/11) + + //fill 26 to display 27, 28 (9/11) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("27", `E & "F"`) //checkboxes A & B, C & D, E & "F" + postData.Set("26", `E & "F"`) //checkboxes A & B, C & D, E & "F" res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -369,7 +363,7 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { //fill new visible required questions (10/11, 11/11) postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("28", "apple") //multiselect apple, orange, banana, pineapple, avocado + postData.Set("27", "apple") //multiselect apple, orange, banana, pineapple, avocado res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -379,10 +373,9 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } - postData = url.Values{} postData.Set("CSRFToken", CsrfToken) - postData.Set("29", "test") //checkbox, label is 'test' + postData.Set("28", "test") //checkbox, label is 'test' res, err = client.PostForm(urlPostDoModify, postData) if err != nil { t.Error(urlPostDoModify + "Error sending post request") @@ -392,4 +385,4 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } -} +} \ No newline at end of file From 04232a1f4531e4931dc0580ac7cd69655d87fe77 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Tue, 10 Dec 2024 10:15:39 -0500 Subject: [PATCH 3/3] LEAF test 4604 add stapled form to test --- API-tests/database/portal_test_db.sql | 11 +++++-- API-tests/form_test.go | 43 ++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/API-tests/database/portal_test_db.sql b/API-tests/database/portal_test_db.sql index df5530c8d..e20bfa2cc 100644 --- a/API-tests/database/portal_test_db.sql +++ b/API-tests/database/portal_test_db.sql @@ -124,7 +124,8 @@ INSERT INTO `categories` (`categoryID`, `parentID`, `categoryName`, `categoryDes ('form_f8b95', '', 'Multiple person designated', '', 4, 0, 1, NULL, 1, 0, '', NULL, 1698274593), ('leaf_devconsole', '', 'LEAF Developer Console', '', -2, 0, 0, NULL, 1, 0, '', NULL, 0), ('leaf_secure', '', 'Leaf Secure Certification', '', -1, 0, 0, NULL, 1, 0, '', NULL, 0), -('form_7664a', '', 'IFTHEN display status progress checking', '', 1, 0, 0, NULL, 1, 0, '', NULL, 1733265434); +('form_7664a', '', 'IFTHEN display status progress checking', '', 1, 0, 0, NULL, 1, 0, '', NULL, 1733265434), +('form_dac2a', '', 'Test IFTHEN staple', '', 0, 10, 0, NULL, 1, 0, '', NULL, 1733840407); DROP TABLE IF EXISTS `category_count`; CREATE TABLE `category_count` ( @@ -1122,6 +1123,8 @@ CREATE TABLE `category_staples` ( CONSTRAINT `category_staples_ibfk_1` FOREIGN KEY (`categoryID`) REFERENCES `categories` (`categoryID`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3; +INSERT INTO `category_staples` (`categoryID`, `stapledCategoryID`) VALUES +('form_7664a', 'form_dac2a'); DROP TABLE IF EXISTS `data`; CREATE TABLE `data` ( @@ -6233,7 +6236,11 @@ INSERT INTO `indicators` (`indicatorID`, `name`, `format`, `description`, `defau (25, 'normal nested multitext sub question', 'textarea', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -127, '2024-12-09 13:38:21', 0, 0), (26, 'checkboxes parent', 'checkboxes\r\nA & B\r\nC & D\r\nE & \"F\"', '', '', 23, 'form_7664a', '', '', NULL, NULL, 1, -126, '2024-12-09 13:38:21', 0, 0), (27, 'multiselect child (show if parent E & "F")', 'multiselect\r\napple\r\norange\r\nbanana\r\npineapple\r\navocado', '', '', 26, 'form_7664a', '', '', '[{\"childIndID\":27,\"parentIndID\":26,\"selectedOp\":\"==\",\"selectedParentValue\":\"E & "F"\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"multiselect\",\"parentFormat\":\"checkboxes\"}]', NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), -(28, 'normal nested checkbox child', 'checkbox\r\ntest', '', '', 27, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0); +(28, 'normal nested checkbox child', 'checkbox\r\ntest', '', '', 27, 'form_7664a', '', '', NULL, NULL, 1, -128, '2024-12-09 13:38:21', 0, 0), +(29, 'Header', '', '', '', NULL, 'form_dac2a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-10 14:19:05', 0, 0), +(30, 'parent dropdown', 'dropdown\n\n1\n2\n3', '', '', 29, 'form_dac2a', NULL, NULL, NULL, NULL, 0, -128, '2024-12-10 14:19:35', 0, 0), +(31, 'child text', 'text', '', '', 30, 'form_dac2a', NULL, NULL, '[{\"childIndID\":31,\"parentIndID\":30,\"selectedOp\":\"==\",\"selectedParentValue\":\"3\",\"selectedChildValue\":\"\",\"selectedOutcome\":\"show\",\"crosswalkFile\":\"\",\"crosswalkHasHeader\":false,\"level2IndID\":null,\"childFormat\":\"text\",\"parentFormat\":\"dropdown\"}]', NULL, 1, -128, '2024-12-10 14:19:47', 0, 0), +(32, 'nested sub question', 'text', '', '', 31, 'form_dac2a', NULL, NULL, NULL, NULL, 1, -128, '2024-12-10 14:20:07', 0, 0); DROP TABLE IF EXISTS `notes`; CREATE TABLE `notes` ( diff --git a/API-tests/form_test.go b/API-tests/form_test.go index 775476626..0effaab8f 100644 --- a/API-tests/form_test.go +++ b/API-tests/form_test.go @@ -170,10 +170,13 @@ func TestForm_FilterChildkeys(t *testing.T) { } func TestForm_GetProgress_ReturnValue(t *testing.T) { - /* Setup form_7664a. 11 required questions with different formats (format influences logic). + /* Setup form_7664a, with staple form_dac2a. + form_7664a has 11 required questions with different formats (format influences logic). 17p controls 18c. 18c has subquestions 19, 20. 18 is visible if 17 is '2' 22p controls 23c. 23c has subquestions 24, 25, (26p, 27c, 28). 23 is visible if 22 is >= '42' -26p controls 27c. 27c has subquestion 28. 27 is visible if 26 includes 'E & "F"' + form_dac2a has 2 required questions + 30p (not required) controls 31c. 31c has subquestion 32. 31 is visisble if 30p is 3 Format information is noted when data is posted */ //create the new request and get the recordID for progress and domodify urls, check intial progress. @@ -385,4 +388,42 @@ func TestForm_GetProgress_ReturnValue(t *testing.T) { if !cmp.Equal(got, want) { t.Errorf("progress check got = %v, want = %v", got, want) } + + //fill staple 30 to display 31c, 32 (11/13) + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("30", "3") //dropdown 1,2,3 + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"85"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("31", "test 31") //text + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"92"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } + postData = url.Values{} + postData.Set("CSRFToken", CsrfToken) + postData.Set("32", "test 32") //text + res, err = client.PostForm(urlPostDoModify, postData) + if err != nil { + t.Error(urlPostDoModify + "Error sending post request") + } + got, res = httpGet(urlGetProgress) + want = `"100"` + if !cmp.Equal(got, want) { + t.Errorf("progress check got = %v, want = %v", got, want) + } } \ No newline at end of file