Skip to content

Commit

Permalink
Use Unquote for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Oct 13, 2019
1 parent 702922e commit 469d959
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 302 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "5.223.0",
"version": "5.224.0",
"commands": [
"paket"
]
Expand Down
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ nuget Selenium.WebDriver.ChromeDriver
github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fsi
github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fs
nuget Nerdbank.GitVersioning copy_local: true
nuget Unquote

group fake
source https://api.nuget.org/v3/index.json
Expand All @@ -40,4 +41,4 @@ nuget Fake.IO.FileSystem
nuget Fake.DotNet.AssemblyInfoFile
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget FSharp.Data ~> 3.0-beta
nuget FSharp.Data ~> 3.0-beta
18 changes: 10 additions & 8 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ NUGET
Microsoft.AspNetCore.SpaServices.Extensions (3.0) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.AspNetCore.SpaServices (>= 3.0) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.Extensions.FileProviders.Physical (>= 3.0) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.Build.Framework (16.0.461)
Microsoft.Build.Framework (16.3)
System.Runtime.Serialization.Primitives (>= 4.1.1)
System.Threading.Thread (>= 4.0)
Microsoft.Build.Utilities.Core (15.9.20)
Expand All @@ -72,17 +72,17 @@ NUGET
System.Collections.Immutable (>= 1.5)
System.Runtime.InteropServices.RuntimeInformation (>= 4.3)
System.Text.Encoding.CodePages (>= 4.4)
Microsoft.CodeAnalysis.Analyzers (2.9.4) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Common (3.3) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Analyzers (>= 2.9.3)
Microsoft.CodeAnalysis.Analyzers (2.9.6) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Common (3.3.1) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Analyzers (>= 2.9.4)
System.Collections.Immutable (>= 1.5)
System.Memory (>= 4.5.3)
System.Reflection.Metadata (>= 1.6)
System.Runtime.CompilerServices.Unsafe (>= 4.5.2)
System.Text.Encoding.CodePages (>= 4.5.1)
System.Threading.Tasks.Extensions (>= 4.5.3)
Microsoft.CodeAnalysis.CSharp (3.3) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Common (3.3)
Microsoft.CodeAnalysis.CSharp (3.3.1) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.CodeAnalysis.Common (3.3.1)
Microsoft.CodeAnalysis.Razor (3.0) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp3.0))
Microsoft.AspNetCore.Razor.Language (>= 3.0)
Microsoft.CodeAnalysis.Common (>= 3.3)
Expand Down Expand Up @@ -173,11 +173,11 @@ NUGET
System.Threading (>= 4.3)
Mono.WebAssembly.Interop (3.0)
Microsoft.JSInterop (>= 3.0)
Nerdbank.GitVersioning (3.0.25) - copy_local: true
Nerdbank.GitVersioning (3.0.26) - copy_local: true
NETStandard.Library (2.0.3)
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (12.0.2)
NuGet.Frameworks (5.2) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp1.0) (>= uap10.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
NuGet.Frameworks (5.3) - restriction: || (== netcoreapp3.0) (&& (== netstandard2.0) (>= netcoreapp1.0) (>= uap10.0)) (&& (== netstandard2.0) (>= netcoreapp2.1))
nunit (3.12)
NETStandard.Library (>= 2.0)
NUnit3TestAdapter (3.15.1)
Expand Down Expand Up @@ -633,6 +633,8 @@ NUGET
FSharp.Core (>= 4.1.17)
NETStandard.Library (>= 1.6.1)
System.ValueTuple (>= 4.4)
Unquote (4.0)
FSharp.Core (>= 4.2.3)
GITHUB
remote: fsprojects/FSharp.TypeProviders.SDK
src/ProvidedTypes.fs (b8727a47dd83d3e88aed8f2100f6712478c64632)
Expand Down
43 changes: 21 additions & 22 deletions tests/Unit/Fixture.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ open System
open System.Threading.Tasks
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting
open FSharp.Quotations
open NUnit.Framework
open OpenQA.Selenium
open OpenQA.Selenium.Chrome
// open OpenQA.Selenium.Firefox
open OpenQA.Selenium.Remote
open OpenQA.Selenium.Support.UI
open Swensen.Unquote
open Bolero.Tests

/// Defines the setup/teardown for all tests that use the web server and Selenium.
/// These web tests must be located in the namespace Bolero.Tests.Web
Expand Down Expand Up @@ -136,28 +139,24 @@ and NodeFixture(parent: unit -> IWebElement, by: By) =
timeout |> Option.defaultWith (fun () -> TimeSpan.FromSeconds(5.)))
.Until(fun _ -> cond())

