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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changelog
- The interns list rejects GitHub usernames that cannot exist.

Every `feat` and `fix` pull request adds a line under `[Unreleased]`, in the
same pull request as the code.
Expand Down
22 changes: 14 additions & 8 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { interns } from '@/data/interns'
import { interns } from '@/data/interns';
import { peopleSoFar } from '@/lib/count';

// Set in .env.local (see .env.example); the fallback keeps the app working without one.
const appName = process.env.NEXT_PUBLIC_APP_NAME || 'Intern playground'
// Set in .env.local (see .env.example); the fallback keeps it working out of the box
const appName = process.env.NEXT_PUBLIC_APP_NAME || 'Intern Playground';

export default function Home() {
const countText = peopleSoFar(interns.length);

return (
<main className="mx-auto flex min-h-screen max-w-2xl flex-col gap-8 px-4 py-16">
<header className="flex flex-col gap-2">
<p className="text-sm font-medium uppercase tracking-wide text-zinc-500">Digital Vantage</p>
<p className="text-sm font-medium uppercase tracking-wider text-zinc-500">
{countText}
</p>
<h1 className="text-4xl font-semibold">{appName}</h1>
<p className="text-zinc-600 dark:text-zinc-400">
Everyone below shipped their first pull request here.
Expand All @@ -21,14 +26,15 @@ export default function Home() {
>
<a
href={`https://github.com/${intern.github}`}
className="font-medium underline-offset-4 hover:underline"
aria-label={`Visit GitHub profile of ${intern.name}`}
className="font-medium underline underline-offset-4 hover:underline"
>
{intern.name}
</a>
<p className="text-zinc-600 dark:text-zinc-400">{intern.goal}</p>
<p className="text-zinc-600 dark:text-zinc-400">{intern.message}</p>
</li>
))}
</ul>
</main>
)
}
);
}
13 changes: 13 additions & 0 deletions src/lib/count.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { describe, expect, it } from 'vitest';
import { peopleSoFar } from './count';

describe('peopleSoFar', () => {
it('formats singular correctly', () => {
expect(peopleSoFar(1)).toBe('1 person so far');
});

it('formats plural correctly', () => {
expect(peopleSoFar(2)).toBe('2 people so far');
expect(peopleSoFar(5)).toBe('5 people so far');
});
});
11 changes: 11 additions & 0 deletions src/lib/cout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function peopleSoFar(count: number): string {
const pr = new Intl.PluralRules('en', { type: 'cardinal' });
const rule = pr.select(count);

switch (rule) {
case 'one':
return `${count} person so far`;
default:
return `${count} people so far`;
}
}
27 changes: 24 additions & 3 deletions src/lib/interns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'

import { interns } from '@/data/interns'

import { duplicateHandles, isSortedByName } from './interns'
import { duplicateHandles, isSortedByName, isValidGithubUsername } from './interns'

describe('the interns list', () => {
it('is sorted by name', () => {
Expand All @@ -13,10 +13,11 @@ describe('the interns list', () => {
expect(duplicateHandles(interns)).toEqual([])
})

it('has a goal for everyone, without the @ in usernames', () => {
it('has a goal for everyone, and valid GitHub usernames', () => {
for (const intern of interns) {
expect(intern.goal.trim()).not.toBe('')
expect(intern.github.startsWith('@')).toBe(false)
// Шаг 5: заменили старую проверку на вашу новую функцию валидации
expect(isValidGithubUsername(intern.github)).toBe(true)
}
})
})
Expand All @@ -39,3 +40,23 @@ describe('duplicateHandles', () => {
expect(duplicateHandles(list)).toEqual(['Anna'])
})
})

// Шаг 1: Добавляем новый блок тестов для isValidGithubUsername
describe('isValidGithubUsername', () => {
it('accepts valid GitHub usernames', () => {
expect(isValidGithubUsername('kbarejko')).toBe(true)
expect(isValidGithubUsername('anna-kowalska')).toBe(true)
expect(isValidGithubUsername('A1')).toBe(true)
expect(isValidGithubUsername('a'.repeat(39))).toBe(true)
})

it('rejects invalid GitHub usernames', () => {
expect(isValidGithubUsername('-anna')).toBe(false)
expect(isValidGithubUsername('anna-')).toBe(false)
expect(isValidGithubUsername('anna--k')).toBe(false)
expect(isValidGithubUsername('anna kowalska')).toBe(false)
expect(isValidGithubUsername('@anna')).toBe(false)
expect(isValidGithubUsername('')).toBe(false)
expect(isValidGithubUsername('a'.repeat(40))).toBe(false)
})
})
Loading