-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
let count = 0; | ||
|
||
export const uuid = () => { | ||
count += 1; | ||
return count; | ||
}; |
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,26 @@ | ||
import { uuid } from './utils.js'; | ||
|
||
/** | ||
* Inserta un nuevo todo al final del original | ||
* @param {*} todos Array en donde insertar el nuevo todo | ||
* @param {*} label Label del nuevo todo | ||
*/ | ||
export const todoInsertar = (todos, label) => { | ||
const todo = { | ||
id: uuid(), | ||
label, | ||
}; | ||
return [ | ||
...todos, | ||
todo, | ||
]; | ||
}; | ||
|
||
/** | ||
* Elimina un todo del array basado en el id | ||
* @param {*} todos Array de donde quitar el todo | ||
* @param {*} id Id del todo a eliminar | ||
*/ | ||
export const todoEliminar = (todos, id) => ( | ||
todos.filter(t => t.id !== id) | ||
); |
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,4 @@ | ||
/** | ||
* Crea un id unico | ||
*/ | ||
export const uuid = () => Date.now(); |
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,28 @@ | ||
import { todoInsertar, todoEliminar } from '../../src/controller/todo'; | ||
|
||
jest.mock('../../src/controller/utils'); | ||
|
||
describe('todo controller', () => { | ||
it('agrega al final', () => { | ||
const todos = [{ id: 0, label: 'existente' }]; | ||
const label = 'nuevo'; | ||
const newTodos = todoInsertar(todos, label); | ||
|
||
expect(newTodos).toEqual([ | ||
{ id: 0, label: 'existente' }, | ||
{ id: 1, label: 'nuevo' }, | ||
]); | ||
}); | ||
it('elimina', () => { | ||
const todos = [ | ||
{ id: 1 }, | ||
{ id: 2 }, | ||
{ id: 3 }, | ||
]; | ||
const newTodos = todoEliminar(todos, 2); | ||
expect(newTodos).toEqual([ | ||
{ id: 1 }, | ||
{ id: 3 }, | ||
]); | ||
}); | ||
}); |
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,12 @@ | ||
/* eslint-disable no-extend-native */ | ||
import { uuid } from '../../src/controller/utils'; | ||
|
||
describe('utils', () => { | ||
it('uuid devuelve timestamp tomado desde `Date.now`', () => { | ||
const now = 1556232924512; | ||
// mockeamos `Date.now` | ||
Date.now = jest.fn().mockReturnValue(now); | ||
|
||
expect(uuid()).toBe(now); | ||
}); | ||
}); |