Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@ namespace UI_DSM.Client.Tests.Components.Administration.ProjectManagement

using Bunit;

using CDP4Common.CommonData;
using CDP4Common.SiteDirectoryData;

using Moq;

using NUnit.Framework;

using UI_DSM.Client.Components.Administration.ProjectManagement;
using UI_DSM.Client.Services.Administration.ParticipantService;
using UI_DSM.Client.Services.Administration.RoleService;
using UI_DSM.Client.Services.ThingService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components.Administration.ProjectManagement;
using UI_DSM.Shared.Enumerator;
using UI_DSM.Shared.Models;

using Participant = UI_DSM.Shared.Models.Participant;
using TestContext = Bunit.TestContext;

[TestFixture]
Expand All @@ -39,6 +44,7 @@ internal class ModelsDetailsTestFixture
private IProjectDetailsViewModel viewModel;
private Mock<IParticipantService> participantService;
private Mock<IRoleService> roleService;
private Mock<IThingService> thingService;
private IRenderedComponent<ModelsDetails> renderer;

[SetUp]
Expand All @@ -50,19 +56,35 @@ public void Setup()
this.context.ConfigureDevExpressBlazor();
this.participantService = new Mock<IParticipantService>();
this.roleService = new Mock<IRoleService>();
this.thingService = new Mock<IThingService>();

var project = new Project(Guid.NewGuid())
{
ProjectName = "Project",
};

var model1 = new UI_DSM.Shared.Models.Model(Guid.NewGuid()) { ModelName = "Model1" };
var model2 = new UI_DSM.Shared.Models.Model(Guid.NewGuid()) { ModelName = "Model2" };
var model1 = new Model(Guid.NewGuid()) { ModelName = "Model1" };
var model2 = new Model(Guid.NewGuid()) { ModelName = "Model2" };

project.Artifacts.Add(model1);
project.Artifacts.Add(model2);

this.viewModel = new ProjectDetailsViewModel(this.participantService.Object, this.roleService.Object)
this.thingService.Setup(x => x.GetThings(It.IsAny<Guid>(), It.IsAny<IEnumerable<Guid>>(), ClassKind.DomainOfExpertise))
.ReturnsAsync(new List<Thing>
{
new DomainOfExpertise()
{
Iid = Guid.NewGuid(),
ShortName = "SYS"
},
new DomainOfExpertise()
{
Iid = Guid.NewGuid(),
ShortName = "THE"
}
});

