Skip to content
Draft
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
3,412 changes: 2,360 additions & 1,052 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions src/lib/components/CheckBoxGroup.svelte.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe, test, expect } from 'vitest';
import '@testing-library/jest-dom/vitest';
import { render, screen } from '@testing-library/svelte';
import CheckBoxGroup from './CheckBoxGroup.svelte';

describe('CheckBoxGroup.svelte', () => {
test('should render without crashing', () => {
const options = [
{ label: 'option1', value: 'option1' },
{ label: 'option2', value: 'option2' }
];

render(CheckBoxGroup, { props: { options, group: [] } });

// Component should render without throwing
expect(document.body).toBeInTheDocument();
});

test('should render checkboxes for all options', () => {
const options = [
{ label: 'option1', value: 'option1' },
{ label: 'option2', value: 'option2' },
{ label: 'option3', value: 'option3' }
];

render(CheckBoxGroup, { props: { options, group: [] } });

const checkboxes = screen.getAllByRole('checkbox');
expect(checkboxes).toHaveLength(3);
});

test('should render options with proper values', () => {
const options = [
{ label: 'First Option', value: 'option1' },
{ label: 'Second Option', value: 'option2' }
];

render(CheckBoxGroup, { props: { options, group: [] } });

const checkboxes = screen.getAllByRole('checkbox');
expect(checkboxes[0]).toHaveAttribute('value', 'option1');
expect(checkboxes[1]).toHaveAttribute('value', 'option2');
});

test('should render with labels', () => {
const options = [
{ label: 'First Option', value: 'option1' }
];

render(CheckBoxGroup, { props: { options, group: [] } });

const labels = screen.getAllByRole('checkbox');
expect(labels).toHaveLength(1);
// Each checkbox is wrapped in a label
const checkbox = labels[0];
expect(checkbox.closest('label')).toBeInTheDocument();
});
});
50 changes: 50 additions & 0 deletions src/lib/components/Select.svelte.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, test, expect } from 'vitest';
import '@testing-library/jest-dom/vitest';
import { render, screen } from '@testing-library/svelte';
import Select from './Select.svelte';

describe('Select.svelte', () => {
test('should render without crashing', () => {
const options = [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' }
];

render(Select, { props: { options, value: 'option1', label: 'Test Select' } });

// Component should render without throwing
expect(document.body).toBeInTheDocument();
});

test('should display label', () => {
const options = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' }
];

render(Select, { props: { options, value: 'apple', label: 'Choose Fruit' } });

expect(screen.getByText('Choose Fruit')).toBeInTheDocument();
});

test('should render select element', () => {
const options = [
{ value: 'a', label: 'Option A' },
{ value: 'b', label: 'Option B' }
];

render(Select, { props: { options, value: 'a', label: 'Test' } });

const selectElement = screen.getByRole('combobox');
expect(selectElement).toBeInTheDocument();
});

test('should handle empty options array', () => {
const options: { value: string; label: string }[] = [];

render(Select, { props: { options, value: '', label: 'Empty Select' } });

const selectElement = screen.getByRole('combobox');
expect(selectElement).toBeInTheDocument();
});
});
66 changes: 66 additions & 0 deletions src/lib/components/ui/button/button.svelte.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { describe, test, expect } from 'vitest';
import '@testing-library/jest-dom/vitest';
import { render, screen } from '@testing-library/svelte';
import Button from './button.svelte';

describe('Button.svelte', () => {
test('should render with default props', () => {
render(Button, {
props: {}
});

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
});

test('should render with text content', () => {
const TestButton = (Component: any) => {
return `<${Component}>Click me</${Component}>`;
};

// Since the component uses bits-ui, we'll just check it renders
render(Button, { props: {} });

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
});

test('should apply variant classes', () => {
render(Button, {
props: { variant: 'destructive' }
});

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
// The button should have variant styling applied
expect(button.className).toContain('destructive');
});

test('should apply size classes', () => {
render(Button, {
props: { size: 'sm' }
});

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
// The button should have h-8 class for small size
expect(button.className).toContain('h-8');
});

test('should apply custom class names', () => {
render(Button, {
props: { class: 'custom-class' }
});

const button = screen.getByRole('button');
expect(button).toBeInTheDocument();
expect(button).toHaveClass('custom-class');
});

test('should have button type by default', () => {
render(Button, { props: {} });

const button = screen.getByRole('button');
expect(button).toHaveAttribute('type', 'button');
});
});
173 changes: 173 additions & 0 deletions src/lib/database/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { describe, test, expect, vi } from 'vitest';
import {
getEntityDB,
findConnectiveForDB,
getRecommendationDB,
getHistoryDB,
searchForEntitiesDB,
createDuplicationDB,
createConnectionDB,
createStatementDB,
voteForEntityDB
} from './index';
import type { IEntityType } from '$lib/types';

