Skip to content

Commit

Permalink
Feature: accessibility table added
Browse files Browse the repository at this point in the history
  • Loading branch information
x-Milosz authored Jan 18, 2025
1 parent f815eb9 commit f516a42
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install cypress
working-directory: "./tests/e2e_tests"
run: |
npm install cypress
npm install cypress && npm install cypress-browser-permissions
- name: Run e2e tests
run: |
PYTHONUNBUFFERED=1;FLASK_ENV=development;FLASK_APP="goodmap.goodmap:create_app(config_path='./tests/e2e_tests/e2e_test_config.yml')" poetry run flask run &
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ unit-tests-no-coverage:
poetry run python -m pytest -m "skip_coverage"

e2e-tests:
cd tests/e2e_tests && node_modules/cypress/bin/cypress run --browser chromium --spec cypress/e2e/basic-test/*
cd tests/e2e_tests && node_modules/cypress/bin/cypress run --browser chromium --spec "cypress/e2e/basic-test/*.cy.js"

e2e-stress-tests-generate-data:
python tests/e2e_tests/cypress/support/generate_stress_test_data.py
Expand Down
29 changes: 28 additions & 1 deletion goodmap/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Any, Dict, List

# TODO move filtering to db site


Expand All @@ -10,10 +12,35 @@ def does_fulfill_requirement(entry, requirements):
return all(matches)


def sort_by_distance(data: List[Dict[str, Any]], query_params: Dict[str, List[str]]):
try:
if "lat" in query_params and "lon" in query_params:
lat = float(query_params["lat"][0])
lon = float(query_params["lon"][0])
data.sort(key=lambda x: (x["position"][0] - lat) ** 2 + (x["position"][1] - lon) ** 2)
return data
return data
except (ValueError, KeyError, IndexError):
return data


def limit(data, query_params):
try:
if "limit" in query_params:
limit = int(query_params["limit"][0])
data = data[:limit]
return data
return data
except (ValueError, KeyError, IndexError):
return data


def get_queried_data(all_data, categories, query_params):
requirements = []
for key in categories.keys():
requirements.append((key, query_params.get(key)))

filtered_data = [x for x in all_data if does_fulfill_requirement(x, requirements)]
return filtered_data
final_data = sort_by_distance(filtered_data, query_params)
final_data = limit(final_data, query_params)
return final_data
1 change: 1 addition & 0 deletions goodmap/templates/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
window.SHOW_SUGGEST_NEW_POINT_BUTTON = {{ feature_flags.SHOW_SUGGEST_NEW_POINT_BUTTON | default(false) | tojson }};
window.SHOW_SEARCH_BAR = {{ feature_flags.SHOW_SEARCH_BAR | default(false) | tojson }};
window.USE_LAZY_LOADING = {{ feature_flags.USE_LAZY_LOADING | default(false) | tojson }};
window.SHOW_ACCESSIBILITY_TABLE = {{ feature_flags.SHOW_ACCESSIBILITY_TABLE | default(false) | tojson }};
</script>
<script src="/static/map.js"></script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { fakeLocation } from '../../utils/fake-location';

function rowElements() {
return cy.get('tr');
}

describe('Accessibility table test', () => {
beforeEach(() => {
const latitude = 51.10655;
const longitude = 17.0555;
cy.visit('/', fakeLocation(latitude, longitude));
cy.get('button[id="listViewButton"]').click();
});

it('should properly display places', () => {
rowElements()
// Header + 2 rows
.should('have.length', 3);
});

it("should 'Zwierzyniecka' be first row", () => {
rowElements().eq(1).find('td').should('contain', 'Zwierzyniecka');
});
});
1 change: 1 addition & 0 deletions tests/e2e_tests/e2e_test_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LANGUAGES:

FEATURE_FLAGS:
USE_LAZY_LOADING: False
SHOW_ACCESSIBILITY_TABLE: True
98 changes: 97 additions & 1 deletion tests/unit_tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from goodmap.core import does_fulfill_requirement, get_queried_data
from goodmap.core import does_fulfill_requirement, get_queried_data, limit, sort_by_distance

test_data = [
{
Expand Down Expand Up @@ -79,3 +79,99 @@ def test_category_match_if_not_specified():
]
filtered_data = list(filter(lambda x: does_fulfill_requirement(x, requirements), test_data))
assert filtered_data == expected_data


def test_that_limit_works_properly():
test_data_15_items = [
{
"name": f"PCK_{i+1}",
"position": [51.1, 17.05],
"types": ["clothes"],
"gender": ["male"],
}
for i in range(15)
]
expected_data = test_data_15_items[:10]
query_params = {"limit": ["10"]}
limited_data = limit(test_data_15_items, query_params)
assert limited_data == expected_data


def test_that_limit_does_not_change_data_if_limit_not_specified():
expected_data = [
{
"name": "LASSO",
"position": [51.113, 17.06],
"types": ["shoes"],
"gender": ["male", "female"],
},
{
"name": "PCK",
"position": [51.1, 17.05],
"types": ["clothes"],
"gender": ["male"],
},
]
limit_returned_data = limit(test_data, {})
assert limit_returned_data == expected_data


def test_that_sort_by_distance_works_as_intended():
expected_data = [
{
"name": "PCK",
"position": [51.1, 17.05],
"types": ["clothes"],
"gender": ["male"],
},
{
"name": "LASSO",
"position": [51.113, 17.06],
"types": ["shoes"],
"gender": ["male", "female"],
},
]

query_params = {"lat": ["51.1"], "lon": ["17.05"]}
sorted_data = sort_by_distance(test_data, query_params)
assert sorted_data == expected_data


def test_that_sort_by_distance_returns_data_when_query_params_are_corrupted():
expected_data = [
{
"name": "PCK",
"position": [51.1, 17.05],
"types": ["clothes"],
"gender": ["male"],
},
{
"name": "LASSO",
"position": [51.113, 17.06],
"types": ["shoes"],
"gender": ["male", "female"],
},
]
query_params = {"lat": ["51c.o1ruppted"], "lon": ["17c.05ruptted"]}
sorted_data = sort_by_distance(test_data, query_params)
assert sorted_data == expected_data


def test_that_limit_returns_data_when_query_params_are_corrupted():
expected_data = [
{
"name": "PCK",
"position": [51.1, 17.05],
"types": ["clothes"],
"gender": ["male"],
},
{
"name": "LASSO",
"position": [51.113, 17.06],
"types": ["shoes"],
"gender": ["male", "female"],
},
]
query_params = {"limit": ["1c0rupte0d"]}
limit_data = limit(test_data, query_params)
assert limit_data == expected_data

0 comments on commit f516a42

Please sign in to comment.