-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from devrchancay/master
ahora soy un modulo de npm π
- Loading branch information
Showing
4 changed files
with
54 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,48 +1,42 @@ | ||
/** | ||
* | ||
* EUNews | ||
* | ||
* EUNews | ||
* lea las notas guardas | ||
* Agrege las notas | ||
* Elimine. | ||
*/ | ||
|
||
import EuNews from '../index' | ||
import EuNews from "../index"; | ||
|
||
describe("Probar el correcto funcinamiento de EUNews", function() { | ||
const eu = new EuNews(); | ||
|
||
const nota = { | ||
id: 1, | ||
slug: "deportes" | ||
}; | ||
|
||
describe('Probar el correcto funcinamiento de EUNews', function(){ | ||
it("Deberia inicializarse sin notas", function() { | ||
expect(eu.getNews()).toEqual([]); | ||
}); | ||
|
||
const eu = new EuNews(); | ||
it("Deberia agregar una nota", function() { | ||
eu.addNews(nota); | ||
expect(eu.getNews()).toContain(nota); | ||
}); | ||
|
||
const nota = { | ||
id: 1, | ||
slug: 'deportes' | ||
} | ||
it("No deberia agregar notas repetidas", function() { | ||
eu.addNews(nota); | ||
expect(eu.getNews().length).toEqual(1); | ||
}); | ||
|
||
it('Deberia inicializarse sin notas', function(){ | ||
expect(eu.getNews()).toEqual([]); | ||
}); | ||
it("Deberia encontrar la nota por slug", function() { | ||
const nota_encontrada = eu.findNews(nota.slug); | ||
expect(nota_encontrada).toEqual(nota); | ||
}); | ||
|
||
it('Deberia agregar una nota', function(){ | ||
eu.addNews(nota) | ||
expect(eu.getNews()).toContain(nota); | ||
}); | ||
|
||
it('No deberia agregar notas repetidas', function(){ | ||
eu.addNews(nota); | ||
expect(eu.getNews().length).toEqual(1); | ||
}) | ||
|
||
it('Deberia encontrar la nota por slug', function(){ | ||
const nota_encontrada = eu.findNews(nota.slug); | ||
expect(nota_encontrada).toEqual(nota) | ||
}) | ||
|
||
it('Deberia eliminar la nota', function(){ | ||
eu.removeNews(nota.id); | ||
expect(eu.getNews().length).toEqual(0) | ||
}) | ||
|
||
|
||
|
||
}) | ||
it("Deberia eliminar la nota", function() { | ||
eu.removeNews(nota.id); | ||
expect(eu.getNews().length).toEqual(0); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,36 +1,32 @@ | ||
class EuNews { | ||
constructor() { | ||
this.news = []; | ||
} | ||
|
||
constructor(){ | ||
this.news = [] | ||
} | ||
getNews() { | ||
return this.news; | ||
} | ||
|
||
getNews(){ | ||
return this.news; | ||
addNews(nota) { | ||
if (Object.keys(this.findNews(nota.slug)).length === 0) { | ||
this.news.push(nota); | ||
} | ||
} | ||
|
||
addNews(nota){ | ||
if(Object.keys(this.findNews(nota.slug)).length === 0){ | ||
this.news.push(nota); | ||
} | ||
} | ||
|
||
removeNews(id){ | ||
const index = this.news.findIndex(item => item.id === id); | ||
if(index !== -1){ | ||
this.news = [...this.news.slice(0, index), ...this.news.slice(index + 1)]; | ||
} | ||
removeNews(id) { | ||
const index = this.news.findIndex(item => item.id === id); | ||
if (index !== -1) { | ||
this.news = [...this.news.slice(0, index), ...this.news.slice(index + 1)]; | ||
} | ||
} | ||
|
||
findNews(slug){ | ||
if(this.news.some(item => item.slug === slug)){ | ||
return this.news.find(item => item.slug === slug); | ||
} | ||
else{ | ||
return {} | ||
} | ||
findNews(slug) { | ||
if (this.news.some(item => item.slug === slug)) { | ||
return this.news.find(item => item.slug === slug); | ||
} else { | ||
return {}; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
export default EuNews; | ||
export default EuNews; |