Skip to content

Commit

Permalink
Add unit tests on lorawan device pages (#1145)
Browse files Browse the repository at this point in the history
* Create Page LoraDevice Tests

* Create edit lora device tests

* Fix Formatting

* Test LoRaWAN commands in device detail page

* News tests

* Edit ClassType and Deduplication

* edit reported properties

Co-authored-by: crib <christophe.ribeiro@cgi.com>
Co-authored-by: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 6, 2022
1 parent 1edb2cf commit 4f566cc
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) CGI France. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace AzureIoTHub.Portal.Tests.Unit.Client.Pages.Devices
{
using System;
using AzureIoTHub.Portal.Client.Pages.Devices.LoRaWAN;
using AzureIoTHub.Portal.Client.Validators;
using AzureIoTHub.Portal.Models.v10.LoRaWAN;
using Bunit;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor.Services;
using NUnit.Framework;
using UnitTests.Bases;
using UnitTests.Mocks;

[TestFixture]
public class CreateLoraDeviceTests : BlazorUnitTest
{

public override void Setup()
{
base.Setup();

Services.Add(new ServiceDescriptor(typeof(IResizeObserver), new MockResizeObserver()));
}

[Test]
public void WhenUseOTAAShouldDisplayOTAATextboxes()
{
var mockLoRaModel = new LoRaDeviceModel
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = true
};

var deviceDetails = new LoRaDeviceDetails()
{
DeviceID = Guid.NewGuid().ToString(),
ModelId = mockLoRaModel.ModelId,
AppEUI = Guid.NewGuid().ToString(),
AppKey = Guid.NewGuid().ToString()
};

var validator = new LoRaDeviceDetailsValidator();

// Act

var cut = RenderComponent<CreateLoraDevice>(
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.LoRaDevice), deviceDetails),
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.loraModel), mockLoRaModel),
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.LoraValidator), validator));


// Assert
cut.WaitForAssertion(() => Assert.AreEqual(deviceDetails.AppEUI, cut.WaitForElement($"#{nameof(LoRaDeviceDetails.AppEUI)}").GetAttribute("value")));
cut.WaitForAssertion(() => Assert.AreEqual(deviceDetails.AppKey, cut.WaitForElement($"#{nameof(LoRaDeviceDetails.AppKey)}").GetAttribute("value")));
}

[Test]
public void WhenNotUseOTAAShouldDisplayABPTextboxes()
{
var mockLoRaModel = new LoRaDeviceModel
{
ModelId = Guid.NewGuid().ToString(),
UseOTAA = false
};

var deviceDetails= new LoRaDeviceDetails()
{
DeviceID = Guid.NewGuid().ToString(),
ModelId = mockLoRaModel.ModelId,
AppSKey = Guid.NewGuid().ToString(),
NwkSKey = Guid.NewGuid().ToString(),
DevAddr = Guid.NewGuid().ToString(),
};
var validator = new LoRaDeviceDetailsValidator();

// Act
var cut = RenderComponent<CreateLoraDevice>(
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.LoRaDevice), deviceDetails),
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.loraModel), mockLoRaModel),
ComponentParameter.CreateParameter(nameof(CreateLoraDevice.LoraValidator), validator));


// Assert

cut.WaitForAssertion(() => Assert.AreEqual(deviceDetails.AppSKey, cut.WaitForElement($"#{nameof(LoRaDeviceDetails.AppSKey)}").GetAttribute("value")));
cut.WaitForAssertion(() => Assert.AreEqual(deviceDetails.NwkSKey, cut.WaitForElement($"#{nameof(LoRaDeviceDetails.NwkSKey)}").GetAttribute("value")));
cut.WaitForAssertion(() => Assert.AreEqual(deviceDetails.DevAddr, cut.WaitForElement($"#{nameof(LoRaDeviceDetails.DevAddr)}").GetAttribute("value")));
}
}
}
Loading

0 comments on commit 4f566cc

Please sign in to comment.