fix: test dashboard homepage and fix template vars in dash home

This commit is contained in:
Aravinth Manivannan 2022-12-03 15:31:40 +05:30
parent 6660602ab6
commit 330e835094
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 87 additions and 82 deletions

View file

@ -59,6 +59,7 @@ impl Home {
let ctx = RefCell::new(context(settings));
if let Some(sites) = sites {
ctx.borrow_mut().insert(PAYLOAD_KEY, sites);
println!("{:#?}", sites)
}
Self { ctx }
}
@ -101,3 +102,52 @@ pub async fn get_home(ctx: AppCtx, id: Identity) -> PageResult<impl Responder, H
pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(get_home);
}
#[cfg(test)]
mod tests {
use super::*;
use actix_web::http::StatusCode;
use actix_web::test;
use crate::ctx::ArcCtx;
use crate::tests;
use crate::*;
use super::PAGES;
#[actix_rt::test]
async fn postgres_dash_home_works() {
let (_, ctx) = tests::get_ctx().await;
dashboard_home_works(ctx.clone()).await;
}
async fn dashboard_home_works(ctx: ArcCtx) {
const NAME: &str = "testdashuser";
const EMAIL: &str = "testdashuser@foo.com";
const PASSWORD: &str = "longpassword";
let _ = ctx.delete_user(NAME, PASSWORD).await;
let (_, signin_resp) = ctx.register_and_signin(NAME, EMAIL, PASSWORD).await;
let cookies = get_cookie!(signin_resp);
let app = get_app!(ctx).await;
let resp = get_request!(&app, PAGES.dash.home, cookies.clone());
assert_eq!(resp.status(), StatusCode::OK);
let res = String::from_utf8(test::read_body(resp).await.to_vec()).unwrap();
println!("before adding site: {res}");
assert!(res.contains("Nothing to show"));
let page = ctx.add_test_site(NAME.into()).await;
let resp = get_request!(&app, PAGES.dash.home, cookies.clone());
assert_eq!(resp.status(), StatusCode::OK);
let res = String::from_utf8(test::read_body(resp).await.to_vec()).unwrap();
println!("after adding site: {res}");
assert!(!res.contains("Nothing here"));
assert!(res.contains(&page.domain));
assert!(res.contains(&page.repo));
let _ = ctx.delete_user(NAME, PASSWORD).await;
}
}

View file

@ -1,87 +1,38 @@
{% extends 'base' %}
{% block title %} Add Site{% endblock title %}
{% block nav %} {% include "auth_nav" %} {% endblock nav %}
{% block main %}
{% extends 'base' %}{% block title %} Add Site{% endblock title %} {% block nav
%} {% include "auth_nav" %} {% endblock nav %} {% block main %}
<main class="sites__main">
<div class="sites__collection">
<div class="sites__actions">
<a class="sites__actions__new-site" href="{{ page.dash.site.add }}">
<button>Add new site</button>
</a>
</div>
{% for site in payload %}
<a href="/sites/mcaptcha.org" class="site__container">
<div class="site__info--head">
<img
class="site__container--preview"
src="https://mcaptcha.org/favicon.ico"
/>
<div class="site__info--column">
<p href="https://mcaptcha.org">
<b>{{ site.info.hostname }}</b>
</p>
<p>Deploys from {{ site.info.source_url }}</p>
</div>
</div>
{% if site.last_update %}
<div class="site__info--tail">
<p>Last update {{ site.last_update.time }}</p>
</div>
{% endif %}
</a>
{% endfor %}
</div>
<div class="sites__collection">
<div class="sites__actions">
<a class="sites__actions__new-site" href="{{ page.dash.site.add }}">
<button>Add New Site</button>
</a>
</div>
{% if payload|length > 0 %}
{% for deployment in payload %}
<a href="/sites/view/{{ deployment.site.hostname }}" class="site__container">
<div class="site__info--head">
<img
class="site__container--preview"
src="{{ deployment.site.hostname }}/favicon.ico"
alt="{{ deployment.site.hostname }}'s favicon"
/>
<div class="site__info--column">
<p><b>{{ deployment.site.hostname }}</b></p>
<p>Deploys from {{ deployment.site.repo_url }}</p>
</div>
</div>
{% if deployment.last_update %}
<div class="site__info--tail">
<p>Last update {{ deployment.last_update.time }}</p>
</div>
{% endif %}
</a>
{% endfor %}
{% else %}
<p class="sites__banner">Nothing to show, click <a href="{{page.dash.site.add}}">here</a> to get started!</p>
{% endif %}
</div>
</main>
{% endblock main %}
<!--
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="{{ assets.css }}" />
<title>LibrePages</title>
</head>
<body class="auth__body">
<header>
{% include "auth_nav" %}
</header>
<main>
<div class="sites__collection">
<div class="sites__actions">
<a class="sites__actions__new-site" href="{{ page.dash.site.add }}">
<button>Add new site</button>
</a>
</div>
{% for site in payload %}
<a href="/sites/mcaptcha.org" class="site__container">
<div class="site__info--head">
<img
class="site__container--preview"
src="https://mcaptcha.org/favicon.ico"
/>
<div class="site__info--column">
<p href="https://mcaptcha.org"><b>{{ site.info.hostname }}</b></p>
<p>Deploys from {{ site.info.source_url }}</p>
</div>
</div>
{% if site.last_update %}
<div class="site__info--tail">
<p>Last update {{ site.last_update.time }}</p>
</div>
{% endif %}
</a>
{% endfor %}
</div>
</main>
{% include "footer" %}
</body>
</html>
-->

View file

@ -79,3 +79,7 @@
height: 50px;
border-radius: 50%;
}
.sites__banner {
text-align: center;
}