Skip to content

Commit a13fadd

Browse files
authored
Add: end-to-end tests for translations (#344)
1 parent 428241a commit a13fadd

7 files changed

Lines changed: 58 additions & 13 deletions

File tree

e2e/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ async def _run_server():
4141
os.makedirs("data")
4242
with open("data/LICENSE.mediawiki", "w") as f:
4343
f.write("end-to-end test file")
44+
# Make sure a few languages exist.
45+
os.makedirs("data/Page/en")
46+
os.makedirs("data/Page/de")
4447

4548
# Run TrueWiki, with coverage enabled.
4649
command = ["coverage", "run", "--branch", "--source", "truewiki"]

e2e/e2e_edit.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ def test_create_page_again(page: Page, login):
6565
create.click()
6666
page.wait_for_url("/edit/en/Main%20Page")
6767

68-
page.locator("[name=content]").fill("My Third Edit\n\n[[Category:en/MyPages]]\n{{en/Summary}}\n{{Page:en/Empty}}")
68+
page.locator("[name=content]").fill(
69+
"[[Translation:en/Main Page]]\nMy Third Edit\n\n[[Category:en/MyPages]]\n{{en/Summary}}\n{{Page:en/Empty}}"
70+
)
6971
with page.expect_navigation():
7072
page.locator("[name=save]").click()
7173
page.wait_for_url("/en/Main%20Page")
@@ -135,12 +137,12 @@ def test_rename_page_invalid_language(page: Page, login):
135137
edit.click()
136138
page.wait_for_url("/edit/en/Main%20Page")
137139

138-
page.locator("[name=page]").fill("de/Main Page")
140+
page.locator("[name=page]").fill("zz/Main Page")
139141
with page.expect_navigation():
140142
page.locator("[name=save]").click()
141143
page.wait_for_url("/edit/en/Main%20Page")
142144

143-
expect(page.locator('text=Page name "de/Main Page" is in language "de" that does not exist.')).to_be_visible()
145+
expect(page.locator('text=Page name "zz/Main Page" is in language "zz" that does not exist.')).to_be_visible()
144146

145147

146148
def test_rename_page_invalid_casing(page: Page, login):
@@ -205,3 +207,40 @@ def test_edit_page_invalid_language(page: Page, login):
205207
"""View a page with an invalid language."""
206208
page.goto("http://localhost:8080/test/invalid")
207209
expect(page.locator('text=Page name "test/invalid" is in language "test" that does not exist.')).to_be_visible()
210+
211+
212+
def test_create_translation(page: Page, login):
213+
"""Create a translation for the main page."""
214+
page.goto("http://localhost:8080/de/")
215+
216+
create = page.locator("text=Create Page")
217+
expect(create).to_be_visible()
218+
with page.expect_navigation():
219+
create.click()
220+
page.wait_for_url("/edit/de/Main%20Page")
221+
222+
page.locator("[name=content]").fill(
223+
"[[Translation:en/Main Page]]\nMein dritter Edit\n\n[[Category:de/MyPages]]\n{{de/Summary}}\n{{Page:de/Empty}}"
224+
)
225+
with page.expect_navigation():
226+
page.locator("[name=save]").click()
227+
page.wait_for_url("/de/Main%20Page")
228+
229+
expect(page).to_have_title("Unnamed | Unnamed's Wiki")
230+
expect(page.locator("text=Mein dritter Edi")).to_be_visible()
231+
expect(page.locator("text=Page:de/Empty")).to_be_visible()
232+
233+
234+
def test_language_bar(page: Page):
235+
"""Check that the language bar is working."""
236+
page.goto("http://localhost:8080/de/")
237+
238+
expect(page.locator('strong:has-text("de")')).to_be_visible()
239+
en = page.locator("#language-bar >> text=en")
240+
expect(en).to_be_visible()
241+
with page.expect_navigation():
242+
en.click()
243+
page.wait_for_url("/en/")
244+
245+
expect(page.locator('strong:has-text("en")')).to_be_visible()
246+
expect(page.locator("#language-bar >> text=de")).to_be_visible()

e2e/e2e_namespace_category.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ def test_category_edit_invalid_language(page: Page, login):
118118
edit.click()
119119
page.wait_for_url("/edit/Category/en/")
120120

121-
page.locator("[name=page]").fill("Category/de/test")
121+
page.locator("[name=page]").fill("Category/zz/test")
122122
page.locator("[name=content]").fill("Some text")
123123
with page.expect_navigation():
124124
page.locator("[name=save]").click()
125125
page.wait_for_url("/edit/Category/en/")
126126

127-
expect(page.locator('text=Page name "Category/de/test" is in language "de" that does not exist.')).to_be_visible()
127+
expect(page.locator('text=Page name "Category/zz/test" is in language "zz" that does not exist.')).to_be_visible()
128128

129129

130130
def test_category_root(page: Page):

e2e/e2e_namespace_folder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ def test_folder_invalid_file_in_namespace(page: Page):
6868

6969
def test_folder_invalid_language(page: Page):
7070
"""Opening a folder in a language that doesn't exist."""
71-
page.goto("http://localhost:8080/Folder/Page/de/")
71+
page.goto("http://localhost:8080/Folder/Page/zz/")
7272

7373
expect(
74-
page.locator('text=Page name "Folder/Page/de/Main Page" is in language "de" that does not exist.')
74+
page.locator('text=Page name "Folder/Page/zz/Main Page" is in language "zz" that does not exist.')
7575
).to_be_visible()
7676

7777

e2e/e2e_namespace_template.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ def test_template_edit_invalid_language(page: Page, login):
180180
edit.click()
181181
page.wait_for_url("/edit/Template/en/")
182182

183-
page.locator("[name=page]").fill("Template/de/test")
183+
page.locator("[name=page]").fill("Template/zz/test")
184184
page.locator("[name=content]").fill("Some text")
185185
with page.expect_navigation():
186186
page.locator("[name=save]").click()
187187
page.wait_for_url("/edit/Template/en/")
188188

189-
expect(page.locator('text=Page name "Template/de/test" is in language "de" that does not exist.')).to_be_visible()
189+
expect(page.locator('text=Page name "Template/zz/test" is in language "zz" that does not exist.')).to_be_visible()
190190

191191

192192
def test_template_linked_category(page: Page):

e2e/e2e_sitemap.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33

44
def test_sitemap_page(page: Page):
55
"""Check if the sitemap is being generated correctly."""
6-
page.goto("http://localhost:8080/sitemap.xml")
6+
page.goto("view-source:http://localhost:8080/sitemap.xml")
77
expect(page.locator("text=http://www.sitemaps.org/schemas/sitemap/0.9")).to_be_visible()
88
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page</loc>")).to_be_visible()
99
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page2</loc>")).to_be_visible()
10+
expect(page.locator("text=http://localhost:8080/de/").nth(1)).to_be_visible()
1011

1112

1213
def test_sitemap_page_cached(page: Page):
1314
"""Second call loads it from the cache. Ensure it is still correct."""
14-
page.goto("http://localhost:8080/sitemap.xml")
15+
page.goto("view-source:http://localhost:8080/sitemap.xml")
1516
expect(page.locator("text=http://www.sitemaps.org/schemas/sitemap/0.9")).to_be_visible()
1617
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page</loc>")).to_be_visible()
1718
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page2</loc>")).to_be_visible()
19+
expect(page.locator("text=http://localhost:8080/de/").nth(1)).to_be_visible()
1820

1921

2022
def test_sitemap_invalidate(page: Page, login):
@@ -37,8 +39,9 @@ def test_sitemap_invalidate(page: Page, login):
3739

3840
def test_sitemap_page_after_change(page: Page):
3941
"""Check if the new page ended up in the sitemap."""
40-
page.goto("http://localhost:8080/sitemap.xml")
42+
page.goto("view-source:http://localhost:8080/sitemap.xml")
4143
expect(page.locator("text=http://www.sitemaps.org/schemas/sitemap/0.9")).to_be_visible()
4244
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page</loc>")).to_be_visible()
4345
expect(page.locator("text=<loc>http://localhost:8080/en/Main%20Page2</loc>")).to_be_visible()
46+
expect(page.locator("text=http://localhost:8080/de/").nth(1)).to_be_visible()
4447
expect(page.locator("text=<loc>http://localhost:8080/en/Sitemap%20Change</loc>")).to_be_visible()

e2e/e2e_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_source_page(page: Page):
1515
page.locator("text=You do not have permission to edit this page, because you are not logged in.")
1616
).to_be_visible()
1717
expect(page.locator("textarea")).to_have_text(
18-
"My Third Edit\n\n[[Category:en/MyPages]]\n{{en/Summary}}\n{{Page:en/Empty}}"
18+
"[[Translation:en/Main Page]]\nMy Third Edit\n\n[[Category:en/MyPages]]\n{{en/Summary}}\n{{Page:en/Empty}}"
1919
)
2020
expect(page.locator("text=My Third Edit")).to_be_visible()
2121

0 commit comments

Comments
 (0)