Skip to content

Commit

Permalink
Added coloring of PwEntries to TOTPEntries. (#183)
Browse files Browse the repository at this point in the history
* Added colors of PwEntry to TOTPEntry.
* Added tests for coloring.

Fixes #176
  • Loading branch information
dannoe committed Aug 29, 2020
1 parent 211b789 commit ab8ce8e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
14 changes: 10 additions & 4 deletions KeeTrayTOTP.Tests/Extensions/PwDocumentExtensions.cs
@@ -1,4 +1,5 @@
using KeePass.UI;
using System;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
Expand Down Expand Up @@ -37,12 +38,17 @@ public static PwDocument CreateRecycleBin(this PwDocument pwDocument)
}

public static PwDocument WithTotpEnabledEntries(this PwDocument pwDocument, int count)
{
return WithTotpEnabledEntries(pwDocument, count, entry => entry);
}

public static PwDocument WithTotpEnabledEntries(this PwDocument pwDocument, int count, Func<PwEntry, PwEntry> additionalConfigurations)
{
for (int i = 0; i < count; i++)
{
pwDocument.Database.RootGroup.AddEntry(
new PwEntry(true, true).WithValidTotpSettings(),
true);
var withValidTotpSettings = new PwEntry(true, true).WithValidTotpSettings();
var pwEntry = additionalConfigurations(withValidTotpSettings);
pwDocument.Database.RootGroup.AddEntry(pwEntry, true);
}

return pwDocument;
Expand Down
30 changes: 30 additions & 0 deletions KeeTrayTOTP.Tests/Menu/TrayMenuTests.cs
Expand Up @@ -5,7 +5,9 @@
using KeeTrayTOTP.Tests.Helpers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using KeePassLib;

namespace KeeTrayTOTP.Tests.Menu
{
Expand Down Expand Up @@ -144,5 +146,33 @@ public void BuildMenuItemsForRootDropDown_ShouldReturnEntryMenuItems_WhenRecycle
sut.Count.Should().Be(6,
"because, the recycle bin is treated as a regular folder.");
}

[TestMethod]
public void BuildMenuItemsForRootDropDown_ShouldReturnColoredEntryMenuItems_IfThereAreColoredPwEntries()
{
var foregroundColor = Color.Red;
var backgroundColor = Color.Blue;

PwEntry ApplyColor(PwEntry entry)
{
entry.ForegroundColor = foregroundColor;
entry.BackgroundColor = backgroundColor;
return entry;
}

var documents = new List<PwDocument>(new[]
{
new PwDocument().New().WithTotpEnabledEntries(1, ApplyColor).WithTotpEnabledEntries(1)
});

var sut = _trayMenuItemProvider.BuildMenuItemsForRootDropDown(documents).ToList();

sut.Should().Contain(
item =>
item.ForeColor == foregroundColor &&
item.BackColor == backgroundColor,
"because, there is one entry with these colors set.");
}

}
}
2 changes: 2 additions & 0 deletions KeeTrayTOTP/Menu/TrayMenuItemProvider.cs
Expand Up @@ -198,6 +198,8 @@ protected ToolStripMenuItem CreateMenuItemFromPwEntry(PwEntry entry, PwDatabase
{
Tag = entry,
Image = validEntry ? GetEntryImage(entry, pwDatabase) : Resources.TOTP_Error,
BackColor = entry.BackgroundColor,
ForeColor = entry.ForegroundColor,
Enabled = validEntry,
};
menuItem.Click += OnNotifyMenuTOTPClick;
Expand Down

0 comments on commit ab8ce8e

Please sign in to comment.