Skip to content

Commit

Permalink
LEAF 4604 update form structure and nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
aerinkayne committed Dec 9, 2024
1 parent 080f2ca commit b1ead14
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 56 deletions.
27 changes: 13 additions & 14 deletions API-tests/database/portal_test_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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` (
Expand Down
77 changes: 35 additions & 42 deletions API-tests/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
}
}
}

0 comments on commit b1ead14

Please sign in to comment.