Skip to content

Commit

Permalink
Add unit tests (Issue #212) ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jul 20, 2022
1 parent 63a6a29 commit 4711417
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/Client/BuildingBlockFunctions.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ let case_tableWithFeaturedCol : Column [] =
}|]
}|]

let case_tableWithSingleCol : Column [] =
[|{
Index = 12
Header = { SwateColumnHeader = "Protocol REF" }
Cells = [|{
Index = 1
Value = Some "My Fancy Protocol Name"
Unit = None
}|]
}|]

open OfficeInterop.BuildingBlockFunctions.Aux_GetBuildingBlocksPostSync


Expand Down Expand Up @@ -233,11 +244,27 @@ let tests_buildingBlockFunctions = testList "BuildingBlockFunctions" [
Expect.isTrue buildingBlock_withMainColumnTerms.[0].hasCompleteTerm "Protocol Type hasCompleteTerm"
Expect.equal buildingBlock_withMainColumnTerms.[0].MainColumnTerm (TermMinimal.create "protocol type" "NFDI4PSO:1000161" |> Some) "MainColumnTerm for 'Protocol Type' differs from expected value"

testCase "BuildingBlocks from case_tableWithSingleCol" <| fun _ ->
let buildingBlocks =
sortColsIntoBuildingBlocks case_tableWithSingleCol
|> List.rev
|> Array.ofList

let buildingBlock_withMainColumnTerms =
buildingBlocks
|> Array.map getMainColumnTerm

Expect.equal buildingBlocks.Length 1 "Different number of BuildingBlocks expected."
Expect.equal buildingBlocks.[0].MainColumn.Header.SwateColumnHeader "Protocol REF" "First Building Block must be 'Protocol REF'."
Expect.isTrue buildingBlocks.[0].MainColumn.Header.isSingleCol "First Building Block must be 'isSingleCol'."
Expect.equal buildingBlock_withMainColumnTerms buildingBlocks "Protocol REF should not change when updating record type with main column terms."

testCase "BuildingBlocks from combined cases" <| fun _ ->

let combinedCases =
// Array.append adds second arr to the end of first arr, so we need to build backwards using the pipe operator
case_tableWithFeaturedCol
case_tableWithSingleCol
|> Array.append case_tableWithFeaturedCol
|> Array.append case_tableWithParamsWithUnit
|> Array.append case_tableWithParameterAndValue

Expand All @@ -250,7 +277,7 @@ let tests_buildingBlockFunctions = testList "BuildingBlockFunctions" [
buildingBlocks
|> Array.map getMainColumnTerm

Expect.equal buildingBlocks.Length 5 "Different number of BuildingBlocks expected."
Expect.equal buildingBlocks.Length 6 "Different number of BuildingBlocks expected."
// Source Name
Expect.equal buildingBlocks.[0].MainColumn.Header.SwateColumnHeader "Source Name" "First Building Block must be 'Source Name'."
Expect.equal buildingBlocks.[0].MainColumn.Cells.[0].Value.Value "test/source/path" ""
Expand Down Expand Up @@ -290,4 +317,8 @@ let tests_buildingBlockFunctions = testList "BuildingBlockFunctions" [
// check main column term correct
Expect.isTrue buildingBlock_withMainColumnTerms.[4].hasCompleteTerm "Protocol Type hasCompleteTerm"
Expect.equal buildingBlock_withMainColumnTerms.[4].MainColumnTerm (TermMinimal.create "protocol type" "NFDI4PSO:1000161" |> Some) "MainColumnTerm for 'Protocol Type' differs from expected value"

// Protocol REF
Expect.equal buildingBlocks.[5].MainColumn.Header.SwateColumnHeader "Protocol REF" "First Building Block must be 'Protocol REF'."
Expect.isTrue buildingBlocks.[5].MainColumn.Header.isSingleCol "First Building Block must be 'isSingleCol'."
]
34 changes: 34 additions & 0 deletions tests/Client/BuildingBlockView.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module BuildingBlockView

open Fable.Mocha
open Client

open Shared.OfficeInteropTypes
open Shared.TermTypes

open BuildingBlock

let tests_BuildingBlockView = testList "BuildingBlockView" [
testCase "isValidBuildingBlock" <| fun _ ->

// only columns which require input, the so called term columns, can be invalid if they don't have a name.
let protocolREF = BuildingBlockNamePrePrint.init(BuildingBlockType.ProtocolREF) |> isValidBuildingBlock
let source = BuildingBlockNamePrePrint.init(BuildingBlockType.Source) |> isValidBuildingBlock
let parameter = BuildingBlockNamePrePrint.create BuildingBlockType.Parameter "instrument model" |> isValidBuildingBlock
let parameter_nonsense = BuildingBlockNamePrePrint.create BuildingBlockType.Parameter "banana balloon animal" |> isValidBuildingBlock
let characteristic = BuildingBlockNamePrePrint.create BuildingBlockType.Characteristics "strain" |> isValidBuildingBlock
let factor = BuildingBlockNamePrePrint.create BuildingBlockType.Characteristics "temperature" |> isValidBuildingBlock
/// Featured column should always be valid
let protocolType = BuildingBlockNamePrePrint.init BuildingBlockType.ProtocolType |> isValidBuildingBlock

let term_empty = BuildingBlockNamePrePrint.create BuildingBlockType.Characteristics "" |> isValidBuildingBlock

Expect.isTrue protocolREF "protocolREF"
Expect.isTrue source "source"
Expect.isTrue parameter "parameter"
Expect.isTrue parameter_nonsense "parameter_nonsense"
Expect.isTrue characteristic "characteristic"
Expect.isTrue factor "factor"
Expect.isTrue protocolType "protocolType"
Expect.isFalse term_empty "term_empty"
]
1 change: 1 addition & 0 deletions tests/Client/Client.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let all =
Shared.Tests.shared
#endif
BuildingBlockFunctions.tests_buildingBlockFunctions
BuildingBlockView.tests_BuildingBlockView
client
]

Expand Down
1 change: 1 addition & 0 deletions tests/Client/Client.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="BuildingBlockView.Tests.fs" />
<Compile Include="BuildingBlockFunctions.Tests.fs" />
<Compile Include="Client.Tests.fs" />
</ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions tests/Shared/OfficeInteropTypes.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ let buildingBlockTypes = testList "buildingBlockTypes" [

Expect.equal header.getFeaturedColAccession "NFDI4PSO:1000161" ""

testCase "Protocol REF" <| fun _ ->
let header = {SwateColumnHeader = BuildingBlockType.ProtocolREF.toString}
Expect.isTrue header.isMainColumn "isMainColumn"
Expect.isTrue header.isSingleCol "isSingleCol"
Expect.isFalse header.isFeaturedCol "isFeaturedCol"
Expect.isFalse header.isInputCol "isInputCol"
Expect.isFalse header.isOutputCol "isOutputCol"
Expect.isFalse header.isUnitCol "isUnitCol"
Expect.isFalse header.isTANCol "isTANCol"
Expect.isFalse header.isTSRCol "isTSRCol"
Expect.isFalse header.isTermColumn "isTermColumn"

testCase "Parameter [instrument model]" <| fun _ ->
let header = {SwateColumnHeader = "Parameter [instrument model]"}

Expand Down

0 comments on commit 4711417

Please sign in to comment.