Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Version>2.11.1.0</Version>
<AssemblyVersion>2.11.1.0</AssemblyVersion>
<FileVersion>2.11.1.0</FileVersion>
<Version>2.12.0.0</Version>
<AssemblyVersion>2.12.0.0</AssemblyVersion>
<FileVersion>2.12.0.0</FileVersion>
</PropertyGroup>
</Project>
46 changes: 46 additions & 0 deletions LetterboxdSync.Tests/DashboardMarkupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public static IEnumerable<object[]> Pages() => new[]
new object[] { "userPage.html", "#letterboxdUserPage" },
};

public static IEnumerable<object[]> Files() => Pages().Select(p => new[] { p[0] });

private static string Read(string file)
{
var asm = typeof(Plugin).Assembly;
Expand Down Expand Up @@ -153,6 +155,50 @@ public void Controls_AreKeyboardReachable_AndNamed(string file, string root)
Assert.Contains(root + " :focus-visible { outline: 2px solid var(--ws-focus);", page, StringComparison.Ordinal);
}

[Theory]
[MemberData(nameof(Files))]
public void ActivityList_CanBeSearched_AndPagedToItsEnd(string file)
{
var page = Read(file);
Assert.Contains("id=\"historySearch\" placeholder=\"Search titles\" aria-label=\"Search activity by title\"", page, StringComparison.Ordinal);
Assert.Contains("<button type=\"button\" class=\"ws-btn\" id=\"historyMore\">Load older history</button>", page, StringComparison.Ordinal);

// GET History serves at most 200 Letterboxd events a page; asking for more silently got 200
// and the list stopped there. Each page asks for what the server gives, then pages by offset.
Assert.Matches(@"histChunk: 200,", page);
Assert.DoesNotMatch(@"History[^\n]*count(=|: )250", page);
Assert.Matches(@"offset(: |=' \+ )h\.loaded", page);
// The merged list stops at the oldest loaded event of a service with more to load, and an event
// that a later page repeats is shown once.
Assert.Contains("all = this.visibleEvents(f).filter(", page, StringComparison.Ordinal);
Assert.Contains("if (self.seen[k]) return false;", page, StringComparison.Ordinal);

// The group header of a binge is a button that says whether it is open, and every value it
// shows (show name, first and last episode) goes through the page's escaper.
var at = page.IndexOf("groupHtml: function", StringComparison.Ordinal);
Assert.True(at >= 0, "no groupHtml");
var groupHtml = Regex.Match(page.Substring(at), @"^groupHtml: function[\s\S]*?\n\s*\},").Value;
Assert.NotEmpty(groupHtml);
Assert.Matches(@"self\.esc(Attr)?\(u\.show\)", groupHtml);
Assert.Matches(@"self\.esc(Attr)?\(range\)", groupHtml);
Assert.Contains("class=\"ws-grp-btn ws-tc\" data-grp=\"' + id + '\" aria-expanded=\"false\"", page, StringComparison.Ordinal);
}

[Theory]
[MemberData(nameof(Files))]
public void AccountDialog_NamesTheServicesPlainly_AndRewordsTheWatchlistToggleWhenTheServiceChanges(string file)
{
var page = Read(file);
Assert.Contains("<option value=\"serializd\">Serializd: TV</option><option value=\"letterboxd\">Letterboxd: Film</option>", page, StringComparison.Ordinal);
// A new account opens as Serializd; switching it to Letterboxd must reword the watchlist toggle too.
var at = page.IndexOf("onSvcChange: function", StringComparison.Ordinal);
Assert.True(at >= 0, "no onSvcChange");
var end = new[] { "fillSecret: function", "openAccount: function" }
.Select(n => page.IndexOf(n, at, StringComparison.Ordinal)).Where(i => i > at).Min();
Assert.Contains("watchDesc.textContent = this.watchDesc(svc)", page.Substring(at, end - at), StringComparison.Ordinal);
Assert.Matches(@"'chkWatch', svc === 'serializd' \? !!a\.\w+ : !!a\.\w+, this\.watchDesc\(svc\)\]", page);
}

[Fact]
public void AdminPage_OffersThePromisedTelemetryAndLogBundlePreviews()
{
Expand Down
7 changes: 4 additions & 3 deletions LetterboxdSync.Tests/LetterboxdControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ public void GetHistory_EveryPageSizeTheDashboardsAskFor_IsServedInFull()
var resource = asm.GetManifestResourceNames().Single(n => n.EndsWith(".Web." + page, StringComparison.Ordinal));
using var reader = new StreamReader(asm.GetManifestResourceStream(resource)!);
var html = reader.ReadToEnd();
// "/History?count=250" (userPage) and "/History', { count: 250" (configPage).
// Literal sizes in the request ("/History?count=250", "/History', { count: 250") and the
// page-size settings the requests use ("histChunk: 200", "pageSize: 25").
requested.AddRange(System.Text.RegularExpressions.Regex
.Matches(html, @"/History(?:\?count=|'\s*,\s*\{\s*count:\s*)(\d+)")
.Select(m => int.Parse(m.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture)));
.Matches(html, @"/History(?:\?count=|'\s*,\s*\{\s*count:\s*)(\d+)|\b(?:histChunk|pageSize):\s*(\d+)")
.Select(m => int.Parse(m.Groups[1].Success ? m.Groups[1].Value : m.Groups[2].Value, System.Globalization.CultureInfo.InvariantCulture)));
}

Assert.NotEmpty(requested);
Expand Down
4 changes: 2 additions & 2 deletions LetterboxdSync/LetterboxdSync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyVersion>2.11.1.0</AssemblyVersion>
<FileVersion>2.11.1.0</FileVersion>
<AssemblyVersion>2.12.0.0</AssemblyVersion>
<FileVersion>2.12.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading
Loading