mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 23:28:33 -06:00
testing view models
This commit is contained in:
@@ -80,4 +80,18 @@ public class SemesterPlannerTests
|
|||||||
semester.Months.Last().Month.Should().Be(1);
|
semester.Months.Last().Month.Should().Be(1);
|
||||||
semester.Months.Last().Year.Should().Be(2023);
|
semester.Months.Last().Year.Should().Be(2023);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSemesterTracksDaysOfWeek()
|
||||||
|
{
|
||||||
|
DayOfWeek[] days = new DayOfWeek[] { DayOfWeek.Monday };
|
||||||
|
var config = new SemesterConfiguration(
|
||||||
|
StartDate: new DateTime(2022, 12, 1),
|
||||||
|
EndDate: new DateTime(2023, 1, 1),
|
||||||
|
days
|
||||||
|
);
|
||||||
|
|
||||||
|
var semester = new SemesterPlanner(config);
|
||||||
|
semester.Days.Should().BeEquivalentTo(days);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Management\Management.csproj" />
|
<ProjectReference Include="..\Management\Management.csproj" />
|
||||||
|
<ProjectReference Include="..\Management.Web\Management.Web.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
14
Management.Test/ViewModels/MonthDetailTests.cs
Normal file
14
Management.Test/ViewModels/MonthDetailTests.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Management.Web.Shared.Semester;
|
||||||
|
|
||||||
|
public class MonthDetailTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestCanGetMonthName()
|
||||||
|
{
|
||||||
|
var detail = new MonthDetail();
|
||||||
|
var calendarMonth = new CalendarMonth(2022, 2);
|
||||||
|
detail.Month = calendarMonth;
|
||||||
|
|
||||||
|
detail.MonthName.Should().Be("February");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,10 @@
|
|||||||
{
|
{
|
||||||
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
get => terms?.FirstOrDefault(t => t.Id == selectedTermId);
|
||||||
}
|
}
|
||||||
|
private List<DayOfWeek> days { get; set; } = new();
|
||||||
|
private bool saved { get; set; } = false;
|
||||||
|
private SemesterConfiguration? configuration { get; set; }
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
terms = await canvasService.GetCurrentTermsFor();
|
terms = await canvasService.GetCurrentTermsFor();
|
||||||
@@ -38,5 +42,40 @@
|
|||||||
}
|
}
|
||||||
@if (selectedTerm is not null)
|
@if (selectedTerm is not null)
|
||||||
{
|
{
|
||||||
<SemesterDetail Term="selectedTerm" />
|
<h5>Select Days Of Week</h5>
|
||||||
|
<div class="row m-3">
|
||||||
|
@foreach (DayOfWeek day in (DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)))
|
||||||
|
{
|
||||||
|
<div class="col">
|
||||||
|
<button class="@(
|
||||||
|
days.Contains(day)
|
||||||
|
? "btn btn-secondary"
|
||||||
|
: "btn btn-outline-secondary"
|
||||||
|
)" @onclick="() => {
|
||||||
|
if(days.Contains(day))
|
||||||
|
days.Remove(day);
|
||||||
|
else
|
||||||
|
days.Add(day);
|
||||||
|
}" disabled="@saved">
|
||||||
|
@day
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-auto">
|
||||||
|
<button @onclick="() => {
|
||||||
|
saved = true;
|
||||||
|
configuration = ConfigurationManagement.CreateFromTerm(selectedTerm, days.ToArray());
|
||||||
|
}" class="btn btn-primary" disabled="@saved">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (configuration is not null)
|
||||||
|
{
|
||||||
|
<SemesterDetail Configuration="configuration" />
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,45 @@
|
|||||||
|
@using System.Linq;
|
||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public CalendarMonth Month { get; set; } = default!;
|
public CalendarMonth Month { get; set; } = default!;
|
||||||
|
|
||||||
|
[Parameter, EditorRequired]
|
||||||
|
public SemesterPlanner Semester { get; set; } = default!;
|
||||||
|
public DayOfWeek[] WeekDaysList { get => (DayOfWeek[])Enum.GetValues(typeof(DayOfWeek)); }
|
||||||
|
|
||||||
|
public string MonthName { get => Month?.DaysByWeek.First().FirstOrDefault(d => d != null)?.ToString("MMMM") ?? ""; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<h3 class="text-center">
|
||||||
|
@MonthName
|
||||||
|
</h3>
|
||||||
|
|
||||||
<div class="row text-center fw-bold">
|
<div class="row text-center fw-bold">
|
||||||
<div class="col">Saturday</div>
|
@foreach (DayOfWeek day in WeekDaysList)
|
||||||
<div class="col">Monday</div>
|
{
|
||||||
<div class="col">Tuesday</div>
|
<div class="@(Semester.Days.Contains(day) ? "col" : "col text-secondary")">@day</div>
|
||||||
<div class="col">Wednesday</div>
|
}
|
||||||
<div class="col">Thursday</div>
|
|
||||||
<div class="col">Friday</div>
|
|
||||||
<div class="col">Saturday</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@foreach (var week in Month.DaysByWeek)
|
@foreach (var week in Month.DaysByWeek)
|
||||||
{
|
{
|
||||||
<div class="row m-3">
|
<div class="row m-3">
|
||||||
@foreach (var day in week)
|
@foreach (var day in week)
|
||||||
{
|
{
|
||||||
<div class="col border rounded rounded-3 pb-5 m-1">@day?.Day</div>
|
|
||||||
|
var baseClasses = "col border rounded rounded-3 pb-5 m-1";
|
||||||
|
DayOfWeek? weekDay = day?.DayOfWeek;
|
||||||
|
if (weekDay != null)
|
||||||
|
{
|
||||||
|
DayOfWeek notNullDay = weekDay ?? default;
|
||||||
|
var totalClasses = Semester.Days.Contains(notNullDay) ? $"bg-light {baseClasses}" : baseClasses;
|
||||||
|
<div class="@totalClasses">@day?.Day</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="@baseClasses"></div>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@@ -4,20 +4,21 @@
|
|||||||
@code
|
@code
|
||||||
{
|
{
|
||||||
[Parameter, EditorRequired]
|
[Parameter, EditorRequired]
|
||||||
public EnrollmentTermModel Term { get; set; } = default!;
|
public SemesterConfiguration Configuration { get; set; } = default!;
|
||||||
|
|
||||||
@* private SemesterPlanner semester { get; set; } = default!;
|
private SemesterPlanner? semester { get; set; }
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
semester = new SemesterPlanner(Term);
|
semester = new SemesterPlanner(Configuration);
|
||||||
} *@
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Term.Name
|
}
|
||||||
|
<br>
|
||||||
@* @foreach (var month in semester.Months)
|
@if (semester != null)
|
||||||
{
|
{
|
||||||
<MonthDetail Month="month" />
|
@foreach (var month in semester.Months)
|
||||||
|
{
|
||||||
|
<MonthDetail Month="month" Semester="semester" />
|
||||||
<hr />
|
<hr />
|
||||||
} *@
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ using CanvasModel.EnrollmentTerms;
|
|||||||
public class SemesterPlanner
|
public class SemesterPlanner
|
||||||
{
|
{
|
||||||
public IEnumerable<CalendarMonth> Months { get; }
|
public IEnumerable<CalendarMonth> Months { get; }
|
||||||
|
public IEnumerable<DayOfWeek> Days { get; }
|
||||||
public SemesterPlanner(SemesterConfiguration configuration)
|
public SemesterPlanner(SemesterConfiguration configuration)
|
||||||
{
|
{
|
||||||
var start = configuration.StartDate;
|
var start = configuration.StartDate;
|
||||||
@@ -20,5 +21,6 @@ public class SemesterPlanner
|
|||||||
var year = start.Year + ((start.Month + monthDiff - 1) / 12);
|
var year = start.Year + ((start.Month + monthDiff - 1) / 12);
|
||||||
return new CalendarMonth(year, month);
|
return new CalendarMonth(year, month);
|
||||||
});
|
});
|
||||||
|
Days = configuration.Days;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user