Home / File/ astro-pagination.test.js — astro Source File

astro-pagination.test.js — astro Source File

Architecture documentation for astro-pagination.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  c41fa92e_d473_c53d_01f7_cd3f7993018d["astro-pagination.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  c41fa92e_d473_c53d_01f7_cd3f7993018d --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  c41fa92e_d473_c53d_01f7_cd3f7993018d --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  c41fa92e_d473_c53d_01f7_cd3f7993018d --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  c41fa92e_d473_c53d_01f7_cd3f7993018d --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  c41fa92e_d473_c53d_01f7_cd3f7993018d --> deb87372_5629_35f8_9a54_e755a08f776a
  style c41fa92e_d473_c53d_01f7_cd3f7993018d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Pagination', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/astro-pagination/',
			site: 'https://mysite.dev/',
			base: '/blog',
		});
		await fixture.build();
	});

	it('optional root page', async () => {
		for (const file of [
			'/posts/optional-root-page/index.html',
			'/posts/optional-root-page/2/index.html',
			'/posts/optional-root-page/3/index.html',
		]) {
			assert.ok(await fixture.readFile(file));
		}
	});

	it('named root page', async () => {
		for (const file of [
			'/posts/named-root-page/1/index.html',
			'/posts/named-root-page/2/index.html',
			'/posts/named-root-page/3/index.html',
		]) {
			assert.ok(await fixture.readFile(file));
		}
	});

	it('multiple params', async () => {
		const params = [
			{ color: 'red', p: '1' },
			{ color: 'blue', p: '1' },
			{ color: 'blue', p: '2' },
		];
		await Promise.all(
			params.map(async ({ color, p }) => {
				const html = await fixture.readFile(`/posts/${color}/${p}/index.html`);
				const $ = cheerio.load(html);
				assert.equal($('#page-param').text(), p);
				assert.equal($('#currentPage').text(), p);
				assert.equal($('#filter').text(), color);

				const prevHref = $('#prev').attr('href');
				const nextHref = $('#next').attr('href');

				if (color === 'red') {
					assert.equal(prevHref, undefined);
					assert.equal(nextHref, undefined);
				}
				if (color === 'blue' && p === '1') {
					assert.equal(prevHref, undefined);
					assert.equal(nextHref, '/blog/posts/blue/2');
				}
				if (color === 'blue' && p === '2') {
					assert.equal(prevHref, '/blog/posts/blue/1');
					assert.equal(nextHref, undefined);
				}
			}),
		);
	});
});

Dependencies

Frequently Asked Questions

What does astro-pagination.test.js do?
astro-pagination.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does astro-pagination.test.js depend on?
astro-pagination.test.js imports 5 module(s): cheerio, loadFixture, node:test, strict, test-utils.js.
Where is astro-pagination.test.js in the architecture?
astro-pagination.test.js is located at packages/astro/test/astro-pagination.test.js (domain: IntegrationAdapters, directory: packages/astro/test).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free