Skip to content

Commit 8e644e3

Browse files
committed
Ocultados los apartados de back y front hasta fecha prevista
1 parent 449e470 commit 8e644e3

File tree

15 files changed

+400
-78
lines changed

15 files changed

+400
-78
lines changed

src/components/ComingSoon.astro

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
const { section, date } = Astro.props;
3+
---
4+
5+
<section style="text-align:center; padding:4rem;">
6+
<h1>Sección no disponible todavía</h1>
7+
<p>La sección <strong>{section}</strong> estará disponible el {date.toLocaleDateString("es-ES")}.</p>
8+
<a href="/astro-proyect/">Volver al inicio</a>
9+
</section>

src/components/Navbar.astro

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,24 @@ const { posts } = Astro.props;
4747
const res = await fetch('/astro-proyect/search-index.json');
4848
const data = await res.json();
4949

50-
const sectionPosts = Object.entries(sectionMap).map(([category, section]) => ({
51-
title: category,
52-
description: `Ver todos los artículos de ${category}`,
53-
url: `/astro-proyect/${section}/${category}/`
54-
}));
50+
const today = new Date();
51+
const releaseBackEnd = new Date('2025-12-14');
52+
const releaseFrontEnd = new Date('2026-02-22');
53+
54+
const showBackend = today >= releaseBackEnd;
55+
const showFrontend = today >= releaseFrontEnd;
56+
57+
const sectionPosts = Object.entries(sectionMap)
58+
.filter(([category, section]) => {
59+
if (section === 'backend' && !showBackend) return false;
60+
if (section === 'frontend' && !showFrontend) return false;
61+
return true;
62+
})
63+
.map(([category, section]) => ({
64+
title: category,
65+
description: `Ver todos los artículos de ${category}`,
66+
url: `/astro-proyect/${section}/${category}/`
67+
}));
5568

