Skip to content

Commit 822779a

Browse files
committed
Started mixed-mode tests
1 parent 9727ea6 commit 822779a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+667
-180
lines changed

sample/src/Components/Alert.razor

Lines changed: 0 additions & 50 deletions
This file was deleted.

sample/src/Components/ThemeInfo.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ public class ThemeInfo
1010
{
1111
public string? Value { get; set; }
1212
}
13+
14+
// <script>
15+
// function queryWiki(query) {
16+
// return fetch('https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&search=' + query)
17+
// .then(x => x.text());
18+
// }
19+
// </script>
20+
1321
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@inject IJSRuntime jsRuntime
2+
3+
<p>@searchResult</p>
4+
5+
@code {
6+
string searchResult = string.Empty;
7+
8+
// Assumes the following function is available in the DOM
9+
// <script>
10+
// function queryWiki(query) {
11+
// return fetch('https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&search=' + query)
12+
// .then(x => x.text());
13+
// }
14+
// </script>
15+
protected override async Task OnAfterRenderAsync(bool firstRender)
16+
{
17+
if (firstRender)
18+
{
19+
searchResult = await jsRuntime.InvokeAsync<string>("queryWiki", "blazor");
20+
StateHasChanged();
21+
}
22+
}
23+
}

sample/src/Pages/Index.razor

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44

55
Welcome to your new app.
66

7-
<CascadingValue Value="theme" IsFixed="true">
8-
<ThemedButton>TEST TEST TEST</ThemedButton>
9-
</CascadingValue>
10-
11-
12-
@code {
13-
private ThemeInfo theme = new ThemeInfo { Value = "btn btn-primary" };
14-
}
7+
<WikiSearch />

sample/src/Pages/_Host.cshtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@
1818
</app>
1919

2020
<script src="_framework/blazor.server.js"></script>
21+
<script>
22+
function queryWiki(query) {
23+
return fetch('https://en.wikipedia.org/w/api.php?origin=*&action=opensearch&search=' + query)
24+
.then(x => x.text());
25+
}
26+
</script>
2127
</body>
2228
</html>

sample/tests/CodeOnlyTests/Components/ThemedXXTest.cs renamed to sample/tests/CodeOnlyTests/Components/CascadingValueTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace Egil.RazorComponents.Testing.Library.SampleApp.CodeOnlyTests.Components
1212
{
13-
public class ThemedXXTest : ComponentTestFixture
13+
public class CascadingValueTest : ComponentTestFixture
1414
{
1515
[Fact(DisplayName = "Themed button uses provided theme info to set class attribute")]
1616
public void Test001()

sample/tests/CodeOnlyTests/Components/CounterTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6-
using Egil.RazorComponents.Testing.Asserting;
76
using Egil.RazorComponents.Testing.Library.SampleApp.Pages;
87
using Shouldly;
98
using Xunit;

sample/tests/CodeOnlyTests/Components/FetchDataTest.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text;
5-
using System.Threading.Tasks;
65
using Egil.RazorComponents.Testing.Library.SampleApp.Data;
76
using Egil.RazorComponents.Testing.Library.SampleApp.Components;
87
using Xunit;
98
using Egil.RazorComponents.Testing.Library.SampleApp.Pages;
109
using Shouldly;
11-
using Egil.RazorComponents.Testing.Asserting;
1210

1311
namespace Egil.RazorComponents.Testing.Library.SampleApp.CodeOnlyTests
1412
{
1513
public class FetchDataTest : ComponentTestFixture
1614
{
17-
class MockForecastService : IWeatherForecastService
18-
{
19-
public TaskCompletionSource<WeatherForecast[]> Task { get; } = new TaskCompletionSource<WeatherForecast[]>();
20-
21-
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) => Task.Task;
22-
}
23-
2415
[Fact]
2516
public void InitialLoadingHtmlRendersCorrectly()
2617
{

sample/tests/CodeOnlyTests/Components/PassingChildContentTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Text;
55
using System.Threading.Tasks;
66
using Egil.RazorComponents.Testing.Library.SampleApp.Components;
7-
using Egil.RazorComponents.Testing.Asserting;
87
using Shouldly;
98
using Xunit;
109

sample/tests/CodeOnlyTests/Components/TodoItemTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Egil.RazorComponents.Testing.Asserting;
2-
using Egil.RazorComponents.Testing.Library.SampleApp.Components;
1+
using Egil.RazorComponents.Testing.Library.SampleApp.Components;
32
using Egil.RazorComponents.Testing.Library.SampleApp.Data;
43
using Microsoft.AspNetCore.Components;
54
using Shouldly;
@@ -21,12 +20,14 @@ public void Test001()
2120
Should.Throw<InvalidOperationException>(() => RenderComponent<TodoItem>((nameof(TodoItem.Todo), null)));
2221
}
2322

24-
[Fact(DisplayName = "The control renders the expected output")]
23+
[Fact(DisplayName = "The component renders the expected output")]
2524
public void Test002()
2625
{
2726
var todo = new Todo { Id = 42, Text = "Hello world" };
2827
var cut = RenderComponent<TodoItem>((nameof(TodoItem.Todo), todo));
2928

29+
cut.ShouldBe(cut);
30+
3031
cut.ShouldBe($@"<li id=""todo-{todo.Id}"" class=""list-group-item list-group-item-action"">
3132
<span>{todo.Text}</span>
3233
<span class=""float-right text-danger"">(click to complete)</span>

0 commit comments

Comments
 (0)