Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E test file component #4094

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/openforms/tests/e2e/data/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello
74 changes: 74 additions & 0 deletions src/openforms/tests/e2e/test_file_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from pathlib import Path
from unittest.mock import patch

from django.urls import reverse

from asgiref.sync import sync_to_async
from furl import furl
from playwright.async_api import expect
from rest_framework.test import APIRequestFactory

from openforms.forms.tests.factories import FormFactory
from openforms.tests.e2e.base import E2ETestCase, browser_page

factory = APIRequestFactory()

TEST_FILES = Path(__file__).parent / "data"


class FillInFormTests(E2ETestCase):
async def test_form_with_file_upload(self):
# If using the ci.py settings locally, the SDK_RELEASE variable should be set to 'latest', otherwise the
# JS/CSS for the SDK will not be found (since they will be expected to be in the folder
# openforms/static/sdk/<SDK version tag> instead of openforms/static/sdk
@sync_to_async
def setUpTestData():
# set up a form
form = FormFactory.create(
name="Form with file upload",
slug="form-with-file-upload",
generate_minimal_setup=True,
formstep__form_definition__name="First step",
formstep__form_definition__slug="first-step",
formstep__form_definition__configuration={
"components": [
{
"type": "file",
"key": "fileUpload",
"label": "File Upload",
"storage": "url",
}
]
},
translation_enabled=False, # force Dutch
ask_privacy_consent=False,
ask_statement_of_truth=False,
)
return form

form = await setUpTestData()
form_url = str(
furl(self.live_server_url)
/ reverse("forms:form-detail", kwargs={"slug": form.slug})
)

with patch("openforms.utils.validators.allow_redirect_url", return_value=True):
async with browser_page() as page:
await page.goto(form_url)

await page.get_by_role("button", name="Formulier starten").click()

async with page.expect_file_chooser() as fc_info:
await page.get_by_text("blader").click()

file_chooser = await fc_info.value
await file_chooser.set_files(TEST_FILES / "test.txt")

uploaded_file = page.get_by_text("test.txt")
await expect(uploaded_file).to_be_visible()

await page.get_by_role("button", name="Volgende").click()
await page.get_by_role("button", name="Verzenden").click()
await expect(
page.get_by_text("Een moment geduld", exact=False)
).to_be_visible()
Loading