from unittest import TestCase

from regulations.generator.layers.footnotes import FootnotesLayer


class FootnotesLayerTest(TestCase):
    def test_single_note(self):
        layer = {
            "555-220-p1": [
                {
                    "footnote_data": {
                        "note": "Some notes",
                        "ref": "1"
                    },
                    "locations": [
                        0
                    ],
                    "text": "[^1]Some actual text"
                }
            ]
        }
        fl = FootnotesLayer(layer)
        self.assertEqual(fl.apply_layer('555-220'), ('footnotes',
                         [{'ref': '1',
                           'note': 'Some notes'}]))

    def test_sorted_multiple_notes(self):
        layer = {
            "555-220-p1": [
                {
                    "footnote_data": {
                        "note": "Third notes",
                        "ref": "3"
                    },
                    "locations": [
                        0
                    ],
                    "text": "[^3]Some actual text"
                },
                {
                    "footnote_data": {
                        "note": "First notes",
                        "ref": "1"
                    },
                    "locations": [
                        0
                    ],
                    "text": "[^1]Some actual text"
                },
                {
                    "footnote_data": {
                        "note": "Second notes",
                        "ref": "2"
                    },
                    "locations": [
                        0
                    ],
                    "text": "[^2]Some actual text"
                }
            ]
        }
        fl = FootnotesLayer(layer)
        self.assertEqual(fl.apply_layer('555-220'), ('footnotes',
                         [
                             {'ref': '1', 'note': 'First notes'},
                             {'ref': '2', 'note': 'Second notes'},
                             {'ref': '3', 'note': 'Third notes'},
                         ]))

@@ -2149,12 +2149,1085 @@
         %5D))%0A
+%0A    def test_multiple_children(self):%0A        layer = %7B%0A            %22555-220-p1%22: %5B%0A                %7B%0A                    %22footnote_data%22: %7B%0A                        %22note%22: %22First notes%22,%0A                        %22ref%22: %221%22%0A                    %7D,%0A                    %22locations%22: %5B%0A                        0%0A                    %5D,%0A                    %22text%22: %22%5B%5E1%5DSome actual text%22%0A                %7D%0A            %5D,%0A            %22555-220-p2%22: %5B%0A                %7B%0A                    %22footnote_data%22: %7B%0A                        %22note%22: %22Second notes%22,%0A                        %22ref%22: %222%22%0A                    %7D,%0A                    %22locations%22: %5B%0A                        0%0A                    %5D,%0A                    %22text%22: %22%5B%5E1%5DSome actual text%22%0A                %7D%0A            %5D%0A        %7D%0A        fl = FootnotesLayer(layer)%0A        self.assertEqual(fl.apply_layer('555-220'), ('footnotes',%0A                         %5B%0A                             %7B'ref': '1', 'note': 'First notes'%7D,%0A                             %7B'ref': '2', 'note': 'Second notes'%7D,%0A                         %5D))%0A

Add test to verify note collation across paragraphs