/// NUnit assertion that the given condition eventually becomes non-null non-false.
member this.AssertEventually(cond, ?message, ?timeout) =
let run() =
match this.Wait(cond, ?timeout = timeout) |> box with
| :? bool as b -> Assert.IsTrue(b)
| x -> Assert.IsNotNull(x)
match message with
| None -> Assert.DoesNotThrow(TestDelegate run)
| Some m -> Assert.DoesNotThrow(TestDelegate run, m)

/// NUnit assertion that the actual value eventually becomes equal to the expected value.
member this.AssertAreEqualEventually(expected, getActual, ?message: string, ?timeout) =
let mutable actual = Unchecked.defaultof<_>
try this.Wait(
(fun () ->
actual <- getActual()
expected = actual),
?timeout = timeout) |> ignore
with :? WebDriverTimeoutException -> ()
match message with
| None -> Assert.AreEqual(expected, actual)
| Some m -> Assert.AreEqual(expected, actual, m)
member private this.WaitOrFalse(f: unit -> bool) =
try this.Wait(f)
with :? WebDriverTimeoutException -> false

/// Assert that the given test eventually succeeds.
member this.Eventually(expr: Expr<bool>) =
if not (this.WaitOrFalse(fun () -> eval expr)) then
test expr

/// Assert that the given value is eventually null.
member this.EventuallyNull<'T when 'T : null>(expr: Expr<'T>) =
if not (this.WaitOrFalse(fun () -> isNull <| eval expr)) then
testNull expr

/// Assert that the given value is eventually non-null.
member this.EventuallyNotNull<'T when 'T : null>(expr: Expr<'T>) =
if not (this.WaitOrFalse(fun () -> isNotNull <| eval expr)) then
testNotNull expr

[<AutoOpen>]
module Extensions =
Expand Down
18 changes: 7 additions & 11 deletions tests/Unit/Tests/Elmish.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Bolero.Tests.Web

open NUnit.Framework
open OpenQA.Selenium
open Swensen.Unquote
open Bolero.Tests

/// Elmish program integration.
[<Category "Elmish">]
Expand All @@ -11,29 +13,23 @@ module Elmish =

[<Test>]
let ``ProgramComponent is rendered``() =
Assert.IsNotNull(elt.ByClass("container"))
Assert.AreEqual(
"constant value",
elt.ByClass("constValue-input").GetAttribute("value"))
testNotNull <@ elt.ByClass("container") @>
test <@ elt.ByClass("constValue-input").GetAttribute("value") = "constant value" @>

[<Test; NonParallelizable>]
let ``Input event handler dispatches message``() =
let el = elt.ByClass("stringValue-input")
el.SendKeys("Changed!")
el.SendKeys(Keys.Backspace)
elt.AssertAreEqualEventually(
"stringValueInitChanged",
(fun () -> elt.ByClass("stringValue-repeat").Text),
"Element not updated")
elt.Eventually <@ elt.ByClass("stringValue-repeat").Text = "stringValueInitChanged" @>

[<Test>]
let ``ElmishComponent is rendered``() =
Assert.IsNotNull(elt.ByClass("intValue-input"))
testNotNull <@ elt.ByClass("intValue-input") @>

[<Test>]
let ``ElmishComponent dispatches message``() =
let el = elt.ByClass("intValue-input")
el.Clear()
el.SendKeys("35")
elt.AssertEventually((fun () ->
elt.ByClass("intValue-repeat").Text = "35"))
elt.Eventually <@ elt.ByClass("intValue-repeat").Text = "35" @>
Loading

0 comments on commit 469d959

Please sign in to comment.