// Mock data imports
vi.mock('../features/statement/data', () => ({
statements: [
{
id: '1',
type: 'statement',
text: 'Test statement',
lastSeasonTruth: 0.8,
numberOfVotes: 100,
voteRatio: 0.6,
author: 'Test Author'
}
]
}));

vi.mock('../features/statement/features/connection/data', () => ({
connections: [
{
id: '1',
type: 'connection',
thesis: { id: '1', type: 'statement', text: 'Test', lastSeasonTruth: 0.8, numberOfVotes: 100, voteRatio: 0.6, author: 'Test' },
argument: { id: '2', type: 'statement', text: 'Test arg', lastSeasonTruth: 0.7, numberOfVotes: 50, voteRatio: 0.5, author: 'Test' },
isProArgument: true,
weight: 0.8,
numberOfVotes: 100,
isTrueVotes: 80,
creator: 'Test Creator'
}
]
}));

vi.mock('../features/statement/features/duplication/data', () => ({
duplictons: [
{
id: '1',
type: 'duplication',
statementA: { id: '1', type: 'statement', text: 'Test A', lastSeasonTruth: 0.8, numberOfVotes: 100, voteRatio: 0.6, author: 'Test' },
statementB: { id: '2', type: 'statement', text: 'Test B', lastSeasonTruth: 0.7, numberOfVotes: 50, voteRatio: 0.5, author: 'Test' },
numberOfVotes: 100,
isDuplicateVotes: 75
}
]
}));

describe('database functions', () => {
describe('getHistoryDB', () => {
test('should return default history without parameters', () => {
const result = getHistoryDB();
expect(result).toHaveProperty('ids');
expect(result).toHaveProperty('types');
expect(Array.isArray(result.ids)).toBe(true);
expect(Array.isArray(result.types)).toBe(true);
});

test('should handle skip and limit parameters', () => {
const result = getHistoryDB(10, 20);
expect(result).toHaveProperty('ids');
expect(result).toHaveProperty('types');
});
});

describe('searchForEntitiesDB', () => {
test('should return search results for given term and filter', () => {
const filterOptions = {
entitytype: ['statement' as IEntityType]
};

const result = searchForEntitiesDB('test', filterOptions);
expect(Array.isArray(result)).toBe(true);
});

test('should handle empty search term', () => {
const filterOptions = {
entitytype: ['statement' as IEntityType]
};

const result = searchForEntitiesDB('', filterOptions);
expect(Array.isArray(result)).toBe(true);
});
});

describe('createDuplicationDB', () => {
test('should create duplication and return id', () => {
const result = createDuplicationDB('statement1', 'statement2');
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});
});

describe('createConnectionDB', () => {
test('should create connection and return id', () => {
const result = createConnectionDB('thesis1', 'argument1', true);
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

test('should handle both pro and contra arguments', () => {
const proResult = createConnectionDB('thesis1', 'argument1', true);
const contraResult = createConnectionDB('thesis1', 'argument1', false);

expect(typeof proResult).toBe('string');
expect(typeof contraResult).toBe('string');
});
});

describe('createStatementDB', () => {
test('should create statement and return id', () => {
const result = createStatementDB('Test statement text');
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

test('should handle optional tags parameter', () => {
const resultWithoutTags = createStatementDB('Test statement');
const resultWithTags = createStatementDB('Test statement', ['tag1', 'tag2']);

expect(typeof resultWithoutTags).toBe('string');
expect(typeof resultWithTags).toBe('string');
});
});

describe('voteForEntityDB', () => {
test('should handle voting for statement entities', () => {
const result = voteForEntityDB('1', 'statement', 1);
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

test('should handle voting for connection entities', () => {
const result = voteForEntityDB('1', 'connection', 0);
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

test('should handle voting for duplication entities', () => {
const result = voteForEntityDB('1', 'duplication', -1);
expect(typeof result).toBe('string');
expect(result.length).toBeGreaterThan(0);
});

test('should handle different vote values', () => {
const voteValues = [-1, 0, 1];

voteValues.forEach(value => {
const result = voteForEntityDB('1', 'statement', value);
expect(typeof result).toBe('string');
});
});
});

describe('getRecommendationDB', () => {
test('should return a valid entity', () => {
const result = getRecommendationDB();
expect(result).toBeDefined();
expect(result).toHaveProperty('id');
expect(result).toHaveProperty('type');
});
});
});
Loading