Refactor code structure for improved readability and maintainability

This commit is contained in:
Shni
2025-10-15 09:54:32 -05:00
parent 0ab59bf6a8
commit 2a67d249fb
8 changed files with 133 additions and 16 deletions

View File

@@ -0,0 +1,52 @@
# Pruebas colaborativas - Dashboard
Objetivo
- Producir una prueba rápida que renderice la plantilla `dashboard` y detecte si aparece la cadena "[object Promise]" en el HTML final.
Ejecutar (solo colaboradores)
- Para evitar ejecuciones accidentales, este script solo se ejecuta si la variable de entorno `COLLAB_TEST` está establecida en `1`.
Ejemplo:
```bash
COLLAB_TEST=1 ./scripts/collab-tests/dashboard/run.sh
```
Salida
- El script imprimirá un JSON con la forma:
- ok: true|false
- length: longitud del HTML renderizado
- foundIndex: índice de "[object Promise]" o -1
Notas
- Este test está pensado para replicar exactamente el pipeline de EJS con `{ async: true }` y los locals mínimos necesarios. Si el test falla en tu entorno de desarrollo, revisa las modificaciones temporales en locales u otras plantillas.
Uso de la fuente BoldPixels.ttf
- Copia de la fuente del repo: `src/server/public/assets/fonts/BoldPixels.ttf`.
- Añade la regla CSS siguiente (por ejemplo en `src/server/public/assets/css/_fonts.css`) y luego importa ese archivo en tu layout o en `styles.css`:
```css
@font-face {
font-family: 'BoldPixels';
src: url('/assets/fonts/BoldPixels.ttf') format('truetype');
font-weight: 700;
font-style: normal;
}
.bold-pixels {
font-family: 'BoldPixels', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
}
```
Ejemplo de uso en EJS:
```html
<h1 class="bold-pixels">Título con fuente BoldPixels</h1>
```

View File

@@ -0,0 +1,35 @@
const ejs = require('ejs');
const path = require('path');
const fs = require('fs');
(async function(){
try{
const cwd = process.cwd();
const viewsDir = path.join(cwd,'src','server','views');
const pageFile = path.join(viewsDir,'pages','dashboard.ejs');
const layoutFile = path.join(viewsDir,'layouts','layout.ejs');
const locals = {
appName:'amayo',
user:{username:'collab-test',id:'1',avatar:''},
guilds:[],
useDashboardNav:false,
version:'test',
selectedGuild:null,
title:'Dashboard collab test',
hideNavbar:false
};
const pageBody = await ejs.renderFile(pageFile, locals, {async:true, views:[viewsDir]});
const html = await ejs.renderFile(layoutFile, {...locals, body: pageBody, dashboardNav:null, navbar:null}, {async:true, views:[viewsDir]});
const found = html.indexOf('[object Promise]') !== -1;
const out = { ok: !found, length: html.length, foundIndex: found ? html.indexOf('[object Promise]') : -1 };
console.log(JSON.stringify(out, null, 2));
if(found) process.exitCode = 2;
}catch(err){
console.error('ERROR', err && err.stack ? err.stack : err);
process.exitCode = 3;
}
})();

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Small wrapper to run the collab test only when COLLAB_TEST=1 is set.
set -euo pipefail
if [ "${COLLAB_TEST:-0}" != "1" ]; then
echo "This test is for collaborators only. Set COLLAB_TEST=1 to run it."
echo "Example: COLLAB_TEST=1 ./scripts/collab-tests/dashboard/run.sh"
exit 1
fi
node ./scripts/collab-tests/dashboard/check_dashboard_render.js