Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions resources/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["*.ts"]
}
13 changes: 7 additions & 6 deletions tests/Unit/CommitImages.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { renderToStaticMarkup } from 'react-dom/server';
import { test } from 'vite-plus/test';
import {
CommitImages,
replaceFailedImage,
Expand Down Expand Up @@ -37,6 +37,7 @@ const commit: Commit = {
has_sponsors_listing: false,
has_github_account: true,
lane: 0,
timezone: null,
created_at: '2026-10-16T10:00:00Z',
updated_at: '2026-10-16T10:00:00Z',
},
Expand All @@ -51,15 +52,15 @@ const commit: Commit = {
],
};

void test('keeps the uploaded image until it fails to load', () => {
test('keeps the uploaded image until it fails to load', () => {
assert.ok(
renderToStaticMarkup(<CommitImages commit={commit} />).includes(
'src="/images/missing.webp"',
),
);
});

void test('shows the short image hash instead of the alt text while the image loads', () => {
test('shows the short image hash instead of the alt text while the image loads', () => {
const markup = renderToStaticMarkup(<CommitImages commit={commit} />);
const placeholder = markup.match(
/<div aria-hidden="true" data-test="commit-image-loading".*?<\/div><\/div><\/div>/,
Expand All @@ -69,7 +70,7 @@ void test('shows the short image hash instead of the alt text while the image lo
assert.equal(placeholder[0].replace(/<[^>]+>/g, ''), 'commitb8a0c3d');
});

void test('scrambles each hash differently, locking it in from left to right, then rolls again', () => {
test('scrambles each hash differently, locking it in from left to right, then rolls again', () => {
const lockedAt = (frame: number) =>
scrambleHash('9f3a6c1', frame)
.filter(({ isLocked }) => isLocked)
Expand Down Expand Up @@ -100,7 +101,7 @@ void test('scrambles each hash differently, locking it in from left to right, th
);
});

void test('replaces a failed image with the site logo without retrying the fallback', () => {
test('replaces a failed image with the site logo without retrying the fallback', () => {
let replacements = 0;
let source = '/images/missing.webp';
const target = {
Expand All @@ -121,6 +122,6 @@ void test('replaces a failed image with the site logo without retrying the fallb
assert.equal(replacements, 1);
});

void test('renders nothing when there are no uploaded images', () => {
test('renders nothing when there are no uploaded images', () => {
assert.equal(CommitImages({ commit: { ...commit, images: [] } }), null);
});
4 changes: 2 additions & 2 deletions tests/Unit/CommitQuoteButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import { test } from 'vite-plus/test';
import { CommitQuoteButton } from '../../resources/js/components/commit-quote-button';
import { TooltipProvider } from '../../resources/js/components/ui/tooltip';
import type { Commit } from '../../resources/js/types';
Expand All @@ -15,7 +15,7 @@ const commit = {
} as Commit;

for (const user of [null, { id: 'viewer' }]) {
void test(`renders the quote control for ${user === null ? 'guests' : 'signed-in readers'}`, async () => {
test(`renders the quote control for ${user === null ? 'guests' : 'signed-in readers'}`, async () => {
const result = await createInertiaApp<{
auth: { user: { id: string } | null };
}>({
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/CommitStarButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import { test } from 'vite-plus/test';
import { CommitStarButton } from '../../resources/js/components/commit-star-button';
import { TooltipProvider } from '../../resources/js/components/ui/tooltip';
import type { Commit } from '../../resources/js/types';
Expand Down Expand Up @@ -54,7 +54,7 @@ async function render(
}

for (const status of ['approved', 'pending', 'rejected'] as const) {
void test(`authors see only their ${status} commit's star count`, async () => {
test(`authors see only their ${status} commit's star count`, async () => {
const body = await render({ id: 'author' }, { status });

assert.match(body, /data-test="star-count-readonly"/);
Expand All @@ -63,15 +63,15 @@ for (const status of ['approved', 'pending', 'rejected'] as const) {
});
}

void test('authors see an accessible empty star count', async () => {
test('authors see an accessible empty star count', async () => {
const body = await render({ id: 'author' }, { stars_count: 0 });

assert.match(body, /aria-label="No stars yet"/);
assert.doesNotMatch(body, /<button\b/);
});

for (const user of [null, { id: 'viewer' }]) {
void test(`approved commits keep the star control for ${user === null ? 'guests' : 'other readers'}`, async () => {
test(`approved commits keep the star control for ${user === null ? 'guests' : 'other readers'}`, async () => {
const body = await render(user);

assert.match(body, /data-test="star-commit-button"/);
Expand All @@ -82,7 +82,7 @@ for (const user of [null, { id: 'viewer' }]) {
}

for (const status of ['pending', 'rejected'] as const) {
void test(`other readers cannot star a ${status} commit`, async () => {
test(`other readers cannot star a ${status} commit`, async () => {
const body = await render({ id: 'viewer' }, { status });

assert.doesNotMatch(
Expand All @@ -93,7 +93,7 @@ for (const status of ['pending', 'rejected'] as const) {
}

for (const status of ['approved', 'pending', 'rejected'] as const) {
void test(`authors see their ${status} reply's read-only star count`, async () => {
test(`authors see their ${status} reply's read-only star count`, async () => {
const body = await render(
{ id: 'author' },
{ status, parent_id: 'parent' },
Expand Down
13 changes: 10 additions & 3 deletions tests/Unit/CommitThread.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="node" />

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { createInertiaApp } from '@inertiajs/react';
import { renderToString } from 'react-dom/server';
import { test } from 'vite-plus/test';
import {
ThreadActions,
ThreadReplies,
Expand All @@ -21,8 +21,15 @@ const reply = (id: string): Commit =>
created_at: new Date().toISOString(),
status: 'approved',
body_segments: [{ type: 'text', text: `Visible reply ${id}` }],
preview_segments: null,
replies_count: 0,
user: { id: 'author', name: 'Author', username: 'author', lane: 1, timezone: null },
user: {
id: 'author',
name: 'Author',
username: 'author',
lane: 1,
timezone: null,
},
}) as Commit;

async function renderThread(count: number) {
Expand Down Expand Up @@ -70,7 +77,7 @@ async function renderThread(count: number) {
}

for (const count of [0, 1, 2, 5]) {
void test(`shows ${Math.min(count, 1)} replies immediately out of ${count}`, async () => {
test(`shows ${Math.min(count, 1)} replies immediately out of ${count}`, async () => {
const html = await renderThread(count);
assert.equal(
(html.match(/Visible reply /g) ?? []).length,
Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/ComposerPreview.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// <reference types="node" />
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { App } from '@inertiajs/react';
import type { ComponentProps, KeyboardEvent, ReactElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { test } from 'vite-plus/test';
import { CommitBody } from '../../resources/js/components/commit-body';
import { CommitComposer } from '../../resources/js/components/commit-composer';
import { revokeObjectUrls } from '../../resources/js/components/commit-image-picker';
Expand Down Expand Up @@ -75,7 +75,7 @@ function previewFor(options: {

for (const modifier of ['ctrlKey', 'metaKey'] as const) {
for (const shiftKey of [false, true]) {
void test(`${modifier} + ${shiftKey ? 'Shift + ' : ''}Enter publishes from preview`, () => {
test(`${modifier} + ${shiftKey ? 'Shift + ' : ''}Enter publishes from preview`, () => {
let submitted = 0;
let prevented = 0;
const preview = previewFor({ isSubmittable: true });
Expand All @@ -96,7 +96,7 @@ for (const modifier of ['ctrlKey', 'metaKey'] as const) {
}
}

void test('does not publish an incomplete draft from preview', () => {
test('does not publish an incomplete draft from preview', () => {
previewFor({ isSubmittable: false }).onPreviewKeyDown({
key: 'Enter',
ctrlKey: true,
Expand Down Expand Up @@ -165,7 +165,7 @@ function renderComposer(body: string): string {
}

for (const count of [1, 2, 3, 3850]) {
void test(`counts ${count} emoji as Unicode characters in the preview composer`, () => {
test(`counts ${count} emoji as Unicode characters in the preview composer`, () => {
const markup = renderComposer('🚀'.repeat(count));
const submit = markup.match(
/<button[^>]*data-test="create-commit-button"[^>]*>/,
Expand All @@ -181,7 +181,7 @@ for (const count of [1, 2, 3, 3850]) {
});
}

void test('previews the chosen link card instead of the first link in the body', () => {
test('previews the chosen link card instead of the first link in the body', () => {
const preview = previewFor({
body: 'https://first.example.com https://second.example.com',
isSubmittable: true,
Expand All @@ -200,7 +200,7 @@ void test('previews the chosen link card instead of the first link in the body',
assert.ok(!card.includes('first.example.com'));
});

void test('omits the preview card when the author chooses no card', () => {
test('omits the preview card when the author chooses no card', () => {
const preview = previewFor({
body: 'https://first.example.com',
isSubmittable: true,
Expand All @@ -213,7 +213,7 @@ void test('omits the preview card when the author chooses no card', () => {
assert.ok(!markup.includes('data-test="link-card-preview"'));
});

void test('retains the link card picker and scheduling beside preview', () => {
test('retains the link card picker and scheduling beside preview', () => {
const markup = renderComposer(
'https://first.example.com https://second.example.com',
);
Expand All @@ -232,7 +232,7 @@ void test('retains the link card picker and scheduling beside preview', () => {

const secret = 'ghp_' + 'Ab3dEf6hIj9kLm2nOp5qRs8tUv1wXy4zABCD';

void test('keeps the sensitive text warning beside preview', () => {
test('keeps the sensitive text warning beside preview', () => {
const markup = renderComposer(secret);

assert.equal(
Expand All @@ -244,14 +244,14 @@ void test('keeps the sensitive text warning beside preview', () => {
assert.ok(!markup.includes('Publish possible secrets?'));
});

void test('ordinary drafts retain preview without a sensitive text warning', () => {
test('ordinary drafts retain preview without a sensitive text warning', () => {
const markup = renderComposer('Shipped a small fix');
assert.ok(markup.includes('data-test="preview-toggle"'));
assert.ok(!markup.includes('aria-label="Sensitive text warning"'));
});

for (const isAdmin of [false, true]) {
void test(`previews a poll draft as ${isAdmin ? 'an open' : 'a pending'} poll`, () => {
test(`previews a poll draft as ${isAdmin ? 'an open' : 'a pending'} poll`, () => {
const markup = renderPage(
<ComposerPollPreview
poll={{
Expand All @@ -275,7 +275,7 @@ for (const isAdmin of [false, true]) {
});
}

void test('previews attached image descriptions without a published photo link', () => {
test('previews attached image descriptions without a published photo link', () => {
const images = [
new File(['first'], 'first.png', { type: 'image/png' }),
new File(['second'], 'second.png', { type: 'image/png' }),
Expand All @@ -302,7 +302,7 @@ void test('previews attached image descriptions without a published photo link',

for (const pasteisMode of [false, true]) {
for (const isStatic of [false, true]) {
void test(`renders pastel words as ${pasteisMode ? 'emoji' : 'text'} in ${isStatic ? 'excerpts' : 'commit previews'}`, () => {
test(`renders pastel words as ${pasteisMode ? 'emoji' : 'text'} in ${isStatic ? 'excerpts' : 'commit previews'}`, () => {
const body =
'pastel, pasteis! (pastéis) PASTEL PASTEIS PASTÉIS :rocket:';
const preview = previewFor({ body, isSubmittable: true });
Expand Down Expand Up @@ -349,7 +349,7 @@ for (const pasteisMode of [false, true]) {
}
});

void test(`preserves code, URLs, usernames and larger words with mode ${pasteisMode ? 'on' : 'off'} in ${isStatic ? 'excerpts' : 'commits'}`, () => {
test(`preserves code, URLs, usernames and larger words with mode ${pasteisMode ? 'on' : 'off'} in ${isStatic ? 'excerpts' : 'commits'}`, () => {
const preview = previewFor({
body: 'pastel https://pasteis.com/pastel @pastel pastels pastelaria épastel pastelé pastel_1\n`pasteis`\n```text\npastéis\n```',
isSubmittable: true,
Expand Down
Loading
Loading