| 1 | use std::time::Duration; |
| 2 | |
| 3 | use crate::common::boot_forge; |
| 4 | use reqwest::header::ACCEPT_LANGUAGE; |
| 5 | |
| 6 | #[tokio::test] |
| 7 | async fn snippets_page_follows_the_browser_language() { |
| 8 | let root = tempfile::tempdir().expect("temp dir"); |
| 9 | let dir = root.path().to_path_buf(); |
| 10 | let (_server, ports) = boot_forge(&dir, "", &[&["create-user", "tahinli"]]).await; |
| 11 | |
| 12 | let client = reqwest::Client::builder() |
| 13 | .timeout(Duration::from_secs(60)) |
| 14 | .build() |
| 15 | .expect("http client"); |
| 16 | let base = format!("http://127.0.0.1:{}", ports.http); |
| 17 | |
| 18 | let turkish = client |
| 19 | .get(format!("{base}/snippets")) |
| 20 | .header(ACCEPT_LANGUAGE, "tr-TR,tr;q=0.9,en;q=0.8") |
| 21 | .send() |
| 22 | .await |
| 23 | .expect("GET /snippets (tr)"); |
| 24 | assert_eq!(turkish.status().as_u16(), 200); |
| 25 | let body = turkish.text().await.expect("read body"); |
| 26 | assert!(body.contains("<html lang=\"tr\""), "html lang is tr"); |
| 27 | assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading"); |
| 28 | assert!( |
| 29 | body.contains("Gösterilecek parçacık yok."), |
| 30 | "Turkish empty state" |
| 31 | ); |
| 32 | assert!(!body.contains("No snippets to show."), "no English left"); |
| 33 | |
| 34 | let english = client |
| 35 | .get(format!("{base}/snippets")) |
| 36 | .header(ACCEPT_LANGUAGE, "en-US,en;q=0.9") |
| 37 | .send() |
| 38 | .await |
| 39 | .expect("GET /snippets (en)"); |
| 40 | let body = english.text().await.expect("read body"); |
| 41 | assert!(body.contains("<h1>Snippets</h1>"), "English heading"); |
| 42 | assert!(body.contains("No snippets to show."), "English empty state"); |
| 43 | } |