Skip to content
Open
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
6 changes: 3 additions & 3 deletions app/components/navbar.responsive-breakpoints.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ describe('Navbar Responsive Breakpoints & Menu Toggle', () => {
expect(screen.getByRole('button', { name: 'Open menu' })).toBeDefined();
});

it('4. Hides the desktop nav row on mobile and only reveals mobile hamburger controls, via complementary md: classes', () => {
it('4. Hides the desktop nav row on mobile and only reveals mobile hamburger controls, via complementary lg: classes', () => {
const { container } = render(<Navbar />);

const desktopNavRow = container.querySelector('.hidden.items-center.gap-2.md\\:flex');
const desktopNavRow = container.querySelector('.hidden.items-center.gap-2.lg\\:flex');
expect(desktopNavRow).toBeInTheDocument();

const mobileControls = container.querySelector(
'.md\\:hidden.inline-flex.items-center.justify-center.gap-1'
'.lg\\:hidden.inline-flex.items-center.justify-center.gap-1'
);
expect(mobileControls).toBeInTheDocument();
});
Expand Down
109 changes: 109 additions & 0 deletions app/generator/GeneratorClient.type-compiler.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { describe, expectTypeOf, it } from 'vitest';
import { GeneratorClient } from './GeneratorClient';
import type {
GeneratorState,
Technology,
Social,
TechCategory,
SocialCategory,
IconType,
} from './types';
import type {
GitHubUser,
GitHubRepo,
GitHubSocialAccount,
ImportedData,
} from './utils/githubMapper';
import { mapGitHubData } from './utils/githubMapper';

describe('GeneratorClient TypeScript Compiler Validation', () => {
// 1. Use type-testing assertions (expectTypeOf) to enforce field property configurations.
it('enforces field property configurations of GeneratorState', () => {
expectTypeOf<GeneratorState['name']>().toEqualTypeOf<string>();
expectTypeOf<GeneratorState['description']>().toEqualTypeOf<string>();
expectTypeOf<GeneratorState['selectedTechs']>().toEqualTypeOf<string[]>();
expectTypeOf<GeneratorState['selectedSocials']>().toEqualTypeOf<string[]>();
expectTypeOf<GeneratorState['socialLinks']>().toEqualTypeOf<Record<string, string>>();
expectTypeOf<GeneratorState['githubUsername']>().toEqualTypeOf<string>();
expectTypeOf<GeneratorState['showCommitPulse']>().toEqualTypeOf<boolean>();
expectTypeOf<GeneratorState['commitPulseAccent']>().toEqualTypeOf<string>();
expectTypeOf<GeneratorState['showRepoSpotlight']>().toEqualTypeOf<boolean>();
expectTypeOf<GeneratorState['spotlightRepo']>().toEqualTypeOf<string>();
expectTypeOf<GeneratorState['showSnakeGraph']>().toEqualTypeOf<boolean>();
expectTypeOf<GeneratorState['showPacmanGraph']>().toEqualTypeOf<boolean>();
expectTypeOf<GeneratorState['graphPlacement']>().toEqualTypeOf<'top' | 'middle' | 'bottom'>();
});

// 2. Assert that invalid prop parameters are blocked during static type checking.
it('blocks invalid prop parameters during static type checking', () => {
// GeneratorClient has no props
expectTypeOf(GeneratorClient).toBeFunction();

void ({
name: 'John Doe',
description: 'Bio details',
selectedTechs: [],
selectedSocials: [],
socialLinks: {},
githubUsername: 'john',
showCommitPulse: true,
commitPulseAccent: '#ff0000',
showRepoSpotlight: false,
spotlightRepo: '',
showSnakeGraph: false,
showPacmanGraph: false,
// @ts-expect-error graphPlacement must be 'top' | 'middle' | 'bottom'
graphPlacement: 'left',
} satisfies GeneratorState);

void ({
name: 'John Doe',
description: 'Bio details',
// @ts-expect-error selectedTechs must be array of strings
selectedTechs: 'react',
selectedSocials: [],
socialLinks: {},
githubUsername: 'john',
showCommitPulse: true,
commitPulseAccent: '#ff0000',
showRepoSpotlight: false,
spotlightRepo: '',
showSnakeGraph: false,
showPacmanGraph: false,
graphPlacement: 'top',
} satisfies GeneratorState);
});

// 3. Verify custom types accept optional/nullable values without compile errors.
it('verifies custom GitHub data types accept optional/nullable values without compile errors', () => {
const user: GitHubUser = {
name: null,
bio: null,
blog: null,
twitter_username: null,
email: null,
};

expectTypeOf(user.name).toEqualTypeOf<string | null>();
expectTypeOf(user.bio).toEqualTypeOf<string | null>();
});

// 4. Verify field configurations and types for Technology and Social interfaces.
it('verifies Technology and Social interfaces and categories', () => {
expectTypeOf<Technology['category']>().toEqualTypeOf<TechCategory>();
expectTypeOf<Social['category']>().toEqualTypeOf<SocialCategory>();
expectTypeOf<Technology['type']>().toEqualTypeOf<IconType>();
expectTypeOf<Social['type']>().toEqualTypeOf<IconType>();
});

// 5. Verify schema validation constraints return strict validation reports.
it('verifies parameter constraints and return shapes on mapGitHubData', () => {
expectTypeOf(mapGitHubData).parameter(0).toEqualTypeOf<GitHubUser>();
expectTypeOf(mapGitHubData).parameter(1).toEqualTypeOf<GitHubRepo[]>();
expectTypeOf(mapGitHubData).parameter(2).toEqualTypeOf<GitHubSocialAccount[]>();
expectTypeOf(mapGitHubData).returns.toEqualTypeOf<ImportedData>();

// @ts-expect-error mapGitHubData parameter 0 must satisfy GitHubUser structure
void mapGitHubData({ name: 123 }, [], []);
});
});
Loading