Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeM-2ISA authored and hocinehacherouf committed Apr 7, 2023
1 parent 30426d6 commit 5525151
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
<MudExpansionPanel Text="Properties">
<TitleContent><MudText Typo="Typo.h6">Properties</MudText></TitleContent>
<ChildContent>
<MudGrid>
<MudGrid id="device-properties">
@foreach (var item in Properties.OrderBy(c => c.Order))
{
switch (item.PropertyType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,62 +629,102 @@ public void DisplayValidationErrorMessageRenderCorrectly()
cut.WaitForAssertion(() => cut.Find("p.validation-error-message").TextContent.Should().Be("The Model is required."));
}

//[Test]
//public async Task DisplayPropertiesRenderCorrectly()
//{
// // Arrange
// var mockDeviceModel = new DeviceModelDto
// {
// ModelId = Guid.NewGuid().ToString(),
// Description = Guid.NewGuid().ToString(),
// SupportLoRaFeatures = false,
// Name = Guid.NewGuid().ToString()
// };
[Test]
public async Task DisplayPropertiesRenderCorrectly()
{
// Arrange
var mockDeviceModel = new DeviceModelDto
{
ModelId = Guid.NewGuid().ToString(),
Description = Guid.NewGuid().ToString(),
SupportLoRaFeatures = false,
Name = Guid.NewGuid().ToString()
};

// var expectedDeviceDetails = new DeviceDetails
// {
// DeviceName = Guid.NewGuid().ToString(),
// ModelId = mockDeviceModel.ModelId,
// DeviceID = Guid.NewGuid().ToString(),
// };
var expectedDeviceDetails = new DeviceDetails
{
DeviceName = Guid.NewGuid().ToString(),
ModelId = mockDeviceModel.ModelId,
DeviceID = Guid.NewGuid().ToString(),
};

// _ = this.mockDeviceClientService.Setup(service => service.CreateDevice(It.Is<DeviceDetails>(details => expectedDeviceDetails.DeviceID.Equals(details.DeviceID, StringComparison.Ordinal))))
// .Returns(Task.CompletedTask);
_ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
.ReturnsAsync(new List<DeviceTagDto>
{
new()
{
Label = Guid.NewGuid().ToString(),
Name = Guid.NewGuid().ToString(),
Required = false,
Searchable = false
}
});

// _ = this.mockDeviceTagSettingsClientService.Setup(service => service.GetDeviceTags())
// .ReturnsAsync(new List<DeviceTagDto>
// {
// new()
// {
// Label = Guid.NewGuid().ToString(),
// Name = Guid.NewGuid().ToString(),
// Required = false,
// Searchable = false
// }
// });

// _ = this.mockDeviceModelsClientService
// .Setup(service => service.GetDeviceModelModelProperties(mockDeviceModel.ModelId))
// .ReturnsAsync(new List<DeviceProperty>());

// _ = this.mockDeviceClientService
// .Setup(service => service.SetDeviceProperties(expectedDeviceDetails.DeviceID, It.IsAny<IList<DevicePropertyValue>>()))
// .Returns(Task.CompletedTask);

// var cut = RenderComponent<EditDevice>();
// var saveButton = cut.WaitForElement("#SaveButton");
_ = this.mockDeviceModelsClientService
.Setup(service => service.GetDeviceModelModelProperties(mockDeviceModel.ModelId))
.ReturnsAsync(new List<DeviceProperty>
{
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.Boolean,
IsWritable = true
},
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.Float,
IsWritable = true
},
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.Double,
IsWritable = true
},
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.Integer,
IsWritable = true
},
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.Long,
IsWritable = true
},
new()
{
Name = Guid.NewGuid().ToString(),
DisplayName = Guid.NewGuid().ToString(),
Order = 1,
PropertyType = Models.DevicePropertyType.String,
IsWritable = true
}
});

// // Act
// cut.WaitForElement($"#{nameof(DeviceDetails.DeviceName)}").Change(expectedDeviceDetails.DeviceName);
// cut.WaitForElement($"#{nameof(DeviceDetails.DeviceID)}").Change(expectedDeviceDetails.DeviceID);
// await cut.Instance.ChangeModel(mockDeviceModel);
var cut = RenderComponent<EditDevice>();

// saveButton.Click();
// Act
cut.WaitForElement($"#{nameof(DeviceDetails.DeviceName)}").Change(expectedDeviceDetails.DeviceName);
cut.WaitForElement($"#{nameof(DeviceDetails.DeviceID)}").Change(expectedDeviceDetails.DeviceID);
await cut.Instance.ChangeModel(mockDeviceModel);

// // Assert
// cut.WaitForAssertion(() => MockRepository.VerifyAll());
// cut.WaitForAssertion(() => this.mockNavigationManager.Uri.Should().EndWith("/devices"));
//}
// Assert
cut.WaitForAssertion(() => cut.FindAll("#device-properties > .mud-grid-item").Count.Should().Be(6));
cut.WaitForAssertion(() => MockRepository.VerifyAll());
}

//[Test]
//public async Task DisplayCreateLoraDeviceComponentRenderCorrectly()
Expand All @@ -709,6 +749,7 @@ public void DisplayValidationErrorMessageRenderCorrectly()

// // Act
// await cut.Instance.ChangeModel(mockDeviceModel);
// _ = cut.WaitForElement("#tab-lorawan");

// // Assert
// cut.WaitForAssertion(() => cut.Find("#tab-lorawan").TextContent.Should().Be("LoRaWAN"));
Expand Down

0 comments on commit 5525151

Please sign in to comment.