-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa8cce3
commit 0c4d405
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |