Skip to content

Commit

Permalink
Add some tests for demo mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
christabor committed Jan 3, 2017
1 parent d300813 commit 6860387
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions flask_jsondash/templates/pages/chart_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
{% block chart_body %}
<div class="row">
<div class="col-md-12">
<h2 class="lead text-center">
<h2 class="chart-header lead text-center">
{% if not demo_mode %}
<small>
<a href="{{ url_for('jsondash.dashboard') }}" class="btn-xs btn-default pull-left">
<a href="{{ url_for('jsondash.dashboard') }}" class="btn-xs btn btn-default pull-left">
<span class="fa fa-angle-left"></span> Back
</a>
</small>
Expand Down
28 changes: 28 additions & 0 deletions tests/test_charts_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,31 @@ def test_update_valid(monkeypatch, ctx, client):
flash_msg = 'Updated view "{}"'.format(view_id)
assert dom.find('.alert-info').text() == flash_msg
assert len(read()) == 1


def test_no_demo_mode(monkeypatch, ctx, client):
app, test = client
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
data = dict(name='newname', modules=[])
test.post(url_for('jsondash.create'), data=data, follow_redirects=True)
view_id = read()[0]['id']
url = url_for('jsondash.view', c_id=view_id)
res = test.get(url)
dom = pq(res.data)
assert dom.find('.chart-header small > .btn')
assert dom.find('.chart-header small > .btn').text().strip() == 'Back'
assert dom.find('.chart-header .dropdown-toggle')


def test_demo_mode(monkeypatch, ctx, client):
# Test that certain UI elements are removed when in demo mode.
app, test = client
monkeypatch.setattr(charts_builder, 'auth', auth_valid)
data = dict(name='newname', modules=[])
test.post(url_for('jsondash.create'), data=data, follow_redirects=True)
view_id = read()[0]['id']
url = url_for('jsondash.view', c_id=view_id) + '?jsondash_demo_mode=1'
res = test.get(url)
dom = pq(res.data)
assert not dom.find('.chart-header > small .btn')
assert not dom.find('.chart-header .dropdown-toggle')

0 comments on commit 6860387

Please sign in to comment.