6
6
import pytest
7
7
8
8
from tests import TEST_DOCS_SRC
9
+ from sphinx_search .extension import CUSTOM_ASSETS_FILES
9
10
10
11
11
12
@pytest .mark .sphinx (srcdir = TEST_DOCS_SRC )
@@ -14,31 +15,62 @@ def test_static_files_exists(app, status, warning):
14
15
app .build ()
15
16
path = app .outdir
16
17
17
- js_file = os .path .join (path , '_static' , 'js' , 'rtd_sphinx_search.min.js' )
18
- css_file = os .path .join (path , '_static' , 'css' , 'rtd_sphinx_search.min.css' )
18
+ static_files = CUSTOM_ASSETS_FILES ['MINIFIED' ] + CUSTOM_ASSETS_FILES ['UN_MINIFIED' ]
19
19
20
- assert (
21
- os .path .exists (js_file ) is True
22
- ), 'js file should be copied to build folder'
20
+ for file in static_files :
21
+ file_path = os .path .join (path , '_static' , file )
22
+ assert (
23
+ os .path .exists (file_path )
24
+ ), f'{ file_path } should be present in the _build folder'
23
25
24
- assert (
25
- os .path .exists (css_file ) is True
26
- ), 'css file should be copied to build folder'
27
26
27
+ @pytest .mark .sphinx (
28
+ srcdir = TEST_DOCS_SRC ,
29
+ confoverrides = {
30
+ 'RTD_SPHINX_SEARCH_FILE_TYPE' : 'MINIFIED'
31
+ }
32
+ )
33
+ def test_minified_static_files_injected_in_html (selenium , app , status , warning ):
34
+ """Test if the static files are correctly injected in the html."""
35
+ app .build ()
36
+ path = app .outdir / 'index.html'
28
37
29
- @pytest .mark .sphinx (srcdir = TEST_DOCS_SRC )
30
- def test_static_files_injected_in_html (selenium , app , status , warning ):
38
+ selenium .get (f'file://{ path } ' )
39
+ page_source = selenium .page_source
40
+
41
+ assert app .config .RTD_SPHINX_SEARCH_FILE_TYPE == 'MINIFIED'
42
+
43
+ file_type = app .config .RTD_SPHINX_SEARCH_FILE_TYPE
44
+ files = CUSTOM_ASSETS_FILES [file_type ]
45
+
46
+ for file in files :
47
+ file_name = file .split ('/' )[- 1 ]
48
+ assert (
49
+ page_source .count (file_name ) == 1
50
+ ), f'{ file } should be present in the page source'
51
+
52
+
53
+ @pytest .mark .sphinx (
54
+ srcdir = TEST_DOCS_SRC ,
55
+ confoverrides = {
56
+ 'RTD_SPHINX_SEARCH_FILE_TYPE' : 'UN_MINIFIED'
57
+ }
58
+ )
59
+ def test_un_minified_static_files_injected_in_html (selenium , app , status , warning ):
31
60
"""Test if the static files are correctly injected in the html."""
32
61
app .build ()
33
62
path = app .outdir / 'index.html'
34
63
35
64
selenium .get (f'file://{ path } ' )
36
65
page_source = selenium .page_source
37
66
38
- assert (
39
- page_source .count ('rtd_sphinx_search.min.js' ) == 1
40
- ), 'js file should be injected only once'
67
+ assert app .config .RTD_SPHINX_SEARCH_FILE_TYPE == 'UN_MINIFIED'
68
+
69
+ file_type = app .config .RTD_SPHINX_SEARCH_FILE_TYPE
70
+ files = CUSTOM_ASSETS_FILES [file_type ]
41
71
42
- assert (
43
- page_source .count ('rtd_sphinx_search.min.css' ) == 1
44
- ), 'css file should be injected only once'
72
+ for file in files :
73
+ file_name = file .split ('/' )[- 1 ]
74
+ assert (
75
+ page_source .count (file_name ) == 1
76
+ ), f'{ file_name } should be present in the page source'
0 commit comments