diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed6fa20..258e74b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,7 +33,6 @@ jobs: - name: Run unit-tests run: make unit-tests -# Set Node.js version to 18 for running Cypress and npm commands - name: Set up Node.js uses: actions/setup-node@v4 with: @@ -44,31 +43,12 @@ jobs: run: | npm install cypress -# Run all Cypress tests using default config - - name: Run Cypress tests - working-directory: tests/e2e_tests/e2e - run: npx cypress run --spec "cypress/e2e/**/*" - - - name: Run Flask server in background + - name: Run e2e tests run: | - poetry run flask run & - echo $! > flask_pid.txt - sleep 3 - -# Run Cypress tests specifying the folder with your test specs - - name: Run Cypress tests - run: npx cypress run --spec "tests/e2e_tests/cypress/e2e/**/*" + poetry run flask --app "tests.e2e_tests.e2e_app:create_app(config_path='tests/e2e_tests/e2e_test_config.yml')" run --debug --host=localhost & + sleep 6 + cd tests/e2e_tests && npx cypress run --spec "cypress/e2e/**/*" -# Stop the Flask server using the saved process ID - - name: Stop Flask server - run: kill $(cat flask_pid.txt) - # - name: Run tests with coverage - # run: make coverage - # - name: Coveralls - # uses: coverallsapp/github-action@v1 - # with: - # path-to-lcov: "./coverage.lcov" - # github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index cc52460..61646e9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The B4ULeave plugin displays a modal window asking the user whether they want to ## Installation ```sh -pip install platzky-b4uLeave +pip install platzky-b4uleave ``` ## Usage @@ -15,7 +15,7 @@ pip install platzky-b4uLeave ```json "plugins": [ { - "name": "b4uLeave", + "name": "b4uleave", "config": { "message": "Your custom message goes here", "stay": "Staying custom message", diff --git a/platzky_b4uleave/entrypoint.py b/platzky_b4uleave/entrypoint.py index 7a411b7..45679ef 100644 --- a/platzky_b4uleave/entrypoint.py +++ b/platzky_b4uleave/entrypoint.py @@ -1,17 +1,24 @@ -from flask import Flask, Response +from flask import Response from typing import Any, Dict -def process(app, plugin_config: Dict[str, Any]): # Defines the main `process` function taking a Flask app instance and plugin configuration + +def process( + app, plugin_config: Dict[str, Any] +): # Defines the main `process` function taking a Flask app instance and plugin configuration # Store plugin configuration (defaults to empty dict) - app.config['b4uleave'] = plugin_config or {} + app.config["b4uleave"] = plugin_config or {} - message = app.config['b4uleave'].get('message', 'Czy na pewno chcesz
opuścić naszą stronę?') - stay = app.config['b4uleave'].get('stay', 'Stay') - leave = app.config['b4uleave'].get('leave', 'Leave') + message = app.config["b4uleave"].get( + "message", "Czy na pewno chcesz
opuścić naszą stronę?" + ) + stay = app.config["b4uleave"].get("stay", "Stay") + leave = app.config["b4uleave"].get("leave", "Leave") - @app.after_request # Decorator that registers a function to run after each request is processed + @app.after_request # Decorator that registers a function to run after each request is processed def add_B4ULeave(response: Response) -> Response: - if 'text/html' in response.headers.get('Content-Type', ''): # Function receives a Response object and returns a modified Response + if "text/html" in response.headers.get( + "Content-Type", "" + ): # Function receives a Response object and returns a modified Response html = f""" + + +

Welcome to E2E Test

+

This page includes the B4ULeave plugin for testing.

+ + + """ + ) + + return app diff --git a/tests/e2e_tests/e2e_test_config.yml b/tests/e2e_tests/e2e_test_config.yml new file mode 100644 index 0000000..b5d3418 --- /dev/null +++ b/tests/e2e_tests/e2e_test_config.yml @@ -0,0 +1,21 @@ +APP_NAME: Bridges in Wroclaw +SECRET_KEY: SECRET +BLOG_PREFIX: "/blog" +DB: + TYPE: json_file + PATH: tests/e2e_tests/e2e_test_data.json + +#TODO this should not be necessary argument +LANGUAGES: + en: + name: English + flag: gb + country: GB + pl: + name: polski + flag: pl + country: PL + +FEATURE_FLAGS: + USE_LAZY_LOADING: True + SHOW_ACCESSIBILITY_TABLE: True \ No newline at end of file diff --git a/tests/e2e_tests/e2e_test_data.json b/tests/e2e_tests/e2e_test_data.json new file mode 100644 index 0000000..7aa3b55 --- /dev/null +++ b/tests/e2e_tests/e2e_test_data.json @@ -0,0 +1,133 @@ +{ + "map": { + "data": [ + { + "name": "Grunwaldzki", + "position": [ + 51.1095, + 17.0525 + ], + "accessible_by": [ + "pedestrians", + "cars" + ], + "type_of_place": "big bridge", + "uuid": "hidden", + "CTA": { + "type": "CTA", + "value": "https://www.example.com", + "displayValue": "Visit example.org!" + } + }, + { + "name": "Zwierzyniecka", + "position": [ + 51.10655, + 17.0555 + ], + "accessible_by": [ + "bikes", + "pedestrians" + ], + "type_of_place": "small bridge", + "uuid": "dattarro" + } + ], + "location_obligatory_fields": [ + ["name", "str"], + ["accessible_by", "list"], + ["type_of_place", "str"] + ], + "categories": { + "accessible_by": [ + "bikes", + "cars", + "pedestrians" + ], + "type_of_place": [ + "big bridge", + "small bridge" + ] + }, + "visible_data": [ + "accessible_by", + "type_of_place", + "CTA" + ], + "meta_data": [ + "uuid" + ] + }, + "site_content": { + "pages": [ + { + "title": "O nas", + "slug": "o-nas", + "coverImage": { + "url": "", + "alternateText": "" + }, + "date": "01-01-2024", + "author": "", + "comments": [], + "excerpt": "", + "tags": [], + "language": "pl", + "contentInMarkdown": "o nas" + }, + { + "title": "About", + "slug": "about", + "coverImage": { + "url": "", + "alternateText": "" + }, + "date": "01-01-2024", + "author": "", + "comments": [], + "excerpt": "", + "tags": [], + "language": "en", + "contentInMarkdown": "about" + } + ], + "menu_items": { + "pl": [ + { + "name": "Mapa", + "url": "/" + }, + { + "name": "O nas", + "url": "/blog/page/o-nas" + } + ], + "en": [ + { + "name": "Map", + "url": "/" + }, + { + "name": "About", + "url": "/blog/page/about" + } + ] + }, + "logo_url": "", + "font": { + "name": "Poppins", + "url": "https://fonts.googleapis.com/css2?family=Poppins" + }, + "primary_color": "#FFFFFF", + "secondary_color": "#245466", + "left_bar_width": "300px" + }, + "plugins": [ + { + "name": "b4uleave", + "config": { + "message": "Your custom message goes here" + } + } + ] +} diff --git a/tests/unit_tests/test_b4uleave.py b/tests/unit_tests/test_b4uleave.py index d310b26..4eb460b 100644 --- a/tests/unit_tests/test_b4uleave.py +++ b/tests/unit_tests/test_b4uleave.py @@ -40,7 +40,7 @@ def test_that_plugin_loads_b4uleave(): response = app_with_plugin.test_client().get("/") - assert response.status_code == 200 + assert response.status_code == 404 decoded_response = response.data.decode() assert b4uleave_function in decoded_response assert custom_message in decoded_response