mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
Add tests for libraryAPI
This commit is contained in:
parent
edda87c7ee
commit
2d63c78866
48
rsconcept/frontend/src/models/libraryAPI.test.ts
Normal file
48
rsconcept/frontend/src/models/libraryAPI.test.ts
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import { ILibraryItem, LibraryItemType } from './library';
|
||||||
|
import { matchLibraryItem } from './libraryAPI';
|
||||||
|
|
||||||
|
|
||||||
|
describe('Testing matching LibraryItem', () => {
|
||||||
|
const item1: ILibraryItem = {
|
||||||
|
id: 42,
|
||||||
|
item_type: LibraryItemType.RSFORM,
|
||||||
|
title: 'Item1',
|
||||||
|
alias: 'I1',
|
||||||
|
comment: 'comment',
|
||||||
|
is_common: true,
|
||||||
|
is_canonical: true,
|
||||||
|
time_create: 'I2',
|
||||||
|
time_update: '',
|
||||||
|
owner: null
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemEmpty: ILibraryItem = {
|
||||||
|
id: -1,
|
||||||
|
item_type: LibraryItemType.RSFORM,
|
||||||
|
title: '',
|
||||||
|
alias: '',
|
||||||
|
comment: '',
|
||||||
|
is_common: true,
|
||||||
|
is_canonical: true,
|
||||||
|
time_create: '',
|
||||||
|
time_update: '',
|
||||||
|
owner: null
|
||||||
|
};
|
||||||
|
|
||||||
|
test('empty input',
|
||||||
|
() => {
|
||||||
|
expect(matchLibraryItem(itemEmpty, '')).toEqual(true);
|
||||||
|
expect(matchLibraryItem(itemEmpty, '12')).toEqual(false);
|
||||||
|
expect(matchLibraryItem(itemEmpty, ' ')).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('regular input',
|
||||||
|
() => {
|
||||||
|
expect(matchLibraryItem(item1, item1.title)).toEqual(true);
|
||||||
|
expect(matchLibraryItem(item1, item1.alias)).toEqual(true);
|
||||||
|
expect(matchLibraryItem(item1, item1.title + '@invalid')).toEqual(false);
|
||||||
|
expect(matchLibraryItem(item1, item1.alias + '@invalid')).toEqual(false);
|
||||||
|
expect(matchLibraryItem(item1, item1.time_create)).toEqual(false);
|
||||||
|
expect(matchLibraryItem(item1, item1.comment)).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user