Skip to content

Commit

Permalink
fix all failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Mar 29, 2024
1 parent 68cdc27 commit a094078
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"sortablejs": "^1.15.0",
"tailwindcss": "^3.3.2",
"terser": "^5.16.5",
"tom-select": "^2.2.2",
"tom-select": "^2.3.1",
"ts-node": "^10.9.1",
"ts-pegjs": "^1.2.2",
"tslib": "^2.5.0",
Expand Down
16 changes: 8 additions & 8 deletions testapp/tests/test_e2e_fieldset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['customer'])
def test_submit_customer(page, mocker, viewname):
customer_collections = page.query_selector_all('django-formset > django-form-collection')
assert len(customer_collections) == 2
fieldset = customer_collections[0].query_selector('fieldset[df-hide]')
assert fieldset is not None
legend = fieldset.query_selector('legend')
assert legend.text_content() == "Customer"
assert customer_collections[1].query_selector('fieldset') is None
customer_collections = page.locator('django-formset > django-form-collection')
expect(customer_collections).to_have_count(2)
fieldset = customer_collections.first.locator('fieldset[df-hide]')
expect(fieldset).to_be_visible()
legend = fieldset.locator('legend')
expect(legend).to_have_text("Customer")
expect(customer_collections.last.locator('fieldset')).not_to_be_visible()
page.fill('#id_customer\\.name', "John Doe")
page.fill('#id_customer\\.address', "123, Lye Street")
spy = mocker.spy(FormCollectionView, 'post')
page.query_selector('django-formset button').click()
page.locator('django-formset button').first.click()
sleep(0.25)
assert spy.called
response = json.loads(spy.call_args.args[1].body)
Expand Down
11 changes: 8 additions & 3 deletions testapp/tests/test_e2e_optgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ def test_single_county(page, form, viewname):
else:
assert len(states) == 6
states[4] == "California"
input_field = page.locator('django-formset input[type="select-one"]')
input_field = page.locator('django-formset input[type="text"]')
input_field.type("gosh")
sleep(0.3) # tom-select's loadThrottle is set to 300ms
div_optgroup = page.locator('django-formset .ts-dropdown .optgroup')
expect(div_optgroup.locator('.optgroup-header')).to_have_text("Wyoming")
div_option = div_optgroup.locator('[role="option"]')
Expand All @@ -145,28 +146,32 @@ def test_few_counties(page, form, viewname):
states = [optgroups.nth(i).get_attribute('label') for i in range(optgroups.count())]
assert len(states) == 6
states[4] == "California"
input_field = page.locator('django-formset input[type="select-multiple"]')
input_field = page.locator('django-formset input[type="text"]')
input_field.type("clall")
sleep(0.3) # tom-select's loadThrottle is set to 300ms
div_optgroup = page.locator('django-formset .ts-dropdown .optgroup .optgroup-header')
div_option = page.locator('django-formset .ts-dropdown .optgroup [role="option"]')
expect(div_optgroup).to_have_text("Washington")
div_option = page.locator('django-formset .ts-dropdown .optgroup [role="option"]')
expect(div_option).to_have_text("Clallam (WA)")
div_option.click()
for _ in range(5):
page.keyboard.press("Backspace")
input_field.type("tillam")
sleep(0.3) # tom-select's loadThrottle is set to 300ms
expect(div_optgroup).to_have_text("Oregon")
expect(div_option).to_have_text("Tillamook (OR)")
div_option.click()
for _ in range(6):
page.keyboard.press("Backspace")
input_field.type("stani")
sleep(0.3) # tom-select's loadThrottle is set to 300ms
expect(div_optgroup).to_have_text("California")
expect(div_option).to_have_text("Stanislaus (CA)")
div_option.click()
for _ in range(5):
page.keyboard.press("Backspace")
input_field.type("lync")
sleep(0.3) # tom-select's loadThrottle is set to 300ms
expect(div_optgroup).to_have_text("Virginia")
expect(div_option).to_have_text("Lynchburg (VA)")
div_option.click()
Expand Down
10 changes: 6 additions & 4 deletions testapp/tests/test_e2e_preselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,19 @@ def test_multi_preselections(page, mocker, viewname):
assert first_option.inner_text() == str(queryset.first())
last_county = queryset[SelectizeMultiple.max_prefetch_choices - 1]
last_option = dropdown_element.locator(f'div[data-selectable][data-value="{last_county.id}"]')
assert last_option.inner_text() == str(last_county)
expect(last_option).to_have_text(str(last_county))
zapata_county = County.objects.get(name="Zapata")
expect(dropdown_element.locator(f'div[data-selectable][data-value="{zapata_county.id}"]')).to_have_count(0)
zapata_option = dropdown_element.locator(f'div[data-selectable][data-value="{zapata_county.id}"]')
expect(zapata_option).to_have_count(0)
page.locator('django-formset .ts-control input').type("zap")
sleep(0.5)
sleep(0.75)
spy.assert_called()
assert spy.spy_return.status_code == 200
content = json.loads(spy.spy_return.content)
spy.reset_mock()
assert content['count'] == 1
expect(dropdown_element.locator(f'div[data-selectable][data-value="{zapata_county.id}"]')).to_have_count(1)
expect(zapata_option).to_have_count(1)
expect(zapata_option).to_have_text("Zapata (TX)")


