Skip to content

Commit

Permalink
add card_grid and support tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Gugger committed Jun 11, 2024
1 parent 5bbe17f commit 62e4210
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/basic/templates/support.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="support_content" support_block">
<div id="support_content">
<article class="media">
<div class="media-content">
<div class="content">
Expand Down
2 changes: 1 addition & 1 deletion src/templates/bulma/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

<div class="navbar-end">
{%if support_path %}
<a href="#" class="navbar-item" onclick="toggle_hidden('support')"><i class="fa-solid fa-question"></i></a>
<a id="support_nav" href="#" class="navbar-item" onclick="toggle_hidden('support')"><i class="fa-solid fa-question"></i></a>
{% endif %}

{% if enable_auth %}
Expand Down
19 changes: 19 additions & 0 deletions tests/test_setup/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ pub fn create_actix_admin_builder(
false,
);

let _support_route = admin_builder.add_support_handler("/support", web::get().to(support));
let _card_route = admin_builder.add_custom_handler("card", "/card/{id}", web::get().to(card), false);

let card_grid: Vec<Vec<String>> = vec![
vec!["admin/card/1".to_string(), "admin/card/2".to_string()],
vec!["admin/card/3".to_string()],
];
admin_builder.add_card_grid("Card Grid", "/my_card_grid", card_grid, true);


admin_builder
}

Expand Down Expand Up @@ -198,6 +208,15 @@ async fn edit_post_from_plaintext<E: ActixAdminViewModelTrait>(
.await
}

async fn support() -> Result<HttpResponse, Error> {
let resp = "<div id=\"support_content\">SupportDiv</div>";
Ok(HttpResponse::Ok().content_type("text/html").body(resp))
}

async fn card(id: web::Path<i32>) -> Result<HttpResponse, Error> {
let resp = format!("<div class=\"card-content\">Card{}</div>", id);
Ok(HttpResponse::Ok().content_type("text/html").body(resp))
}
pub trait BodyTest {
fn as_str(&self) -> &str;
}
Expand Down
7 changes: 1 addition & 6 deletions tests/test_setup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ pub use sample_with_tenant_id::Entity as SampleWithTenantId;

#[allow(dead_code)]
pub mod prelude {
pub use super::comment;
pub use super::post;
pub use super::sample_with_tenant_id;
pub use super::Comment;
pub use super::Post;
pub use super::SampleWithTenantId;
pub use super::*;
pub use crate::test_setup::webdriver:: { setup, teardown };
pub use crate::test_setup::helper::{create_actix_admin_builder, setup_db, BodyTest};
}
Expand Down
37 changes: 37 additions & 0 deletions tests/webdriver_cardgrid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use tokio::test as tokio_test;
mod test_setup;
use test_setup::prelude::*;
use tokio;

mod webdriver_tests {
use std::time::Duration;

use super::*;
use fantoccini::Locator;

#[tokio_test]
async fn webdriver_support() -> Result<(), fantoccini::error::CmdError> {
let (server_task, geckodriver, c) = setup(true).await.unwrap();

// Open the index page
c.goto("http://localhost:5555/admin/").await?;
let url = c.current_url().await?;
assert_eq!(url.as_ref(), "http://localhost:5555/admin/");

let html_source = c.source().await?;
assert_eq!(html_source.contains("Card1"), false, "Expected no Card1 on the page");

// Click on support question mark
c.find(Locator::LinkText("Card Grid")).await?.click().await?;
tokio::time::sleep(Duration::from_secs(1)).await;
let url = c.current_url().await?;
assert_eq!(url.as_ref(), "http://localhost:5555/admin/my_card_grid");

let html_source = c.source().await?;
assert!(html_source.contains("Card1"), "Expected Card1 on the page");
assert!(html_source.contains("Card2"), "Expected Card2 on the page");
assert!(html_source.contains("Card3"), "Expected Card3 on the page");

teardown(server_task, geckodriver, c).await
}
}
35 changes: 35 additions & 0 deletions tests/webdriver_support.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use tokio::test as tokio_test;
mod test_setup;
use test_setup::prelude::*;
use tokio;

mod webdriver_tests {
use std::time::Duration;

use super::*;
use fantoccini::Locator;

#[tokio_test]
async fn webdriver_support() -> Result<(), fantoccini::error::CmdError> {
let (server_task, geckodriver, c) = setup(true).await.unwrap();

// Open the index page
c.goto("http://localhost:5555/admin/").await?;
let url = c.current_url().await?;
assert_eq!(url.as_ref(), "http://localhost:5555/admin/");

let html_source = c.source().await?;
assert_eq!(html_source.contains("SupportDiv"), false, "Expected no SupportDiv on the page");

// Click on support question mark
c.find(Locator::Id("support_nav")).await?.click().await?;
tokio::time::sleep(Duration::from_secs(1)).await;
let url = c.current_url().await?;
assert_eq!(url.as_ref(), "http://localhost:5555/admin/#");

let html_source = c.source().await?;
assert!(html_source.contains("SupportDiv"), "Expected SupportDiv on the page");

teardown(server_task, geckodriver, c).await
}
}

0 comments on commit 62e4210

Please sign in to comment.