-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding some straightforward unit tests
- Loading branch information
1 parent
18be2b8
commit 575b866
Showing
7 changed files
with
500 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {describe, it, expect, type TestOptions} from 'vitest'; | ||
import { | ||
CallbackStateProcessor, | ||
CallbackStateProvider, | ||
CrudDefinition, | ||
List, | ||
} from "$lib"; | ||
|
||
const testOpts: TestOptions = {repeats: process.env.REPEAT ? parseInt(process.env.REPEAT) : undefined}; | ||
|
||
type Book = {}; | ||
|
||
describe( | ||
'Crud definition', | ||
() => { | ||
it('can be instantiated with simple config', () => { | ||
const crud = new CrudDefinition<Book>('books', { | ||
label: {singular: '', plural: ''}, | ||
operations: [new List([])], | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}); | ||
|
||
expect(crud).toBeDefined(); | ||
}); | ||
it('can be instantiated with simple config containing existing default operation name', () => { | ||
const crud = new CrudDefinition<Book>('books', { | ||
label: {singular: '', plural: ''}, | ||
operations: [new List([])], | ||
defaultOperationName: 'list', | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}); | ||
|
||
expect(crud).toBeDefined(); | ||
}); | ||
|
||
it('cannot be instantiated without operations', () => { | ||
const construct = () => { | ||
new CrudDefinition<Book>('books', { | ||
label: {singular: '', plural: ''}, | ||
operations: [], | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}); | ||
} | ||
|
||
expect(construct).toThrowError(/^Crud definition "books" has no Crud operations set\./g); | ||
}); | ||
|
||
it('cannot be instantiated if operations list\'s first element is not properly set', () => { | ||
const construct = () => { | ||
const operations = Array(2); | ||
operations[1] = new List([]); | ||
new CrudDefinition<Book>('books', { | ||
label: {singular: '', plural: ''}, | ||
operations: operations, | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}); | ||
} | ||
|
||
expect(construct).toThrowError(/^Crud definition "books" has an invalid default operation name "undefined"\./g); | ||
}); | ||
|
||
it('cannot be instantiated if default operation name does not exist in operations list', () => { | ||
const construct = () => { | ||
const operations = Array(2); | ||
new CrudDefinition<Book>('books', { | ||
label: {singular: '', plural: ''}, | ||
operations: [new List([])], | ||
defaultOperationName: 'edit', | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}); | ||
} | ||
|
||
expect(construct).toThrowError(/^Crud definition "books" has no default operation named "edit"\./g); | ||
}); | ||
}, | ||
testOpts | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {describe, it, expect, type TestOptions} from 'vitest'; | ||
import { | ||
CallbackStateProcessor, | ||
CallbackStateProvider, | ||
CrudDefinition, | ||
DashboardDefinition, | ||
List, | ||
} from "$lib"; | ||
|
||
import {emptyAdminConfig} from "$lib/admin/config/adminConfig.ts"; | ||
|
||
const testOpts: TestOptions = {repeats: process.env.REPEAT ? parseInt(process.env.REPEAT) : undefined}; | ||
|
||
type Book = {}; | ||
|
||
describe( | ||
'Dashboard', | ||
() => { | ||
it('can be instantiated with simple config', () => { | ||
const dashboard = new DashboardDefinition<Book>({ | ||
adminConfig: emptyAdminConfig(), | ||
cruds: [ | ||
new CrudDefinition<Book>('books', { | ||
label: {singular: 'Book', plural: 'Books'}, | ||
operations: [ | ||
new List([]), | ||
], | ||
stateProvider: new CallbackStateProvider<Book>(() => null), | ||
stateProcessor: new CallbackStateProcessor<Book>(() => {}), | ||
}) | ||
], | ||
}); | ||
|
||
expect(dashboard).toBeDefined(); | ||
}); | ||
}, | ||
testOpts | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {describe, it, expect, type TestOptions} from 'vitest'; | ||
import {createEmptyRow} from "$lib/admin/DataTable/DataTable.ts"; | ||
import { | ||
List, | ||
CheckboxField, | ||
Field, | ||
NumberField, | ||
TabsField, | ||
TextareaField, | ||
TextField, | ||
ToggleField, | ||
UrlField | ||
} from "$lib"; | ||
|
||
const testOpts: TestOptions = {repeats: process.env.REPEAT ? parseInt(process.env.REPEAT) : undefined}; | ||
|
||
type Book = {}; | ||
|
||
describe( | ||
'DataTable', | ||
() => { | ||
it('can create an empty row from empty CrudOperation', () => { | ||
const row = createEmptyRow(new List([])); | ||
|
||
expect(row).toBeDefined(); | ||
expect(row).toStrictEqual({ | ||
id: 0, | ||
}) | ||
}); | ||
|
||
it('can create an empty row from CrudOperation with all fields', () => { | ||
const fields = [ | ||
new CheckboxField('field_1'), | ||
new Field('field_2'), | ||
new NumberField('field_3'), | ||
new TabsField('field_4'), | ||
new TextareaField('field_5'), | ||
new TextField('field_6'), | ||
new ToggleField('field_7'), | ||
new UrlField('field_8'), | ||
]; | ||
const row = createEmptyRow(new List(fields)); | ||
|
||
expect(row).toBeDefined(); | ||
expect(row).toStrictEqual({ | ||
id: 0, | ||
field_1: '-', | ||
field_2: '-', | ||
field_3: '-', | ||
field_4: '-', | ||
field_5: '-', | ||
field_6: '-', | ||
field_7: '-', | ||
field_8: '-', | ||
}) | ||
}); | ||
}, | ||
testOpts | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.