From d221452e7e44408da4863bb5e4a09952ee96857d Mon Sep 17 00:00:00 2001 From: AnnMarieW Date: Wed, 8 Jun 2022 16:41:40 -0700 Subject: [PATCH 1/3] fixed tests --- CHANGELOG.md | 6 ++++++ dash/dash.py | 2 +- tests/integration/test_integration.py | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73f20f58e5..d33c21c22a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## Unreleased + +### Fixed +- []() In dash 2.5.0, a default viewport meta tag was added as recommended for mobile-optimized sites by [mdn](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag) +This feature can be disabled by providing an empty viewport meta tag. e.g. `app = Dash(meta_tags=[{"name": "viewport"}])` + ## [2.5.0] - 2022-06-07 ### Added diff --git a/dash/dash.py b/dash/dash.py index 8c95f1791a..71bf360834 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -843,7 +843,7 @@ def _generate_meta_html(self): x.get("http-equiv", "") == "X-UA-Compatible" for x in meta_tags ) has_charset = any("charset" in x for x in meta_tags) - has_viewport = any("viewport" in x for x in meta_tags) + has_viewport = any(x.get("name") == "viewport" for x in meta_tags) tags = [] if not has_ie_compat: diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 0a28752053..40104c1f0b 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -133,6 +133,29 @@ def test_inin007_meta_tags(dash_duo): assert meta_tag.get_attribute("content") == meta_info["content"] +def test_inin007b_change_viewport_meta_tag(dash_duo): + """ + As of dash 2.5 the default viewport meta tag is: + [{"name": "viewport", "content": "width=device-width, initial-scale=1"}] + Test verifies that this feature can be disabled by using an empty viewport tag. + """ + + app = Dash(meta_tags=[{"name": "viewport"}]) + + app.layout = html.Div(id="content") + + dash_duo.start_server(app) + + meta = dash_duo.find_elements("meta") + + # -3 for the meta charset, http-equiv and viewport. + assert len(meta) == 3, "Should have 3 meta tags" + + viewport_meta = meta[2] + assert viewport_meta.get_attribute("name") == "viewport" + assert viewport_meta.get_attribute("content") == "" + + def test_inin008_index_customization(dash_duo): app = Dash() From ca362292dfe70c27a6a42fd842817328536dca0c Mon Sep 17 00:00:00 2001 From: AnnMarieW Date: Wed, 8 Jun 2022 17:05:25 -0700 Subject: [PATCH 2/3] Updated CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d33c21c22a..39bb5e8b9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## Unreleased ### Fixed -- []() In dash 2.5.0, a default viewport meta tag was added as recommended for mobile-optimized sites by [mdn](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag) +- [#2084](https://github.com/plotly/dash/pull/2084) In dash 2.5.0, a default viewport meta tag was added as recommended for mobile-optimized sites by [mdn](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag) This feature can be disabled by providing an empty viewport meta tag. e.g. `app = Dash(meta_tags=[{"name": "viewport"}])` ## [2.5.0] - 2022-06-07 From ecb35c302ba0484f62457d3eaa9c4acd37058a31 Mon Sep 17 00:00:00 2001 From: AnnMarieW Date: Thu, 9 Jun 2022 05:18:09 -0700 Subject: [PATCH 3/3] fixed test --- tests/integration/test_integration.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index 40104c1f0b..d2659ac54f 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -16,7 +16,7 @@ from dash.testing.wait import until -def test_inin004_wildcard_data_attributes(dash_duo): +def test_inin003_wildcard_data_attributes(dash_duo): app = Dash() test_time = datetime.datetime(2012, 1, 10, 2, 3) test_date = datetime.date(test_time.year, test_time.month, test_time.day) @@ -48,7 +48,7 @@ def test_inin004_wildcard_data_attributes(dash_duo): assert dash_duo.get_logs() == [] -def test_inin005_no_props_component(dash_duo): +def test_inin004_no_props_component(dash_duo): app = Dash() app.layout = html.Div( [ @@ -71,7 +71,7 @@ def test_inin005_no_props_component(dash_duo): assert re.sub("\\s+", " ", inner) == expected -def test_inin006_flow_component(dash_duo): +def test_inin005_flow_component(dash_duo): app = Dash() app.layout = html.Div( @@ -109,7 +109,7 @@ def display_output(react_value, flow_value): dash_duo.percy_snapshot(name="flowtype") -def test_inin007_meta_tags(dash_duo): +def test_inin006_meta_tags(dash_duo): metas = [ {"name": "description", "content": "my dash app"}, {"name": "custom", "content": "customized"}, @@ -133,7 +133,7 @@ def test_inin007_meta_tags(dash_duo): assert meta_tag.get_attribute("content") == meta_info["content"] -def test_inin007b_change_viewport_meta_tag(dash_duo): +def test_inin007_change_viewport_meta_tag(dash_duo): """ As of dash 2.5 the default viewport meta tag is: [{"name": "viewport", "content": "width=device-width, initial-scale=1"}] @@ -146,14 +146,10 @@ def test_inin007b_change_viewport_meta_tag(dash_duo): dash_duo.start_server(app) - meta = dash_duo.find_elements("meta") - - # -3 for the meta charset, http-equiv and viewport. - assert len(meta) == 3, "Should have 3 meta tags" + viewport_meta = dash_duo.find_elements('meta[name="viewport"]') - viewport_meta = meta[2] - assert viewport_meta.get_attribute("name") == "viewport" - assert viewport_meta.get_attribute("content") == "" + assert len(viewport_meta) == 1, "Should have 1 viewport meta tags" + assert viewport_meta[0].get_attribute("content") == "" def test_inin008_index_customization(dash_duo):