module Decisions.UpdateTest exposing (all) import Test exposing (Test, test, describe) import Expect import Dict import Decisions.Update exposing (..) import Decisions.Messages exposing (..) import Decisions.Model as Model import Decisions.Update import InputTable.Model exposing (..) import InputTable.Messages all : Test all = describe "Decisions.Update.update" [ test """should make rows disabled when a TableMsg containing a SelectDropdownParent is passed to update and table update should occur as usual""" <| \() -> let msg = Table (InputTable.Messages.SelectDropdownParent "1" "DECISIONS_ID" "Advance" (Decisions.Update.makeNestedColumnSetter "DECISIONS_ID") ) ( newModel, cmd ) = update config msg initialModel disabledMessages = newModel.tableState.rows |> List.map (.disabledMsg) updatedRowValue = newModel.tableState.rows |> List.filter (.id >> (==) "1") |> List.map (.data >> .nestedStringDictData) |> List.map (Dict.get "DECISIONS_ID") in Expect.equal ( disabledMessages, updatedRowValue ) ( [ Just "Submission has been moved to another stage", Nothing ], [ Just { parent = "Advance", child = Nothing } ] ) , test """should set decisions text and set rows with the entered ids to checked when passed SetBulkDecisionsText""" <| \() -> let msg = SetBulkDecisionsText "not an id\n 2 " testTableState = { tableState | rows = [ row1 , { id = "3" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "0", { value = "2", link = Nothing } ) , ( "y", { value = "valy2", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx2", child = Just "childx2" } ) , ( "nestedy", { parent = "parenty2", child = Nothing } ) ] , decision = "asdf" , presentationType = Nothing } , checked = False , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } ] } ( newModel, cmd ) = update config msg { initialModel | tableState = testTableState } expectedTableState = { tableState | rows = [ row1 , { id = "3" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "0", { value = "2", link = Nothing } ) , ( "y", { value = "valy2", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx2", child = Just "childx2" } ) , ( "nestedy", { parent = "parenty2", child = Nothing } ) ] , decision = "asdf" , presentationType = Nothing } , checked = True , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } ] } in Expect.equal newModel { initialModel | tableState = expectedTableState , bulkDecisionsText = "not an id\n 2 " } , test """should set decisions in rows with ids in the bulk decision id input to the specified decision when passed SelectBulkDecision""" <| \() -> let msg = SelectBulkDecision "Accepted" (Just "Oral") testTableState = { tableState | rows = [ row1 , { id = "3" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "0", { value = "2", link = Nothing } ) , ( "y", { value = "valy2", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx2", child = Just "childx2" } ) , ( "nestedy", { parent = "parenty2", child = Nothing } ) ] , decision = "Pending" , presentationType = Nothing } , checked = False , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } ] } ( newModel, cmd ) = update config msg { initialModel | bulkDecisionsText = "not an id\n 2 " , showBulkDecisions = True , showBulkDecisionsDropdown = True , tableState = testTableState } expectedTableState = { tableState | rows = [ row1 , { id = "3" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "0", { value = "2", link = Nothing } ) , ( "y", { value = "valy2", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx2", child = Just "childx2" } ) , ( "nestedy", { parent = "parenty2", child = Nothing } ) ] , decision = "Accepted" , presentationType = Just "Oral" } , checked = False , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } ] } in Expect.equal newModel { initialModel | tableState = expectedTableState , bulkDecisionsText = "not an id\n 2 " , showBulkDecisions = False , showBulkDecisionsDropdown = False } ] config : { postRowsUrl : String, postVisibleColumnsUrl : String, currentPage : Int } config = { postRowsUrl = "url stub" , postVisibleColumnsUrl = "url stub" , currentPage = 1 } initialModel : Model.Model initialModel = { tableState = tableState , decisionFilter = Model.NoFilter , postMessage = "none" , incompleteColumnAndText = Just ( 1, "No" ) , isLoadingInitialRows = True , showBulkDecisions = True , bulkDecisionsText = "" , showBulkDecisionsDropdown = True , focussedBulkDecisionOption = Nothing , hasBulkDecisions = True , bulkDecisionsOptions = [] , urlQuery = "" } tableState : InputTable.Model.TableState Model.RowData Person tableState = { columns = columns , rows = rows , accordionColumns = Nothing , searchText = "" , showVisibleColumnsUi = False , sorting = InputTable.Model.NoSorting , pageSize = Just 50 , currentPage = 1 , rowsAreSelectable = False , sideBarHeaders = Just [] , sideBarRowId = Nothing , tableAction = Nothing , hasSideTable = False , sideColumns = [ SideColumn "Name" .name , SideColumn "Email" .email ] , sideRows = [] , showSideTable = False , sideSearchText = "" , cannotAssignSideRowsReason = Nothing , sideTableIsAssigning = False , sideTableAction = "" , sideTablePreposition = "" , focussedRow = Nothing , rowIdsToTitles = Dict.empty , savingState = None } columns : List (InputTable.Model.Column Model.RowData) columns = [ { id = "1" , name = "col1" , visible = True , hasNumericalValues = False , subType = InputTable.Model.DisplayColumn { get = (\r -> "x") {- function to get data from row data -} , filter = "" {- filter string -} , getSortVal = Nothing } {- contains options specific to column sub type -} , description = "" } , { id = "DECISIONS_ID" , name = "col2" , visible = True , hasNumericalValues = False , subType = InputTable.Model.SubDropdownColumn { get = Decisions.Update.makeNestedColumnGetter "DECISIONS_ID" , set = Decisions.Update.makeNestedColumnSetter "DECISIONS_ID" , filter = "" , options = [ { parent = "parentx1" {- parent level dropdown text -} , isSelectable = True {- decides parent can be selected -} , childHeader = Nothing {- header a top of children list text -} , children = [ "childx1" ] {- list of children -} } ] , focussedRowId = Nothing , focussedOption = Nothing } {- contains options specific to column sub type -} , description = "" } ] rows : List (InputTable.Model.Row Model.RowData) rows = [ row1, row2 ] row1 : InputTable.Model.Row Model.RowData row1 = { id = "1" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "x", { value = "valx1", link = Nothing } ) , ( "y", { value = "valy1", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx1", child = Just "childx1" } ) , ( "nestedy", { parent = "parenty1", child = Nothing } ) ] , decision = "asdf" , presentationType = Nothing } , checked = False , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } row2 : InputTable.Model.Row Model.RowData row2 = { id = "2" , checkboxDisabledMsg = Nothing , data = { stringDictData = Dict.fromList [ ( "x", { value = "valx2", link = Nothing } ) , ( "y", { value = "valy2", link = Nothing } ) ] , boolDictData = Dict.empty , nestedStringDictData = Dict.fromList [ ( "nestedx", { parent = "parentx2", child = Just "childx2" } ) , ( "nestedy", { parent = "parenty2", child = Nothing } ) ] , decision = "asdf" , presentationType = Nothing } , checked = False , disabledMsg = Nothing , accordionRows = Nothing , accordionExpanded = False , rowFocusUrl = Nothing } type alias Person = { name : String , email : String }