Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions JournalApp.Tests/PinnedNotesTests.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@namespace JournalApp.Tests
@inherits JaTestContext

@code {
public override async Task InitializeAsync()
{
await base.InitializeAsync();

AddDbContext();
Services.GetService<AppDbSeeder>().SeedCategories();
}

[Fact]
public void CanPinAndUnpinNote()
{
// Arrange
var category = new DataPointCategory
{
Guid = Guid.NewGuid(),
Type = PointType.Note,
Group = "Notes",
};

var day = Day.Create(new(2024, 01, 01));
var point = DataPoint.Create(day, category);
point.Text = "Test note";

var layout = Render(
@<MainLayout>
<Body>
<DataPointView Point="point" />
</Body>
</MainLayout>
);

// Assert - Note should not be pinned initially
point.IsPinned.Should().BeFalse();

// Act - Pin the note
var pinButton = layout.Find(".note-pin-button");
pinButton.Click();

// Assert - Note should be pinned
point.IsPinned.Should().BeTrue();

// Act - Unpin the note
pinButton.Click();

// Assert - Note should be unpinned
point.IsPinned.Should().BeFalse();
}

[Fact]
public async Task PinnedNotesPageShowsPinnedNotes()
{
// Arrange
using var db = Services.GetService<IDbContextFactory<AppDbContext>>().CreateDbContext();
var today = DateOnly.FromDateTime(DateTime.Now);
var day = await db.GetOrCreateDayAndAddPoints(today);

// Create and pin a note
var note = db.CreateNote(day);
note.Text = "Pinned test note";
note.IsPinned = true;
note.Category.Points.Add(note);
await db.SaveChangesAsync();

// Act
var layout = Render(
@<MainLayout>
<Body>
<PinnedNotesPage />
</Body>
</MainLayout>
);

// Assert - Wait for the component to render and show pinned notes
layout.WaitForState(() => layout.FindAll(".pinned-note-card").Count > 0, timeout: TimeSpan.FromSeconds(5));
layout.Markup.Should().Contain("Pinned test note");
}

[Fact]
public void PinnedNotesPageShowsEmptyMessageWhenNoPinnedNotes()
{
// Arrange - No pinned notes

// Act
var layout = Render(
@<MainLayout>
<Body>
<PinnedNotesPage />
</Body>
</MainLayout>
);

// Assert
layout.Markup.Should().Contain("No pinned notes yet");
}
}
15 changes: 15 additions & 0 deletions JournalApp/Components/DataPointView.razor
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ else if (Point.Type == PointType.Note)
AutoGrow Lines="1" MaxLines="10" />
}

<MudIconButton Class="note-pin-button"
Icon="@Icons.Material.Rounded.PushPin"
aria-label="@(Point.IsPinned ? "Unpin note" : "Pin note")"
OnClick="TogglePin"
Color="@(Point.IsPinned ? Color.Primary : Color.Default)"
Size="Size.Small" />

<MudIconButton Class="note-edit-button"
Icon="@Icons.Material.Rounded.Edit"
aria-label="Edit note"
Expand Down Expand Up @@ -138,6 +145,14 @@ else if (Point.Type == PointType.Medication)
await StateChanged.InvokeAsync();
}

void TogglePin()
{
logger.LogDebug("Toggling pin for note");
Point.IsPinned = !Point.IsPinned;
// Note: Changes are persisted by the parent page's SaveState method
// which is called on navigation, window deactivation, or disposal
}

async Task OnMedicationTakenChanged()
{
// Use service to handle medication dose reset logic
Expand Down
5 changes: 5 additions & 0 deletions JournalApp/Data/DataPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class DataPoint
/// </summary>
public bool Deleted { get; set; }

/// <summary>
/// Indicates whether the note is pinned.
/// </summary>
public bool IsPinned { get; set; }

/// <summary>
/// The mood value of the data point, if applicable.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions JournalApp/Migrations/20251102061630_AddIsPinnedToDataPoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace JournalApp.Migrations
{
/// <inheritdoc />
public partial class AddIsPinnedToDataPoint : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsPinned",
table: "Points",
type: "INTEGER",
nullable: false,
defaultValue: false);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsPinned",
table: "Points");
}
}
}
3 changes: 3 additions & 0 deletions JournalApp/Migrations/AppDbContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<bool>("Deleted")
.HasColumnType("INTEGER");

b.Property<bool>("IsPinned")
.HasColumnType("INTEGER");

b.Property<decimal?>("MedicationDose")
.HasColumnType("TEXT");

Expand Down
Loading