<commit_before>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Duracellko.PlanningPoker.Client.Components;
using Duracellko.PlanningPoker.Client.Controllers;
using Duracellko.PlanningPoker.Client.Service;
using Duracellko.PlanningPoker.Client.Test.Controllers;
using Duracellko.PlanningPoker.Client.UI;
using Duracellko.PlanningPoker.Service;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Duracellko.PlanningPoker.Client.Test.Components
{
    [TestClass]
    public class PlanningPokerDeskTest
    {
        private static readonly string _newLine = Environment.NewLine;

        [TestMethod]
        public async Task InitializedTeamWithScrumMaster_ShowStartEstimationButton()
        {
            var serviceProvider = CreateServiceProvider();
            var renderer = serviceProvider.GetRequiredService<TestRenderer>();
            var controller = serviceProvider.GetRequiredService<PlanningPokerController>();

            await controller.InitializeTeam(PlanningPokerData.GetTeamResult(), PlanningPokerData.ScrumMasterName);
            var target = renderer.InstantiateComponent<PlanningPokerDesk>();

            var componentId = renderer.AssignRootComponentId(target);
            await renderer.RenderRootComponentAsync(componentId);

            Assert.AreEqual(1, renderer.Batches.Count);
            var frames = renderer.Batches[0].ReferenceFrames;
            Assert.IsNotNull(frames);
            Assert.AreEqual(425, frames.Count);

            // Team name and user name
            AssertFrame.Element(frames[0], "div", 425);
            AssertFrame.Attribute(frames[1], "class", "pokerDeskPanel");
            AssertFrame.Element(frames[400], "div", 11);
            AssertFrame.Attribute(frames[401], "class", "team-title");
            AssertFrame.Element(frames[402], "h2", 4);
            AssertFrame.Markup(frames[403], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-people\" title=\"Team\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[404], "span", 2);
            AssertFrame.Text(frames[405], PlanningPokerData.TeamName);
            AssertFrame.Element(frames[407], "h3", 4);
            AssertFrame.Markup(frames[408], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-person\" title=\"User\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[409], "span", 2);
            AssertFrame.Text(frames[410], PlanningPokerData.ScrumMasterName);

            // Button to start estimation
            AssertFrame.Element(frames[411], "div", 14);
            AssertFrame.Attribute(frames[412], "class", "actionsBar");
            AssertFrame.Element(frames[413], "p", 12);
            AssertFrame.Element(frames[414], "button", 5);
            AssertFrame.Attribute(frames[415], "type", "button");
            AssertFrame.Attribute(frames[416], "onclick");
            AssertFrame.Attribute(frames[417], "class", "btn btn-primary mr-3");
            AssertFrame.Markup(frames[418], $"<span class=\"oi oi-media-play mr-1\" aria-hidden=\"true\"></span> Start estimation{_newLine}                    ");
        }

        [TestMethod]
        public async Task PlanningPokerStartedWithMember_ShowsAvailableEstimations()
        {
            var serviceProvider = CreateServiceProvider();
            var renderer = serviceProvider.GetRequiredService<TestRenderer>();
            var controller = serviceProvider.GetRequiredService<PlanningPokerController>();

            var reconnectResult = PlanningPokerData.GetReconnectTeamResult();
            reconnectResult.ScrumTeam!.State = TeamState.EstimationInProgress;
            reconnectResult.ScrumTeam.EstimationParticipants = new List<EstimationParticipantStatus>
            {
                new EstimationParticipantStatus() { MemberName = PlanningPokerData.ScrumMasterName, Estimated = true },
                new EstimationParticipantStatus() { MemberName = PlanningPokerData.MemberName, Estimated = false }
            };
            await controller.InitializeTeam(reconnectResult, PlanningPokerData.MemberName);
            var target = renderer.InstantiateComponent<PlanningPokerDesk>();

            var componentId = renderer.AssignRootComponentId(target);
            await renderer.RenderRootComponentAsync(componentId);

            Assert.AreEqual(1, renderer.Batches.Count);
            var frames = renderer.Batches[0].ReferenceFrames;
            Assert.IsNotNull(frames);
            Assert.AreEqual(488, frames.Count);

            // Team name and user name
            AssertFrame.Element(frames[0], "div", 488);
            AssertFrame.Attribute(frames[1], "class", "pokerDeskPanel");
            AssertFrame.Element(frames[400], "div", 11);
            AssertFrame.Attribute(frames[401], "class", "team-title");
            AssertFrame.Element(frames[402], "h2", 4);
            AssertFrame.Markup(frames[403], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-people\" title=\"Team\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[404], "span", 2);
            AssertFrame.Text(frames[405], PlanningPokerData.TeamName);
            AssertFrame.Element(frames[407], "h3", 4);
            AssertFrame.Markup(frames[408], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-person\" title=\"User\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[409], "span", 2);
            AssertFrame.Text(frames[410], PlanningPokerData.MemberName);

            // Available estimations
            AssertFrame.Element(frames[411], "div", 56);
            AssertFrame.Attribute(frames[412], "class", "availableEstimations");
            AssertFrame.Markup(frames[413], $"<h3>Pick estimation</h3>{_newLine}            ");
            AssertFrame.Element(frames[414], "ul", 53);
            AssertAvailableEstimation(frames, 415, "0");
            AssertAvailableEstimation(frames, 419, "½");
            AssertAvailableEstimation(frames, 423, "1");
            AssertAvailableEstimation(frames, 427, "2");
            AssertAvailableEstimation(frames, 431, "3");
            AssertAvailableEstimation(frames, 435, "5");
            AssertAvailableEstimation(frames, 439, "8");
            AssertAvailableEstimation(frames, 443, "13");
            AssertAvailableEstimation(frames, 447, "20");
            AssertAvailableEstimation(frames, 451, "40");
            AssertAvailableEstimation(frames, 455, "100");
            AssertAvailableEstimation(frames, 459, "∞");
            AssertAvailableEstimation(frames, 463, "?");

            // Members, who estimated already
            AssertFrame.Element(frames[476], "div", 12);
            AssertFrame.Attribute(frames[477], "class", "estimationResult");
            AssertFrame.Markup(frames[478], $"<h3>Selected estimates</h3>");
            AssertFrame.Element(frames[479], "ul", 9);
            AssertSelectedEstimation(frames, 480, PlanningPokerData.ScrumMasterName, string.Empty);
        }
<commit_msg>Fix component tests<commit_after>﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Duracellko.PlanningPoker.Client.Components;
using Duracellko.PlanningPoker.Client.Controllers;
using Duracellko.PlanningPoker.Client.Service;
using Duracellko.PlanningPoker.Client.Test.Controllers;
using Duracellko.PlanningPoker.Client.UI;
using Duracellko.PlanningPoker.Service;
using Microsoft.AspNetCore.Components.RenderTree;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Duracellko.PlanningPoker.Client.Test.Components
{
    [TestClass]
    public class PlanningPokerDeskTest
    {
        private static readonly string _newLine = Environment.NewLine;

        [TestMethod]
        public async Task InitializedTeamWithScrumMaster_ShowStartEstimationButton()
        {
            var serviceProvider = CreateServiceProvider();
            var renderer = serviceProvider.GetRequiredService<TestRenderer>();
            var controller = serviceProvider.GetRequiredService<PlanningPokerController>();

            await controller.InitializeTeam(PlanningPokerData.GetTeamResult(), PlanningPokerData.ScrumMasterName);
            var target = renderer.InstantiateComponent<PlanningPokerDesk>();

            var componentId = renderer.AssignRootComponentId(target);
            await renderer.RenderRootComponentAsync(componentId);

            Assert.AreEqual(1, renderer.Batches.Count);
            var frames = renderer.Batches[0].ReferenceFrames;
            Assert.IsNotNull(frames);
            Assert.AreEqual(426, frames.Count);

            // Team name and user name
            AssertFrame.Element(frames[0], "div", 426);
            AssertFrame.Attribute(frames[1], "class", "pokerDeskPanel");
            AssertFrame.Element(frames[400], "div", 11);
            AssertFrame.Attribute(frames[401], "class", "team-title");
            AssertFrame.Element(frames[402], "h2", 4);
            AssertFrame.Markup(frames[403], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-people\" title=\"Team\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[404], "span", 2);
            AssertFrame.Text(frames[405], PlanningPokerData.TeamName);
            AssertFrame.Element(frames[407], "h3", 4);
            AssertFrame.Markup(frames[408], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-person\" title=\"User\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[409], "span", 2);
            AssertFrame.Text(frames[410], PlanningPokerData.ScrumMasterName);

            // Button to start estimation
            AssertFrame.Element(frames[411], "div", 15);
            AssertFrame.Attribute(frames[412], "class", "actionsBar");
            AssertFrame.Element(frames[413], "p", 13);
            AssertFrame.Element(frames[414], "button", 5);
            AssertFrame.Attribute(frames[415], "type", "button");
            AssertFrame.Attribute(frames[416], "onclick");
            AssertFrame.Attribute(frames[417], "class", "btn btn-primary mr-3");
            AssertFrame.Markup(frames[418], $"<span class=\"oi oi-media-play mr-1\" aria-hidden=\"true\"></span> Start estimation{_newLine}                    ");
        }

        [TestMethod]
        public async Task PlanningPokerStartedWithMember_ShowsAvailableEstimations()
        {
            var serviceProvider = CreateServiceProvider();
            var renderer = serviceProvider.GetRequiredService<TestRenderer>();
            var controller = serviceProvider.GetRequiredService<PlanningPokerController>();

            var reconnectResult = PlanningPokerData.GetReconnectTeamResult();
            reconnectResult.ScrumTeam!.State = TeamState.EstimationInProgress;
            reconnectResult.ScrumTeam.EstimationParticipants = new List<EstimationParticipantStatus>
            {
                new EstimationParticipantStatus() { MemberName = PlanningPokerData.ScrumMasterName, Estimated = true },
                new EstimationParticipantStatus() { MemberName = PlanningPokerData.MemberName, Estimated = false }
            };
            await controller.InitializeTeam(reconnectResult, PlanningPokerData.MemberName);
            var target = renderer.InstantiateComponent<PlanningPokerDesk>();

            var componentId = renderer.AssignRootComponentId(target);
            await renderer.RenderRootComponentAsync(componentId);

            Assert.AreEqual(1, renderer.Batches.Count);
            var frames = renderer.Batches[0].ReferenceFrames;
            Assert.IsNotNull(frames);
            Assert.AreEqual(489, frames.Count);

            // Team name and user name
            AssertFrame.Element(frames[0], "div", 489);
            AssertFrame.Attribute(frames[1], "class", "pokerDeskPanel");
            AssertFrame.Element(frames[400], "div", 11);
            AssertFrame.Attribute(frames[401], "class", "team-title");
            AssertFrame.Element(frames[402], "h2", 4);
            AssertFrame.Markup(frames[403], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-people\" title=\"Team\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[404], "span", 2);
            AssertFrame.Text(frames[405], PlanningPokerData.TeamName);
            AssertFrame.Element(frames[407], "h3", 4);
            AssertFrame.Markup(frames[408], $"<span class=\"badge badge-secondary\"><span class=\"oi oi-person\" title=\"User\" aria-hidden=\"true\"></span></span>{_newLine}            ");
            AssertFrame.Element(frames[409], "span", 2);
            AssertFrame.Text(frames[410], PlanningPokerData.MemberName);

            // Available estimations
            AssertFrame.Element(frames[411], "div", 56);
            AssertFrame.Attribute(frames[412], "class", "availableEstimations");
            AssertFrame.Markup(frames[413], $"<h3>Pick estimation</h3>{_newLine}            ");
            AssertFrame.Element(frames[414], "ul", 53);
            AssertAvailableEstimation(frames, 415, "0");
            AssertAvailableEstimation(frames, 419, "½");
            AssertAvailableEstimation(frames, 423, "1");
            AssertAvailableEstimation(frames, 427, "2");
            AssertAvailableEstimation(frames, 431, "3");
            AssertAvailableEstimation(frames, 435, "5");
            AssertAvailableEstimation(frames, 439, "8");
            AssertAvailableEstimation(frames, 443, "13");
            AssertAvailableEstimation(frames, 447, "20");
            AssertAvailableEstimation(frames, 451, "40");
            AssertAvailableEstimation(frames, 455, "100");
            AssertAvailableEstimation(frames, 459, "∞");
            AssertAvailableEstimation(frames, 463, "?");

            // Members, who estimated already
            AssertFrame.Element(frames[477], "div", 12);
            AssertFrame.Attribute(frames[478], "class", "estimationResult");
            AssertFrame.Markup(frames[479], $"<h3>Selected estimates</h3>");
            AssertFrame.Element(frames[480], "ul", 9);
            AssertSelectedEstimation(frames, 481, PlanningPokerData.ScrumMasterName, string.Empty);
        }

{'fraction_non_alphanumeric': 0.12844162995594713, 'fraction_numerical': 0.030148678414096915, 'mean_word_length': 3.021311929144755, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2564422', 'n_tokens_mistral': 4167, 'n_tokens_neox': 3814, 'n_words': 658}