|
1 | 1 | namespace AngleSharp.Scripting.JavaScript.Tests
|
2 | 2 | {
|
| 3 | + using AngleSharp.Extensions; |
| 4 | + using AngleSharp.Scripting.JavaScript.Tests.Mocks; |
3 | 5 | using NUnit.Framework;
|
4 | 6 | using System;
|
5 | 7 | using System.Collections.Generic;
|
@@ -37,5 +39,50 @@ public async Task JqueryWithSimpleSelector()
|
37 | 39 | var result = await EvaluateScriptWithJqueryAsync(SetResult("$('#result').length.toString()"));
|
38 | 40 | Assert.AreEqual("1", result);
|
39 | 41 | }
|
| 42 | + |
| 43 | + [Test] |
| 44 | + public async Task JqueryWithSettingAttribute() |
| 45 | + { |
| 46 | + var result = await EvaluateScriptWithJqueryAsync("$('#result').attr('foo', 'bar')", SetResult("$('#result').attr('foo')")); |
| 47 | + Assert.AreEqual("bar", result); |
| 48 | + } |
| 49 | + |
| 50 | + [Test] |
| 51 | + public async Task JqueryWithSettingTextProperty() |
| 52 | + { |
| 53 | + var result = await EvaluateScriptWithJqueryAsync("$('#result').text('<span>foo></span>');"); |
| 54 | + Assert.AreEqual("<span>foo&gt;</span>", result); |
| 55 | + } |
| 56 | + |
| 57 | + [Test] |
| 58 | + public async Task JqueryWithSettingHtmlProperty() |
| 59 | + { |
| 60 | + var result = await EvaluateScriptWithJqueryAsync("$('#result').html('<span>foo></span>')"); |
| 61 | + Assert.AreEqual("<span>foo></span>", result); |
| 62 | + } |
| 63 | + |
| 64 | + [Test] |
| 65 | + public async Task JqueryWithAjaxToDelayedResponse() |
| 66 | + { |
| 67 | + var message = "Hi!"; |
| 68 | + var req = new DelayedRequester(10, message); |
| 69 | + var cfg = Configuration.Default.WithJavaScript().WithDefaultLoader(requesters: new[] { req }); |
| 70 | + var sources = new [] { Sources.Jquery, @" |
| 71 | +$.ajax('http://example.com/', { |
| 72 | + success: function (data, status, xhr) { |
| 73 | + var res = document.querySelector('#result'); |
| 74 | + res.textContent = xhr.responseText; |
| 75 | + res.dispatchEvent(new CustomEvent('xhrdone')); |
| 76 | + } |
| 77 | +});" }; |
| 78 | + var scripts = String.Join("</script><script>", sources); |
| 79 | + var html = "<!doctype html><div id=result></div><script>" + scripts + "</script>"; |
| 80 | + var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html)); |
| 81 | + var result = document.QuerySelector("#result"); |
| 82 | + Assert.AreEqual("", result.TextContent); |
| 83 | + Assert.IsTrue(req.IsStarted); |
| 84 | + await result.AwaitEvent("xhrdone").ConfigureAwait(false); |
| 85 | + Assert.AreEqual(message, result.TextContent); |
| 86 | + } |
40 | 87 | }
|
41 | 88 | }
|
0 commit comments