this.viewModel = new ProjectDetailsViewModel(this.participantService.Object, this.roleService.Object, this.thingService.Object)
{
Project = project,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace UI_DSM.Client.Tests.Components.Administration.ProjectManagement
{
using Bunit;

using CDP4Common.CommonData;
using CDP4Common.SiteDirectoryData;

using DevExpress.Blazor;

using Moq;
Expand All @@ -24,12 +27,15 @@ namespace UI_DSM.Client.Tests.Components.Administration.ProjectManagement
using UI_DSM.Client.Components.Administration.ProjectManagement;
using UI_DSM.Client.Services.Administration.ParticipantService;
using UI_DSM.Client.Services.Administration.RoleService;
using UI_DSM.Client.Services.ThingService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components.Administration.ProjectManagement;
using UI_DSM.Shared.DTO.Common;
using UI_DSM.Shared.Enumerator;
using UI_DSM.Shared.Models;
using UI_DSM.Shared.Types;

using Participant = UI_DSM.Shared.Models.Participant;
using TestContext = Bunit.TestContext;

[TestFixture]
Expand All @@ -39,6 +45,7 @@ public class ProjectDetailsTestFixture
private IProjectDetailsViewModel viewModel;
private Mock<IParticipantService> participantService;
private Mock<IRoleService> roleService;
private Mock<IThingService> thingService;

[SetUp]
public void Setup()
Expand All @@ -47,8 +54,24 @@ public void Setup()
this.context.ConfigureDevExpressBlazor();
this.participantService = new Mock<IParticipantService>();
this.roleService = new Mock<IRoleService>();
this.thingService = new Mock<IThingService>();

this.thingService.Setup(x => x.GetThings(It.IsAny<Guid>(), It.IsAny<IEnumerable<Guid>>(), ClassKind.DomainOfExpertise))
.ReturnsAsync(new List<Thing>
{
new DomainOfExpertise()
{
Iid = Guid.NewGuid(),
ShortName = "SYS"
},
new DomainOfExpertise()
{
Iid = Guid.NewGuid(),
ShortName = "THE"
}
});

this.viewModel = new ProjectDetailsViewModel(this.participantService.Object, this.roleService.Object)
this.viewModel = new ProjectDetailsViewModel(this.participantService.Object, this.roleService.Object, this.thingService.Object)
{
Project = new Project(Guid.NewGuid())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ namespace UI_DSM.Client.Tests.Components.NormalUser.ReviewTask
using DevExpress.Blazor;

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;

using NUnit.Framework;

using UI_DSM.Client.Components.NormalUser.ReviewTask;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components;
using UI_DSM.Client.ViewModels.Components.NormalUser.ReviewTask;
using UI_DSM.Shared.Enumerator;
using UI_DSM.Shared.Models;

using TestContext = Bunit.TestContext;
Expand All @@ -48,7 +46,8 @@ public void Setup()
this.taskAssignmentViewModel = new TaskAssignmentViewModel()
{
SelectedParticipants = new List<Participant>(),
OnValidSubmit = new EventCallbackFactory().Create(this, () => this.taskAssignmentViewModel.SelectedParticipants = new List<Participant>())
OnValidSubmit = new EventCallbackFactory().Create(this, () =>
this.taskAssignmentViewModel.SelectedParticipants = null)
};
}

Expand All @@ -63,34 +62,58 @@ public async Task VerifyComponent()
{
try
{
var participants = new List<Participant>
{
new(Guid.NewGuid())
{
User = new UserEntity(Guid.NewGuid())
{
UserName = "user"
},
DomainsOfExpertise =
{
"SYS", "THE"
}
},
new(Guid.NewGuid())
{
User = new UserEntity(Guid.NewGuid())
{
UserName = "user2"
},
DomainsOfExpertise =
{
"SYS", "AOGNC"
}
},
new(Guid.NewGuid())
{
User = new UserEntity(Guid.NewGuid())
{
UserName = "user3"
}
}
};

var renderer = this.context.RenderComponent<TaskAssignment>(parameters =>
{
parameters.AddCascadingValue(this.errorMessageViewModel);
parameters.Add(p => p.ViewModel, this.taskAssignmentViewModel);
parameters.Add(p => p.ProjectParticipants, new List<Participant>());
parameters.Add(p => p.ProjectParticipants, participants);
});

var listBox = renderer.FindComponent<DxListBox<Participant, Participant>>();


Assert.That(listBox.Instance.Values, Is.Empty);

var participant = new Participant(Guid.NewGuid())
{
User = new UserEntity(Guid.NewGuid())
{
UserName = "user"
}
};
await renderer.InvokeAsync(() => renderer.Instance.OnValuesChanged(participants
.Where(x => x.DomainsOfExpertise.Contains("SYS")), "SYS"));

this.taskAssignmentViewModel.SelectedParticipants.ToList().Add(participant);
Assert.That(this.taskAssignmentViewModel.SelectedParticipants, Has.Count.EqualTo(2));

renderer.Render();
await renderer.InvokeAsync(() => renderer.Instance.OnValuesChanged(new List<Participant>(), "SYS"));
Assert.That(this.taskAssignmentViewModel.SelectedParticipants, Is.Empty);

var dxButton = renderer.FindComponent<EditForm>();
await renderer.InvokeAsync(dxButton.Instance.OnValidSubmit.InvokeAsync);
var dxButton = renderer.FindComponent<DxButton>();
await renderer.InvokeAsync(dxButton.Instance.Click.InvokeAsync);

Assert.That(this.taskAssignmentViewModel.SelectedParticipants.First().User, Is.Null);
Assert.That(this.taskAssignmentViewModel.SelectedParticipants, Is.Null);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace UI_DSM.Client.Tests.Pages.Administration.ProjectPages
using Bunit;
using Bunit.TestDoubles;

using CDP4Common.CommonData;
using CDP4Common.SiteDirectoryData;

using Microsoft.Extensions.DependencyInjection;

using Moq;
Expand All @@ -28,13 +31,15 @@ namespace UI_DSM.Client.Tests.Pages.Administration.ProjectPages
using UI_DSM.Client.Services.Administration.ProjectService;
using UI_DSM.Client.Services.Administration.RoleService;
using UI_DSM.Client.Services.ArtifactService;
using UI_DSM.Client.Services.ThingService;
using UI_DSM.Client.Tests.Helpers;
using UI_DSM.Client.ViewModels.Components.Administration.ModelManagement;
using UI_DSM.Client.ViewModels.Pages.Administration.ProjectPages;
using UI_DSM.Shared.Enumerator;
using UI_DSM.Shared.Models;
using UI_DSM.Shared.Types;

using Participant = UI_DSM.Shared.Models.Participant;
using TestContext = Bunit.TestContext;

[TestFixture]
Expand All @@ -47,6 +52,7 @@ public class ProjectPageTestFixture
private Mock<IRoleService> roleService;
private Mock<IArtifactService> artifactService;
private Mock<ICometUploadViewModel> cometConnexionViewModel;
private Mock<IThingService> thingService;

[SetUp]
public void Setup()
Expand All @@ -58,9 +64,10 @@ public void Setup()
this.roleService = new Mock<IRoleService>();
this.cometConnexionViewModel = new Mock<ICometUploadViewModel>();
this.artifactService = new Mock<IArtifactService>();
this.thingService = new Mock<IThingService>();

this.viewModel = new ProjectPageViewModel(this.projectService.Object, this.participantService.Object, this.roleService.Object,
this.cometConnexionViewModel.Object, this.artifactService.Object);
this.cometConnexionViewModel.Object, this.artifactService.Object, this.thingService.Object);

this.context.AddTestAuthorization();
this.context.Services.AddSingleton(this.viewModel);
Expand All @@ -78,6 +85,14 @@ public async Task VerifyRenderer()
var projectGuid = Guid.NewGuid();
this.projectService.Setup(x => x.GetProject(projectGuid, 0)).ReturnsAsync((Project)null);

this.thingService.Setup(x => x.GetThings(It.IsAny<Guid>(), It.IsAny<IEnumerable<Guid>>(), ClassKind.DomainOfExpertise))
.ReturnsAsync(new List<Thing>
{
new DomainOfExpertise(){Iid = Guid.NewGuid(), ShortName = "AOGNC"},
new DomainOfExpertise(){Iid = Guid.NewGuid(), ShortName = "THE"},
new DomainOfExpertise(){Iid = Guid.NewGuid(), ShortName = "SYS"}
});

var renderer = this.context.RenderComponent<ProjectPage>(parameters => { parameters.Add(p => p.ProjectId, projectGuid.ToString()); });

Assert.That(() => renderer.FindComponent<ProjectDetails>(), Throws.Exception);
Expand Down
2 changes: 1 addition & 1 deletion UI_DSM.Client.Tests/Shared/TopMenu/TopMenuTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task VerifyComponent()
renderer.Render();
renderer.Instance.NavigationManager.NavigateTo($"/Project/{projectId}");

Assert.That(renderer.Instance.GetRoleName(), Is.Not.Empty);
Assert.That(renderer.Instance.GetParticipant(), Is.Not.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
//
// The UI-DSM application is provided to the community under the Apache License 2.0.
-------------------------------------------------------------------------------------------------------->
<EditForm Context="editFormContext" Model="@this.ViewModel.Participant" OnValidSubmit="@this.ViewModel.OnValidSubmit">
<DataAnnotationsValidator />
<DxFormLayout>
<DxFormLayoutItem Caption="User :" ColSpanMd="12">
<DxComboBox Data="@this.ViewModel.AvailableUsers"
@bind-Value="this.ViewModel.Participant.User"
TextFieldName="@nameof(UserEntity.UserName)"/>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Role :" ColSpanMd="12">
<DxComboBox Data="@this.ViewModel.AvailableRoles"
@bind-Value="this.ViewModel.Participant.Role"
TextFieldName="@nameof(Role.RoleName)"/>
</DxFormLayoutItem>
</DxFormLayout>
<ValidationSummary/>
<ErrorMessage />
<div class="modal-footer m-top-10px">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Create" SubmitFormOnClick="true"/>
</div>
</EditForm>
<CascadingValue Name="PreventValidation" Value="true">
<EditForm Context="editFormContext" Model="@this.ViewModel.Participant" OnValidSubmit="@this.ViewModel.OnValidSubmit">
<DataAnnotationsValidator />
<DxFormLayout>
<DxFormLayoutItem Caption="User :" ColSpanMd="12">
<DxComboBox Data="@this.ViewModel.AvailableUsers"
@bind-Value="this.ViewModel.Participant.User"
TextFieldName="@nameof(UserEntity.UserName)"/>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Role :" ColSpanMd="12">
<DxComboBox Data="@this.ViewModel.AvailableRoles"
@bind-Value="this.ViewModel.Participant.Role"
TextFieldName="@nameof(Role.RoleName)"/>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Domains Of Expertise :" ColSpanMd="12">
<DxListBox Data="@this.ViewModel.AvailableDomains"
@bind-Values="this.ViewModel.SelectedDomains"
SelectionMode="ListBoxSelectionMode.Multiple" ShowCheckboxes="true" />
</DxFormLayoutItem>
</DxFormLayout>
<ValidationSummary/>
<ErrorMessage />
<div class="modal-footer m-top-10px">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Create" SubmitFormOnClick="true"/>
</div>
</EditForm>
</CascadingValue>
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@
//
// The UI-DSM application is provided to the community under the Apache License 2.0.
-------------------------------------------------------------------------------------------------------->
<CascadingValue Name="PreventValidation" Value="true">
<EditForm Context="editFormContext" Model="@this.ViewModel.Participant" OnValidSubmit="@this.ViewModel.OnValidSubmit">
<DxFormLayout>
<DxFormLayoutItem Caption="Participant Name:" ColSpanMd="12">
<label id="participantName">@this.ViewModel.Participant.User.UserName</label>
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Role :" ColSpanMd="12">
<DxComboBox Data="@this.ViewModel.AvailableRoles"
@bind-Value="this.ViewModel.Participant.Role"
TextFieldName="@nameof(this.ViewModel.Participant.Role.RoleName)" />
@bind-Value="this.ViewModel.Participant.Role"
TextFieldName="@nameof(this.ViewModel.Participant.Role.RoleName)" />
</DxFormLayoutItem>
<DxFormLayoutItem Caption="Domains Of Expertise :" ColSpanMd="12">
<DxListBox Data="@this.ViewModel.AvailableDomains"
@bind-Values="this.ViewModel.SelectedDomains"
SelectionMode="ListBoxSelectionMode.Multiple" ShowCheckboxes="true" />
</DxFormLayoutItem>
</DxFormLayout>
<div class="modal-footer m-top-10px">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Text="Update" SubmitFormOnClick="true" />
</div>
</EditForm>
</CascadingValue>
Loading