예제 #1
0
파일: testjs.cs 프로젝트: JeroenBos/BlaTeX
        public async Task JSInteropTestViaBlazor()
        {
            var    imports  = $"{Program.RootFolder}/wwwroot/js/blatex_wrapper.js".ToSingleton();
            var    result   = await new NodeJSRuntime(imports).InvokeAsync <string>("blatex_wrapper.default.renderToString", "c").AsTask();
            string expected = @"
<span class=""katex"">
    <span class=""katex-mathml"">
      <math xmlns=""http://www.w3.org/1998/Math/MathML"">
        <semantics>
          <mrow>
            <mi>c</mi>
          </mrow>
          <annotation encoding=""application/x-tex"">c</annotation>
        </semantics>
      </math>
    </span>
    <span class=""katex-html"" aria-hidden=""true"">
      <span class=""base"">
        <span class=""strut"" style=""height:0.43056em;vertical-align:0em;""></span>
        <span class=""mord mathnormal"" data-loc=""0,1"">c</span>
      </span>
    </span>
</span>
";

            HtmlEqualityComparer.AssertEqual(result, expected);
        }
예제 #2
0
        protected override async Task Run()
        {
            Validate();

            string blatexJSPath = Program.RootFolder + "/wwwroot/js/blatex_wrapper.js";

            if (!File.Exists(blatexJSPath))
            {
                throw new FileNotFoundException("blatex.js not found. You probably need to build it, see readme. ");
            }

            Services.AddDefaultTestContextServices();
            Services.Add(new ServiceDescriptor(typeof(IJSRuntime), new NodeJSRuntime(new[] { blatexJSPath })));
            Services.Add(new ServiceDescriptor(typeof(IKaTeX), typeof(_KaTeX), ServiceLifetime.Singleton));

            int   id;
            KaTeX cut;
            var   parameters = new ComponentParameter[]
            {
                (nameof(KaTeX.Math), this.Math),
                (nameof(KaTeX.ChildComponentMarkupService), this.ChildComponentMarkupService),
            };

            if (this.Interactive ?? false)
            {
                (id, cut) = this.Renderer.RenderComponent <InteractiveKaTeX>(parameters);
            }
            else
            {
                (id, cut) = this.Renderer.RenderComponent <KaTeX>(parameters);
            }

            if (cut is null)
            {
                throw new InvalidOperationException("The KaTeX component did not render successfully");
            }

            var renderedCut = await WaitForKatexToHaveRendered(cut, id);

            if (this.Action.HasDelegate)
            {
                await this.Action.InvokeAsync(renderedCut);
                await WaitForKatexToHaveRendered(cut, id);
            }

            var katexHtml        = Htmlizer.GetHtml(Renderer, id);
            var expectedRenderId = Renderer.RenderFragment(this.Expected);
            var expectedHtml     = Htmlizer.GetHtml(Renderer, expectedRenderId);

            HtmlEqualityComparer.AssertEqual(expectedHtml, katexHtml);
        }