Kavita/API.Tests/Helpers/TagHelperTests.cs
Joseph Milazzo 5812588fe5
misc stuff to avoid scan loop (#1389)
* Implemented a workaround for nginx users with BlockCommonExploits enabled, which would interfere with book image escaping done by Kavita when images had ../ in their path.

* Added back to top support on all pages but those that untilize virtual scrolling without a parent scroll.

* Hide jumpbar on pages where there is no scroll

* Refactored jumbar code into a dedicated service

* Stash some jumpkey resume code as I can't get it working with the virtual scroller.

* Don't allow non-admins to see File locations on card detail drawer.

* Some cleanup on GetServerInfo

* When an error occurs in register, delete the user on exception.

* Fixed a NPE in Stat collection for brand new users

* When we catch an exception on registering a new user, delete the user as rolling back doesn't do anything.

* Don't close typeahead when we are selecting options from it

* Added shortcut key H to open shortcut modal on manga reader

* When processing progress updates on cards, for volumes, properly find the chapter to update pages read.

* Hide cover image on reading list if it's not set and fixed a missing closing div tag

* Hide collection poster when nothing is set on collection detail

* Small fix around updating state

* Sped up the bookmark image call by removing one DB call

* Fixed broken test from change in bookmark code

* Fixed an oversight where if there is no tag in ComicInfo after a chapter was updated with People or Genres, then the People/Genres would never be removed.

* Added test with TagHelper

* Fixed a bug where 2 clear buttons would show on search bar due to browser injecting their own. Search bar wont show clear button until text is typed.

* Fixed a bug where InstallID wasn't being selected correctly in converter
2022-07-27 08:16:45 -07:00

141 lines
3.5 KiB
C#

using System.Collections.Generic;
using API.Data;
using API.Entities;
using API.Helpers;
using Xunit;
namespace API.Tests.Helpers;
public class TagHelperTests
{
[Fact]
public void UpdateTag_ShouldAddNewTag()
{
var allTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
};
var tagAdded = new List<Tag>();
TagHelper.UpdateTag(allTags, new[] {"Action", "Adventure"}, false, (tag, added) =>
{
if (added)
{
tagAdded.Add(tag);
}
});
Assert.Equal(1, tagAdded.Count);
Assert.Equal(4, allTags.Count);
}
[Fact]
public void UpdateTag_ShouldNotAddDuplicateTag()
{
var allTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
};
var tagAdded = new List<Tag>();
TagHelper.UpdateTag(allTags, new[] {"Action", "Scifi"}, false, (tag, added) =>
{
if (added)
{
tagAdded.Add(tag);
}
TagHelper.AddTagIfNotExists(allTags, tag);
});
Assert.Equal(3, allTags.Count);
Assert.Empty(tagAdded);
}
[Fact]
public void AddTag_ShouldAddOnlyNonExistingTag()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
};
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", false));
Assert.Equal(3, existingTags.Count);
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("action", false));
Assert.Equal(3, existingTags.Count);
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Shonen", false));
Assert.Equal(4, existingTags.Count);
}
[Fact]
public void AddTag_ShouldNotAddSameNameAndExternal()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("action", false),
DbFactory.Tag("Sci-fi", false),
};
TagHelper.AddTagIfNotExists(existingTags, DbFactory.Tag("Action", true));
Assert.Equal(3, existingTags.Count);
}
[Fact]
public void KeepOnlySamePeopleBetweenLists()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("Sci-fi", false),
};
var peopleFromChapters = new List<Tag>
{
DbFactory.Tag("Action", false),
};
var tagRemoved = new List<Tag>();
TagHelper.KeepOnlySameTagBetweenLists(existingTags,
peopleFromChapters, tag =>
{
tagRemoved.Add(tag);
});
Assert.Equal(1, tagRemoved.Count);
}
[Fact]
public void RemoveEveryoneIfNothingInRemoveAllExcept()
{
var existingTags = new List<Tag>
{
DbFactory.Tag("Action", false),
DbFactory.Tag("Sci-fi", false),
};
var peopleFromChapters = new List<Tag>();
var tagRemoved = new List<Tag>();
TagHelper.KeepOnlySameTagBetweenLists(existingTags,
peopleFromChapters, tag =>
{
tagRemoved.Add(tag);
});
Assert.Equal(2, tagRemoved.Count);
}
}