|
| 1 | +import json |
| 2 | + |
| 3 | +import pytest |
| 4 | +from django.test import override_settings |
| 5 | +from django.utils.html import format_html |
| 6 | + |
| 7 | +from adhocracy4.test.helpers import render_template |
| 8 | + |
| 9 | + |
| 10 | +@override_settings(A4_MAP_BASEURL="https://{s}.tile.openstreetmap.org/") |
| 11 | +@override_settings(A4_MAP_ATTRIBUTION='<a href="example.com">attribution</a>') |
| 12 | +@pytest.mark.django_db |
| 13 | +def test_react_maps_without_point(rf, area_settings): |
| 14 | + request = rf.get("/") |
| 15 | + attrs = { |
| 16 | + "map": { |
| 17 | + "attribution": '<a href="example.com">attribution</a>', |
| 18 | + "useVectorMap": 0, |
| 19 | + "baseUrl": "https://{s}.tile.openstreetmap.org/", |
| 20 | + "polygon": area_settings.polygon, |
| 21 | + "name": "test", |
| 22 | + } |
| 23 | + } |
| 24 | + expected = format_html( |
| 25 | + '<div data-a4-widget="choose-point" data-attributes="{attributes}"></div>', |
| 26 | + attributes=json.dumps(attrs), |
| 27 | + ) |
| 28 | + |
| 29 | + context = {"request": request, "polygon": area_settings.polygon} |
| 30 | + template = '{% load react_maps_tags %}{% react_choose_point polygon=polygon point=point name="test" %}' |
| 31 | + result = render_template(template, context) |
| 32 | + assert result == expected |
| 33 | + |
| 34 | + |
| 35 | +@override_settings(A4_MAP_BASEURL="https://{s}.tile.openstreetmap.org/") |
| 36 | +@override_settings(A4_MAP_ATTRIBUTION='<a href="example.com">attribution</a>') |
| 37 | +@pytest.mark.django_db |
| 38 | +def test_react_maps_with_point(rf, area_settings): |
| 39 | + request = rf.get("/") |
| 40 | + point = {"test": [1, 2]} |
| 41 | + |
| 42 | + attrs = { |
| 43 | + "map": { |
| 44 | + "attribution": '<a href="example.com">attribution</a>', |
| 45 | + "useVectorMap": 0, |
| 46 | + "baseUrl": "https://{s}.tile.openstreetmap.org/", |
| 47 | + "polygon": area_settings.polygon, |
| 48 | + "point": point, |
| 49 | + "name": "test", |
| 50 | + } |
| 51 | + } |
| 52 | + expected = format_html( |
| 53 | + '<div data-a4-widget="choose-point" data-attributes="{attributes}"></div>', |
| 54 | + attributes=json.dumps(attrs), |
| 55 | + ) |
| 56 | + |
| 57 | + context = {"request": request, "polygon": area_settings.polygon, "point": point} |
| 58 | + template = '{% load react_maps_tags %}{% react_choose_point polygon=polygon point=point name="test" %}' |
| 59 | + result = render_template(template, context) |
| 60 | + assert result == expected |
0 commit comments