-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feat(side menu): create menu books list):
- Loading branch information
Showing
6 changed files
with
142 additions
and
42 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,25 @@ | ||
/** | ||
* Convert book to menu item | ||
* @param book | ||
* @returns {{icon: string, link: string, name: string, title, type: string}} | ||
*/ | ||
const bookToMenuItem = (book) => { | ||
return { | ||
title: book.title, | ||
icon: "book-marked-line", | ||
link: `/book/${book.id}`, | ||
type: "link", | ||
name: `${book.id}` | ||
} | ||
} | ||
|
||
/** | ||
* Convert books list to menu list | ||
* @param booksList | ||
* @returns {*} | ||
*/ | ||
const booksListToMenuList = (booksList) => { | ||
return booksList.map(bookToMenuItem) | ||
} | ||
|
||
export {bookToMenuItem, booksListToMenuList} |
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,18 @@ | ||
const bookMock = { | ||
"id": "fb5e7d1d-38cd-4831-bae9-07b36080e3e7", | ||
"created_at": "2024-03-01T23:47:35.711668+03:00", | ||
"updated_at": "2024-03-01T23:47:35.711668+03:00", | ||
"deleted_at": null, | ||
"owner": "e75aae0d-c1eb-4199-a1d8-2177f57d6a1e", | ||
"title": "Тестовая книга", | ||
"author": "Васильев А.В.", | ||
"description": "test description", | ||
"is_public": false, | ||
"publication": null, | ||
"image_link": null, | ||
"map_link": null, | ||
"map_params_id": null, | ||
"variables": [] | ||
} | ||
|
||
export {bookMock} |
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
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,56 @@ | ||
import {describe, test, expect} from 'vitest' | ||
import {bookToMenuItem, booksListToMenuList} from '@helpers/menuFuncs' | ||
import {bookMock} from "@helpers/staticData.js"; | ||
|
||
// { | ||
// "title": "Создать книгу", | ||
// "icon": "file-add-line", | ||
// "link": "/new_book", | ||
// "type": "link", | ||
// "name": "new_book" | ||
// }, | ||
// { | ||
// "title": "Книга 1", | ||
// "icon": "book-marked-line", | ||
// "link": "/book/:link", | ||
// "type": "link", | ||
// "name": "book1" | ||
// }, { | ||
// "title": "Книга 2", | ||
// "icon": "book-marked-line", | ||
// "link": "/book/:link", | ||
// "type": "link", | ||
// "name": "book2" | ||
// }, | ||
|
||
describe("bookToMenuItem", () => { | ||
test('convert book to menu item', () => { | ||
const menuItem = bookToMenuItem(bookMock) | ||
const expectedMenuItem = { | ||
"title": "Тестовая книга", | ||
"icon": "book-marked-line", | ||
"link": `/book/${bookMock.id}`, | ||
"type": "link", | ||
"name": `${bookMock.id}` | ||
} | ||
|
||
expect(menuItem).toEqual(expectedMenuItem) | ||
}) | ||
}) | ||
|
||
describe("booksListToMenuList", () => { | ||
test('convert books list to menu list', () => { | ||
const menuList = booksListToMenuList([bookMock]) | ||
const expectedMenuList = [ | ||
{ | ||
"title": "Тестовая книга", | ||
"icon": "book-marked-line", | ||
"link": `/book/${bookMock.id}`, | ||
"type": "link", | ||
"name": `${bookMock.id}` | ||
} | ||
] | ||
|
||
expect(menuList).toEqual(expectedMenuList) | ||
}) | ||
}) |