Skip to content

Commit

Permalink
[#201] Add unit tests for dynamic templates
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Oct 30, 2018
1 parent add7247 commit 83378b7
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 17 deletions.
17 changes: 9 additions & 8 deletions WebSharper.UI.Templating.ServerSide.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,18 @@ let Main = Application.SinglePage(fun ctx ->
)
:> Doc
Template("""
<div>[OK] Inserted using dynamic template</div>
<div>${TextHole}</div>
<div ws-hole="DocHole"></div>
<div class="hidden" ws-attr="AttrHole">[OK] Inserted using dynamic template attr hole</div>
<div ws-onafterrender="OarHole"></div>
<div ws-onmouseenter="EventHole" ws-onafterrender="OarHole2">
<b>[KO] Inserted using dynamic mouse event hole</b>
<div id="dynamic-1">[OK] Inserted using dynamic template</div>
<div id="dynamic-2">${TextHole}</div>
<div id="dynamic-3" ws-hole="DocHole"></div>
<div id="dynamic-4" class="hidden" ws-attr="AttrHole">[OK] Inserted using dynamic template attr hole</div>
<div id="dynamic-5" ws-onafterrender="OarHole"></div>
<div id="dynamic-6" ws-onmouseenter="EventHole" ws-onafterrender="OarHole2">
[FAIL] Inserted using dynamic mouse event hole
</div>
""")
.With("TextHole", "[OK] Inserted using dynamic template text hole")
.With("DocHole", div [] [text "[OK] Inserted using dynamic template doc hole"])
.With("AttrHole", attr.style "display: block")
.With("AttrHole", attr.style "display: block; margin-right: 10px;")
.WithAfterRender("OarHole", fun el ->
el.TextContent <- "[OK] Inserted using dynamic afterrender hole")
.With("EventHole", fun el ev ->
Expand All @@ -138,6 +138,7 @@ let Main = Application.SinglePage(fun ctx ->
.TBody([MainTemplate.Main.Row().Doc(); MainTemplate.Main.Row().Doc()])
.With("DynamicText", """[OK] Inserted using .With("name", "text")""")
.With("DynamicDoc", text """[OK] Inserted using .With("name", doc)""")
.UnitTests(client <@ Unit.RunAllTests() @>)
.Elt(keepUnfilled = true)
.OnAfterRender(fun (_: JavaScript.Dom.Element) ->
let s = "[OK] Inserted using .OnAfterRender() on main template"
Expand Down
1 change: 1 addition & 0 deletions WebSharper.UI.Templating.ServerSide.Tests/Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<meta ws-replace="meta" />
</head>
<body ws-onafterrender="AfterRender">
<div ws-replace="UnitTests"></div>
<div ws-replace="Main">
<div ws-template="ClientTemplate" style="color:${Input};opacity:${Opacity}">
This started as ${Before}, but let's make it
Expand Down
65 changes: 65 additions & 0 deletions WebSharper.UI.Templating.ServerSide.Tests/Unit.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// $begin{copyright}
//
// This file is part of WebSharper
//
// Copyright (c) 2008-2018 IntelliFactory
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License. You may
// obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
// $end{copyright}
[<WebSharper.JavaScript>]
module WebSharper.UI.ServerSide.Unit

open WebSharper
open WebSharper.JavaScript
open WebSharper.Testing

let Dynamic = TestCategory "Dynamic templates" {

Test "was instantiated" {
let elt = JS.Document.GetElementById("dynamic-1")
equal elt.TextContent "[OK] Inserted using dynamic template"
}

Test "text hole is filled" {
let elt = JS.Document.GetElementById("dynamic-2")
equal elt.TextContent "[OK] Inserted using dynamic template text hole"
}

Test "doc hole is filled" {
let elt = JS.Document.GetElementById("dynamic-3")
equal elt.TextContent "[OK] Inserted using dynamic template doc hole"
}

Test "attr hole is filled" {
let elt = JS.Document.GetElementById("dynamic-4")
let style = JS.Window.GetComputedStyle(elt)
equal (style.GetPropertyValue("margin-right")) "10px"
}

Test "onafterrender hole is filled" {
let elt = JS.Document.GetElementById("dynamic-5")
equal elt.TextContent "[OK] Inserted using dynamic afterrender hole"
}

Test "onmouseenter hole is filled" {
let elt = JS.Document.GetElementById("dynamic-6")
equal elt.TextContent "[OK] Inserted using dynamic mouse event hole"
}

}

let RunAllTests() =
Runner.RunTests [
Dynamic
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="Unit.fs" />
<Compile Include="Main.fs" />
<Content Include="Main.html" />
<Content Include="templates.html" />
Expand Down
3 changes: 2 additions & 1 deletion WebSharper.UI.Templating.ServerSide.Tests/paket.references
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
WebSharper
WebSharper.FSharp
HtmlAgilityPack
FSharp.Core
FSharp.Core
WebSharper.Testing
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ group includes
source https://nuget.intellifactory.com/nuget username: "%IF_USER%" password: "%IF_PASS%"

nuget NETStandard.Library framework: netstandard2.0
github dotnet-websharper/websharper src/htmllib/tags.csv
github dotnet-websharper/websharper src/htmllib/tags.csv
14 changes: 7 additions & 7 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,18 @@ NUGET
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
System.Security.Cryptography.OpenSsl (4.3) - restriction: || (&& (== net461) (< net40) (>= netstandard2.0)) (&& (== net461) (>= netstandard1.6) (>= uap10.0)) (&& (== net471) (< net40)) (&& (== net471) (>= uap10.0)) (== netstandard2.0)
runtime.native.System.Security.Cryptography.OpenSsl (>= 4.3) - restriction: || (&& (== net461) (>= monoandroid)) (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Collections (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Collections (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.IO (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Resources.ResourceManager (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Runtime.Extensions (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Runtime.Handles (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.InteropServices (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Numerics (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Handles (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.InteropServices (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Runtime.Numerics (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Security.Cryptography.Algorithms (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Security.Cryptography.Encoding (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Security.Cryptography.Primitives (>= 4.3) - restriction: || (&& (== net461) (>= net463)) (&& (== net461) (>= netstandard1.6)) (== net471) (== netstandard2.0)
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Text.Encoding (>= 4.3) - restriction: || (&& (== net461) (== net471)) (&& (== net461) (>= netstandard1.6)) (&& (== net471) (< net463)) (== netstandard2.0)
System.Security.Cryptography.Primitives (4.3)
System.Diagnostics.Debug (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
System.Globalization (>= 4.3) - restriction: || (&& (== net461) (< net46)) (&& (== net471) (< net46)) (== netstandard2.0)
Expand Down Expand Up @@ -704,4 +704,4 @@ GROUP wsbuild

GIT
remote: https://github.com/dotnet-websharper/build-script
(e000569985e43f3129ad07b2f559314d080cfa9e)
(b55fa7868cffa5dd74ac8bc13b053567f7991add)

0 comments on commit 83378b7

Please sign in to comment.