Skip to content

Commit b227172

Browse files
Copilotkbeaugrand
andcommitted
Simplify CanWrite check by using true directly since page requires PlanningWrite permission
Co-authored-by: kbeaugrand <9513635+kbeaugrand@users.noreply.github.com>
1 parent f65c0f6 commit b227172

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/IoTHub.Portal.Client/Pages/Planning/CreatePlanningsPage.razor

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
@attribute [Authorize]
66

77
<AuthorizedContent IsLoading="@IsLoading" IsAuthorized="@IsAuthorized">
8-
<EditPlanning planning=@Planning scheduleList=@ScheduleList mode="New" CanWrite="@canWrite" />
8+
<EditPlanning planning=@Planning scheduleList=@ScheduleList mode="New" CanWrite="true" />
99
</AuthorizedContent>
1010

1111
@code {
1212
// Specify which permissions are required for this page
1313
protected override PortalPermissions[] RequiredPermissions { get; } = { PortalPermissions.PlanningWrite };
14-
private bool canWrite;
1514

1615
public List<ScheduleDto> ScheduleList { get; set; } = new List<ScheduleDto> { };
1716
public PlanningDto Planning { get; set; } = new PlanningDto();
@@ -22,8 +21,5 @@
2221

2322
Planning.DayOff = DaysEnumFlag.DaysOfWeek.Saturday | DaysEnumFlag.DaysOfWeek.Sunday;
2423
ScheduleList.Add(new ScheduleDto { Start = "00:00" });
25-
26-
// Check if user has write permission for conditional UI elements
27-
canWrite = await HasPermissionAsync(PortalPermissions.PlanningWrite);
2824
}
2925
}

src/IoTHub.Portal.Tests.Unit/Client/Pages/Planning/CreatePlanningsPageTest.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,28 @@ public void OnInitializedAsync_CreatePlanningPage()
5555
Assert.AreEqual(cut.Instance.ScheduleList[0].Start, "00:00");
5656
cut.WaitForAssertion(() => MockRepository.VerifyAll());
5757
}
58+
59+
[Test]
60+
public void CreatePlanningPage_SaveButtonIsDisplayed()
61+
{
62+
_ = this.mockLayerClientService.Setup(service => service.GetLayers())
63+
.ReturnsAsync(new List<LayerDto>());
64+
65+
_ = this.mockDeviceModelsClientService.Setup(service => service.GetDeviceModelsAsync(It.IsAny<DeviceModelFilter>()))
66+
.ReturnsAsync(new PaginationResult<DeviceModelDto>
67+
{
68+
Items = new List<DeviceModelDto>()
69+
});
70+
71+
// Act
72+
var cut = RenderComponent<CreatePlanningsPage>();
73+
74+
// Wait for the save button to be rendered
75+
var saveButton = cut.WaitForElement("#saveButton");
76+
77+
// Assert
78+
Assert.IsNotNull(saveButton);
79+
cut.WaitForAssertion(() => MockRepository.VerifyAll());
80+
}
5881
}
5982
}

0 commit comments

Comments
 (0)