3
0
Fork 0

feat: add basic support for merging 2 records, w/ preview

including basic logic for merging Person or User records
This commit is contained in:
Lance Edgar 2026-03-20 17:20:02 -05:00
parent 8bfbf0e570
commit ee3a789682
10 changed files with 1554 additions and 73 deletions

View file

@ -33,6 +33,94 @@ class TestWebDiff(WebTestCase):
self.assertIn("</table>", html)
class TestMergeDiff(WebTestCase):
def make_diff(self, *args, **kwargs):
return mod.MergeDiff(self.config, *args, **kwargs)
def test_get_final_value_attrs(self):
# no diff
removing = {"foo": "bar"}
keeping = {"foo": "bar"}
final = {"foo": "bar"}
is_diff = False
diff = self.make_diff(removing, keeping, final)
attrs = diff.get_final_value_attrs(is_diff)
self.assertEqual(attrs, {})
# values differ
keeping = {"foo": "baz"}
final = {"foo": "baz"}
is_diff = True
diff = self.make_diff(removing, keeping, final)
attrs = diff.get_final_value_attrs(is_diff)
self.assertEqual(attrs, {"class_": "has-background-warning"})
def test_render_field_row(self):
# no diffs
removing = {"foo": "bar"}
keeping = {"foo": "bar"}
final = {"foo": "bar"}
diff = self.make_diff(removing, keeping, final)
html = diff.render_field_row("foo")
self.assertTrue(html.startswith("<tr>"))
self.assertNotIn('style="padding: 0.5rem;"', html)
self.assertIn("&#39;bar&#39;", html)
self.assertNotIn(f'style="background-color: {diff.old_color}"', html)
self.assertNotIn("&#39;baz&#39;", html)
self.assertNotIn(f'style="background-color: {diff.new_color}"', html)
self.assertNotIn("&#39;bar,baz&#39;", html)
self.assertNotIn('class="has-background-warning"', html)
self.assertTrue(html.endswith("</tr>"))
# remove vs. keep diffs, but not keep vs. final
removing = {"foo": "bar"}
keeping = {"foo": "baz"}
final = {"foo": "baz"}
diff = self.make_diff(removing, keeping, final)
html = diff.render_field_row("foo")
self.assertTrue(html.startswith("<tr>"))
self.assertNotIn('style="padding: 0.5rem;"', html)
self.assertIn("&#39;bar&#39;", html)
self.assertIn(f'style="background-color: {diff.old_color}"', html)
self.assertIn("&#39;baz&#39;", html)
self.assertIn(f'style="background-color: {diff.new_color}"', html)
self.assertNotIn("&#39;bar,baz&#39;", html)
self.assertNotIn('class="has-background-warning"', html)
self.assertTrue(html.endswith("</tr>"))
# remove vs. keep diffs, *and* keep vs. final diffs
removing = {"foo": "bar"}
keeping = {"foo": "baz"}
final = {"foo": "bar,baz"}
diff = self.make_diff(removing, keeping, final)
html = diff.render_field_row("foo")
self.assertTrue(html.startswith("<tr>"))
self.assertNotIn('style="padding: 0.5rem;"', html)
self.assertIn("&#39;bar&#39;", html)
self.assertIn(f'style="background-color: {diff.old_color}"', html)
self.assertIn("&#39;baz&#39;", html)
self.assertIn(f'style="background-color: {diff.new_color}"', html)
self.assertIn("&#39;bar,baz&#39;", html)
self.assertIn('class="has-background-warning"', html)
self.assertTrue(html.endswith("</tr>"))
# again, with cell padding
diff.cell_padding = "0.5rem"
html = diff.render_field_row("foo")
self.assertTrue(html.startswith("<tr>"))
self.assertIn('style="padding: 0.5rem"', html)
self.assertIn("&#39;bar&#39;", html)
self.assertIn(f"background-color: {diff.old_color}", html)
self.assertIn("&#39;baz&#39;", html)
self.assertIn(f"background-color: {diff.new_color}", html)
self.assertIn("&#39;bar,baz&#39;", html)
self.assertIn('class="has-background-warning"', html)
self.assertTrue(html.endswith("</tr>"))
class TestVersionDiff(VersionWebTestCase):
def make_diff(self, *args, **kwargs):