Skip to content

Commit 8ec56dc

Browse files
sensslenSimon Ensslen
andauthored
Add class parameter to allow styling independently from ID (#75)
* Add class support to azure maps in order to allow styling and avoid the necessity to use the ID for that since the ID should be unique * Add solution to facilitate tooling * add rider files to gitignore * Update Tests so that a new context is used for each test * remove solution file as requested by review Co-authored-by: Simon Ensslen <simon.ensslen@griesser.ch>
1 parent c252e58 commit 8ec56dc

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,4 +352,5 @@ healthchecksdb
352352
MigrationBackup/
353353

354354
# Ionide (cross platform F# VS Code tools) working folder
355-
.ionide/
355+
.ionide/
356+
.idea

src/AzureMapsControl.Components/Map/AzureMap.razor

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@inject IMapJsRuntime JSRuntime
1414
@inject Microsoft.Extensions.Logging.ILogger<AzureMap> Logger
1515

16-
<div id="@Id"></div>
16+
<div id="@Id" class="@Class"></div>
1717

1818
@code {
1919

@@ -61,6 +61,12 @@
6161
set { if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentException("ID on the map is mandatory"); } _id = value; }
6262
}
6363

64+
/// <summary>
65+
/// The class of the map component to allow styling
66+
/// </summary>
67+
[Parameter]
68+
public string Class { get; set; } = string.Empty;
69+
6470
/// <summary>
6571
/// Defines the events which needs to be activated
6672
/// </summary>

tests/AzureMapsControl.Components.Tests/Map/AzureMap.cs

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,42 +57,76 @@ public void RegisterServices()
5757

5858
public class AzureMapTests : IClassFixture<AzureMapFixture>
5959
{
60-
private readonly AzureMapFixture _fixture;
61-
public AzureMapTests(AzureMapFixture fixture) => _fixture = fixture;
62-
6360
[Fact]
6461
public void Should_DisplayDivWithId()
6562
{
66-
using (_fixture)
63+
using (var fixture = new AzureMapFixture())
6764
{
6865
const string mapId = "mapID";
6966

70-
_fixture.Configuration.AadAppId = "aadAppId";
67+
fixture.Configuration.AadAppId = "aadAppId";
7168

72-
_fixture.Configuration.AadTenant = "aadTenant";
73-
_fixture.Configuration.ClientId = "clientId";
74-
_fixture.Configuration.SubscriptionKey = "subscriptionKey";
69+
fixture.Configuration.AadTenant = "aadTenant";
70+
fixture.Configuration.ClientId = "clientId";
71+
fixture.Configuration.SubscriptionKey = "subscriptionKey";
7572

76-
_fixture.RegisterServices();
73+
fixture.RegisterServices();
7774

78-
var map = _fixture.TestContext.RenderComponent<AzureMap>(ComponentParameter.CreateParameter("Id", mapId));
75+
var map = fixture.TestContext.RenderComponent<AzureMap>(ComponentParameter.CreateParameter("Id", mapId));
7976

8077
var mapElem = map.Find("div");
8178

8279
Assert.Equal(mapId, mapElem.Attributes["id"].Value);
8380

84-
_fixture.JsRuntime.Verify(runtime => runtime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.AddMap.ToCoreNamespace(), It.Is<object[]>(parameters =>
81+
fixture.JsRuntime.Verify(runtime => runtime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.AddMap.ToCoreNamespace(), It.Is<object[]>(parameters =>
82+
parameters.Length == 5
83+
&& parameters[0] as string == mapId
84+
&& (parameters[1] as AzureMapsConfiguration).AadAppId == fixture.Configuration.AadAppId
85+
&& (parameters[1] as AzureMapsConfiguration).AadTenant == fixture.Configuration.AadTenant
86+
&& (parameters[1] as AzureMapsConfiguration).ClientId == fixture.Configuration.ClientId
87+
&& (parameters[1] as AzureMapsConfiguration).SubscriptionKey == fixture.Configuration.SubscriptionKey
88+
&& parameters[2] != null && parameters[2] is ServiceOptions
89+
&& (parameters[3] as IEnumerable<string>).Single() == MapEventType.Ready.ToString()
90+
&& parameters[4] != null && parameters[4] is DotNetObjectReference<MapEventInvokeHelper>
91+
)), Times.Once);
92+
fixture.JsRuntime.VerifyNoOtherCalls();
93+
}
94+
}
95+
96+
[Fact]
97+
public void Should_DisplayDivWithClass()
98+
{
99+
using (var fixture = new AzureMapFixture())
100+
{
101+
const string classes = "my-class-identifier other-class-identifier";
102+
const string mapId = "mapID";
103+
104+
fixture.Configuration.AadAppId = "aadAppId";
105+
106+
fixture.Configuration.AadTenant = "aadTenant";
107+
fixture.Configuration.ClientId = "clientId";
108+
fixture.Configuration.SubscriptionKey = "subscriptionKey";
109+
110+
fixture.RegisterServices();
111+
112+
var map = fixture.TestContext.RenderComponent<AzureMap>(ComponentParameter.CreateParameter("Id", mapId), ComponentParameter.CreateParameter("Class", classes));
113+
114+
var mapElem = map.Find("div");
115+
116+
Assert.Equal(classes, mapElem.Attributes["class"].Value);
117+
118+
fixture.JsRuntime.Verify(runtime => runtime.InvokeVoidAsync(Constants.JsConstants.Methods.Core.AddMap.ToCoreNamespace(), It.Is<object[]>(parameters =>
85119
parameters.Length == 5
86120
&& parameters[0] as string == mapId
87-
&& (parameters[1] as AzureMapsConfiguration).AadAppId == _fixture.Configuration.AadAppId
88-
&& (parameters[1] as AzureMapsConfiguration).AadTenant == _fixture.Configuration.AadTenant
89-
&& (parameters[1] as AzureMapsConfiguration).ClientId == _fixture.Configuration.ClientId
90-
&& (parameters[1] as AzureMapsConfiguration).SubscriptionKey == _fixture.Configuration.SubscriptionKey
121+
&& (parameters[1] as AzureMapsConfiguration).AadAppId == fixture.Configuration.AadAppId
122+
&& (parameters[1] as AzureMapsConfiguration).AadTenant == fixture.Configuration.AadTenant
123+
&& (parameters[1] as AzureMapsConfiguration).ClientId == fixture.Configuration.ClientId
124+
&& (parameters[1] as AzureMapsConfiguration).SubscriptionKey == fixture.Configuration.SubscriptionKey
91125
&& parameters[2] != null && parameters[2] is ServiceOptions
92126
&& (parameters[3] as IEnumerable<string>).Single() == MapEventType.Ready.ToString()
93127
&& parameters[4] != null && parameters[4] is DotNetObjectReference<MapEventInvokeHelper>
94128
)), Times.Once);
95-
_fixture.JsRuntime.VerifyNoOtherCalls();
129+
fixture.JsRuntime.VerifyNoOtherCalls();
96130
}
97131
}
98132
}

0 commit comments

Comments
 (0)