From f823d28749b8fc0c30fb92e1ffa8f9b6cb1b8c5d Mon Sep 17 00:00:00 2001 From: erdgeist Date: Sun, 2 Aug 2026 14:58:51 +0200 Subject: Test the neighbour revision pair arithmetic --- test/models/helpers/revisions_helper_test.rb | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'test/models/helpers/revisions_helper_test.rb') diff --git a/test/models/helpers/revisions_helper_test.rb b/test/models/helpers/revisions_helper_test.rb index 6bb5f077..f59823f9 100644 --- a/test/models/helpers/revisions_helper_test.rb +++ b/test/models/helpers/revisions_helper_test.rb @@ -1,4 +1,73 @@ require 'test_helper' class RevisionsHelperTest < ActionView::TestCase + class RevisionSet + def initialize revisions + @revisions = revisions + end + + def pages + self + end + + def exists? conditions + @revisions.include?(conditions[:revision]) + end + end + + def node_with *revisions + RevisionSet.new(revisions) + end + + test "a forward pair offers both neighbours in forward orientation" do + assert_equal [[2, 3], [4, 5]], + neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 3, 4) + end + + test "a reverse pair offers both neighbours in reverse orientation" do + assert_equal [[3, 2], [5, 4]], + neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 4, 3) + end + + test "the earliest pair has no earlier neighbour" do + assert_equal [nil, [2, 3]], + neighbour_revision_pairs(node_with(1, 2, 3), 1, 2) + end + + test "the latest pair has no later neighbour" do + assert_equal [[1, 2], nil], + neighbour_revision_pairs(node_with(1, 2, 3), 2, 3) + end + + test "a layer comparison offers no neighbours" do + assert_equal [nil, nil], + neighbour_revision_pairs(node_with(1, 2, 3), "head", "draft") + end + + test "mixing a layer with a number offers no neighbours" do + assert_equal [nil, nil], + neighbour_revision_pairs(node_with(1, 2, 3), "head", 3) + end + + test "a non-adjacent pair offers no neighbours" do + assert_equal [nil, nil], + neighbour_revision_pairs(node_with(1, 2, 3, 4, 5), 2, 5) + end + + # The controller sets both ends to 1 when a node has a single page. + test "a revision compared against itself offers no neighbours" do + assert_equal [nil, nil], neighbour_revision_pairs(node_with(1), 1, 1) + end + + test "string references are accepted, since they arrive from the query string" do + assert_equal [[1, 2], nil], + neighbour_revision_pairs(node_with(1, 2, 3), "2", "3") + end + + # Revision numbers are contiguous today. Should that stop being true, the + # control disables rather than pointing at a revision that is not there. + test "a gap disables the control rather than skipping over it" do + assert_equal [nil, [5, 6]], + neighbour_revision_pairs(node_with(1, 2, 4, 5, 6), 4, 5) + end end -- cgit v1.3