@pytest.mark.urls(__name__)
Expand Down
16 changes: 8 additions & 8 deletions testapp/tests/test_e2e_selectize.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ def test_initial_value(page, form, viewname):
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['selectize1'])
def test_changing_value(page, form, viewname):
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
assert input_element.get_attribute('placeholder') == 'Select'
expect(input_element).to_have_attribute('placeholder', 'Select')
assert input_element.evaluate('elem => elem.value') == ''
field_group_element = page.locator('django-formset [role="group"]')
expect(field_group_element).to_have_count(1)
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_changing_value(page, form, viewname):
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['selectize5'])
def test_add_multiple(page, form, viewname):
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-multiple"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
expect(input_element).to_have_attribute('placeholder', 'Select any')
assert input_element.evaluate('elem => elem.value') == ''
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_change_multiple(page, form, viewname):
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['selectize1'])
def test_lookup_value(page, mocker, form, viewname):
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
input_element.click()
spy = mocker.spy(FormView, 'get')
Expand Down Expand Up @@ -258,7 +258,7 @@ def test_submit_missing(page, view, form, viewname):
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['selectize1'])
def test_submit_value(page, mocker, view, form, viewname):
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
input_element.click()
dropdown_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-dropdown.single')
Expand All @@ -278,7 +278,7 @@ def test_submit_value(page, mocker, view, form, viewname):
@pytest.mark.urls(__name__)
@pytest.mark.parametrize('viewname', ['selectize1'])
def test_submit_invalid(page, mocker, view, form, viewname):
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
dropdown_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-dropdown.single')
expect(input_element).to_be_visible()
expect(dropdown_element).to_be_hidden()
Expand Down Expand Up @@ -311,7 +311,7 @@ def test_reset_selectize(page, view, form, viewname):
select_element = page.locator('django-formset select[is="django-selectize"]')
expect(select_element).to_be_visible()
initial_value = select_element.evaluate('elem => elem.value')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
if form.name in ['selection', 'static_selection']:
input_element.click()
Expand All @@ -337,7 +337,7 @@ def test_touch_selectize(page, form, viewname):
expect(field_group).to_have_class('dj-untouched dj-pristine')
placeholder = page.locator('django-formset ul.dj-errorlist > li.dj-placeholder')
expect(placeholder).to_have_text('')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="select-one"]')
input_element = page.locator('django-formset .shadow-wrapper .ts-wrapper .ts-control input[type="text"]')
expect(input_element).to_be_visible()
input_element.focus()
expect(field_group).to_have_class('dj-pristine dj-touched')
Expand Down

0 comments on commit a094078

Please sign in to comment.