1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
from flask import render_template_string
def test_render_icon_svg(app, client):
@app.route('/icon')
def icon():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart') }}
''')
@app.route('/icon-size')
def icon_size():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', 32) }}
''')
@app.route('/icon-style')
def icon_style():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', color='primary') }}
''')
@app.route('/icon-color')
def icon_color():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', color='green') }}
''')
@app.route('/icon-title')
def icon_title():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', title='Heart') }}
''')
@app.route('/icon-desc-classes')
def icon_desc_classes():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', desc='A heart.', classes='text-success bg-light') }}
''')
response = client.get('/icon')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert 'width="1em"' in data
assert 'height="1em"' in data
response = client.get('/icon-size')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert 'width="32"' in data
assert 'height="32"' in data
response = client.get('/icon-style')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert 'text-primary' in data
response = client.get('/icon-color')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert 'style="color: green"' in data
response = client.get('/icon-title')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert '<title>Heart</title>' in data
response = client.get('/icon-desc-classes')
data = response.get_data(as_text=True)
assert 'bootstrap-icons.svg#heart' in data
assert '<desc>A heart.</desc>' in data
assert 'class="bi text-success bg-light"' in data
def test_render_icon_svg_config(app, client):
app.config['BOOTSTRAP_ICON_SIZE'] = 100
app.config['BOOTSTRAP_ICON_COLOR'] = 'success'
@app.route('/icon')
def icon():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart') }}
''')
response = client.get('/icon')
data = response.get_data(as_text=True)
assert 'width="100"' in data
assert 'height="100"' in data
assert 'text-success' in data
def test_render_icon_font(app, client):
@app.route('/icon')
def icon():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', font=True) }}
''')
@app.route('/icon-size')
def icon_size():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', 32, font=True) }}
''')
@app.route('/icon-style')
def icon_style():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', color='primary', font=True) }}
''')
@app.route('/icon-color')
def icon_color():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', color='green', font=True) }}
''')
response = client.get('/icon')
data = response.get_data(as_text=True)
assert '<i class="bi-heart' in data
assert 'size: 1em;' in data
response = client.get('/icon-size')
data = response.get_data(as_text=True)
assert '<i class="bi-heart' in data
assert 'size: 32;' in data
response = client.get('/icon-style')
data = response.get_data(as_text=True)
assert '<i class="bi-heart' in data
assert ' text-primary' in data
response = client.get('/icon-color')
data = response.get_data(as_text=True)
assert '<i class="bi-heart' in data
assert 'color: green;' in data
def test_render_icon_font_config(app, client):
app.config['BOOTSTRAP_ICON_SIZE'] = 100
app.config['BOOTSTRAP_ICON_COLOR'] = 'success'
@app.route('/icon')
def icon():
return render_template_string('''
{% from 'bootstrap4/utils.html' import render_icon %}
{{ render_icon('heart', font=True) }}
''')
response = client.get('/icon')
data = response.get_data(as_text=True)
assert 'size: 100;' in data
assert 'text-success' in data
|