5669
const contentPosts = data.map(post => ({
5770
title: post.title,

src/content/react/Jest.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Jest
3+
description: ""
4+
pubDate: '01/03/2024'
5+
collection: nodejs
6+
---
7+
8+
## ¿Qué es Jest?
9+
10+
<a href="https://jestjs.io/" target="_blank">Jest</a> es un framework de pruebas en JavaScript desarrollado por Facebook. Es ampliamente utilizado para probar aplicaciones escritas en **JavaScript** y **React**. Jest es ideal para realizar pruebas unitarias, pruebas de integración, y pruebas de instantáneas (snapshots).
11+
12+
## Características Principales
13+
14+
- **Sencillo**: Configuración fácil, con una API intuitiva.
15+
- **Aislado**: Los tests son ejecutados en entornos separados para evitar interferencias.
16+
- **Cobertura de Código**: Genera informes de cobertura sin configuración adicional.
17+
- **Pruebas Asíncronas**: Soporta promesas, async/await y callbacks.
18+
- **Mocks**: Mocking de módulos, funciones y temporizadores.
19+
- **Snapshots**: Verifica que la interfaz de usuario o los datos de salida no cambien de forma inesperada.
20+
21+
## Instalación
22+
23+
Puedes instalar Jest fácilmente a través de npm o yarn.
24+
25+
```bash
26+
# usando npm
27+
npm install --save-dev jest
28+
29+
# usando yarn
30+
yarn add --dev jest
31+
```
32+
33+
## Configuración
34+
35+
Por defecto, Jest no necesita configuración. Si quieres personalizar la configuración, puedes añadir un archivo `jest.config.js` o configurarlo en el campo `jest` en `package.json`.
36+
37+
```json
38+
{
39+
"scripts": {
40+
"test": "jest"
41+
}
42+
}
43+
```
44+
45+
Si ejecutas `npm test`, Jest buscará archivos con las siguientes extensiones para ejecutar las pruebas:
46+
47+
* `.js`
48+
* `.jsx`
49+
* `.ts`
50+
* `.tsx`
51+
52+
## Primer Test
53+
54+
Crea un archivo de prueba, por ejemplo `sum.test.js`:
55+
56+
57+
```javascript
58+
const sum = (a, b) => a + b;
59+
60+
test('suma de 1 + 2 debe ser igual a 3', () => {
61+
expect(sum(1, 2)).toBe(3);
62+
});
63+
```
64+
65+
Luego ejecuta:
66+
67+
```bash
68+
npm test
69+
```
70+
71+
### Explicación
72+
73+
* **test(nombre, callback)**: Define un caso de prueba. `nombre` describe la prueba, y el `callback` contiene la lógica de la prueba.
74+
* **expect(valor)**: Es una aserción. Se espera que el valor cumpla con una condición, que en este caso es `.toBe(3)`.
75+
76+
## Pruebas Asíncronas
77+
78+
Jest maneja pruebas asíncronas fácilmente con promesas o `async/await`.
79+
80+
### Usando Promesas
81+
82+
```javascript
83+
test('el fetch de datos debe tener un nombre de usuario', () => {
84+
return fetchUser().then(data => {
85+
expect(data.username).toBeDefined();
86+
});
87+
});
88+
```
89+
90+
### Usando `async/await`
91+
92+
```javascript
93+
test('el fetch de datos debe tener un nombre de usuario', async () => {
94+
const data = await fetchUser();
95+
expect(data.username).toBeDefined();
96+
});
97+
```
98+
99+
## Mocking en Jest
100+
101+
Jest permite hacer "mock" de funciones, módulos y temporizadores. Esto es útil para aislar la lógica de las pruebas.
102+
103+
### Mock de Funciones
104+
105+
```javascript
106+
const myMock = jest.fn();
107+
myMock('foo');
108+
109+
expect(myMock).toHaveBeenCalledWith('foo');
110+
```
111+
112+
### Mock de Módulos
113+
114+
Si deseas simular un módulo completo:
115+
116+
```javascript
117+
jest.mock('./miModulo');
118+
const miModulo = require('./miModulo');
119+
120+
miModulo.miFuncion.mockReturnValue('valor simulado');
121+
```
122+
123+
## Pruebas de Instantáneas (Snapshots)
124+
125+
Las pruebas de instantáneas permiten capturar la salida de una función o componente y compararla con ejecuciones futuras.
126+
127+
### Creación de un Snapshot
128+
129+
```javascript
130+
test('componente renderiza correctamente', () => {
131+
const tree = renderer.create(<MyComponent />).toJSON();
132+
expect(tree).toMatchSnapshot();
133+
});
134+
```
135+
Esto generará un archivo de snapshot que contendrá la representación de la interfaz en ese momento. Si la salida cambia en futuras ejecuciones, Jest te advertirá.
136+
137+
## Cobertura de Código
138+
139+
Para generar un informe de cobertura de código:
140+
141+
```bash
142+
jest --coverage
143+
```
144+
Esto generará un informe detallado en la consola y también en un formato HTML dentro de la carpeta `coverage`.
145+
146+
## Configuración Avanzada
147+
148+
### Configuración del archivo jest.config.js
149+
150+
```javascript
151+
module.exports = {
152+
verbose: true,
153+
collectCoverage: true,
154+
testEnvironment: 'node',
155+
coverageDirectory: 'coverage',
156+
};
157+
```
158+
159+
### Otros comandos útiles
160+
161+
* `jest --watch`: Ejecuta pruebas continuamente mientras desarrollas.
162+
* `jest --bail`: Detiene la ejecución en la primera prueba fallida.
163+
* `jest --runInBand`: Ejecuta las pruebas en serie en lugar de en paralelo.
164+
165+
## Conclusión
166+
167+
Jest es una herramienta poderosa y versátil para realizar pruebas en proyectos de JavaScript. Con características como pruebas de instantáneas, cobertura de código y soporte para pruebas asíncronas, es una excelente opción para proyectos grandes y pequeños.
168+
169+
## Recursos adicionales
170+
171+
* <a href="https://jestjs.io/docs/getting-started" target="_blank">Documentación Oficial de Jest</a>
172+
* <a href="https://jestjs.io/docs/mock-functions" target="_blank">Guía de Mocking en Jest</a>

src/layouts/BlogPost.astro

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22
import Layout from './Layout.astro';
33
44
type Props = {
5-
title: string;
5+
title: string;
6+
hideBreadcrumbs?: boolean;
7+
isPlaceholder?: boolean;
68
};
79
8-
const { title } = Astro.props as Props;
10+
const { title, hideBreadcrumbs = false, isPlaceholder = false } = Astro.props as Props;
911
1012
---
11-
<Layout title="The Bridge">
12-
<article>
13-
<div class="prose">
14-
<div class="title pageTitle">
15-
<h1>{title}</h1>
16-
<img src="/astro-proyect/images/filled_icon.svg" alt="logo_programacion" class="logo_codigo">
17-
</div>
18-
<slot /> <!-- Slot para contenido dinámico -->
19-
</div>
20-
</article>
13+
<Layout title="The Bridge" hideBreadcrumbs={hideBreadcrumbs}>
14+
<article>
15+
16+
<div class="prose">
17+
{isPlaceholder ? (
18+
<section style="text-align:center; padding:4rem;">
19+
<h1 class="text-5xl font-bold text-red-500">{title}</h1>
20+
<slot />
21+
</section>
22+
) : (
23+
<div class="title pageTitle">
24+
<h1>{title}</h1>
25+
<img src="/astro-proyect/images/filled_icon.svg" alt="logo_programacion" class="logo_codigo">
26+
</div>
27+
)}
28+
</div>
29+
{!isPlaceholder && <slot />}
30+
</article>
2131
</Layout>

src/layouts/Layout.astro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ const isRoot = currentPath === '/' || currentPath === '/astro-proyect';
2929
3030
interface Props {
3131
title: string;
32+
hideBreadcrumbs?: boolean;
3233
}
3334
34-
const { title } = Astro.props;
35+
const { title, hideBreadcrumbs = false } = Astro.props;
3536
---
3637

3738
<!doctype html>
@@ -50,7 +51,7 @@ const { title } = Astro.props;
5051
<Navbar posts={allPosts}/>
5152
</header>
5253
<div class="back-breadcrumbs">
53-
{isRoot ? "" :
54+
{isRoot && hideBreadcrumbs ? (
5455
<Breadcrumbs linkTextFormat="capitalized" separatorAriaHidden={false}>
5556
<svg
5657
slot="separator"
@@ -67,6 +68,7 @@ const { title } = Astro.props;
6768
<polyline points="9 18 15 12 9 6"></polyline>
6869
</svg>
6970
</Breadcrumbs>
71+
) : null
7072
}
7173
</div>
7274
<main transition:animate="slide">

src/layouts/ProtectedLayout.astro

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
import Layout from "./Layout.astro";
3+
4+
const { section } = Astro.props;
5+
6+
const today = new Date();
7+
const releaseBackEnd = new Date('2025-12-14');
8+
const releaseFrontEnd = new Date('2026-02-22');
9+
10+
let available = true;
11+
if (section === 'backend' && today < releaseBackEnd) available = false;
12+
if (section === 'frontend' && today < releaseFrontEnd) available = false;
13+
---
14+
15+
{ available ? (
16+
<Layout title="The Bridge">
17+
<slot />
18+
</Layout>
19+
) : (
20+
<Layout title="The Bridge">
21+
<section style="text-align:center; padding:4rem;">
22+
<h1>Sección no disponible todavía</h1>
23+
<p>
24+
La sección <strong>{section}</strong> estará dispomnible el {" "}
25+
{section === 'backend'
26+
? releaseBackEnd.toLocaleDateString("es-ES")
27+
: releaseFrontEnd.toLocaleDateString("es-ES")}
28+
</p>
29+
<a href="/astro-proyect/">Volver al inicio</a>
30+
</section>
31+
</Layout>
32+
)}

src/pages/backend/bases_de_datos/[slug].astro

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@ export async function getStaticPaths() {
1212
1313
const post = Astro.props;
1414
const { Content } = await post.render();
15+
16+
const today = new Date();
17+
const releaseBackend = new Date('2025-12-14');
18+
const available = today >= releaseBackend;
19+
const title = 'Sección no disponible todavía';
20+
const message = `La sección Backend estará disponible el ${releaseBackend.toLocaleDateString('es-ES')}.`;
1521
---
1622

17-
<BlogPost {...post.data}>
18-
<Content />
19-
</BlogPost>
23+
{available ? (
24+
<BlogPost {...post.data}>
25+
<Content />
26+
</BlogPost>
27+
) : (
28+
<BlogPost title={title} hideBreadcrumbs={true} isPlaceholder={true}>
29+
<section style="text-align:center; padding:4rem;">
30+
<p>{message}</p>
31+
<a href="/astro-proyect/">
32+
Volver al inicio
33+
</a>
34+
</section>
35+
</BlogPost>
36+
)}
37+
38+

src/pages/backend/bases_de_datos/index.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Layout from "../../../layouts/Layout.astro";
2+
import ProtectedLayout from "../../../layouts/ProtectedLayout.astro";
33
import Card from "../../../components/Card.astro";
44
import { getCollection } from "astro:content";
55
@@ -8,7 +8,7 @@ const posts = (await getCollection('bases_de_datos')).sort(
88
);
99
---
1010

11-
<Layout title="The Bridge">
11+
<ProtectedLayout section="backend">
1212
<section>
1313
<div class="pageTitle">
1414
<h1>Bases de datos</h1>
@@ -26,4 +26,4 @@ const posts = (await getCollection('bases_de_datos')).sort(
2626
}
2727
</ul>
2828
</section>
29-
</Layout>
29+
</ProtectedLayout>

0 commit comments

Comments
 (0)