Skip to content

Commit

Permalink
Merge pull request #8 from devrchancay/master
Browse files Browse the repository at this point in the history
ahora soy un modulo de npm πŸŽ‰
  • Loading branch information
devrchancay authored Oct 13, 2018
2 parents ca982a2 + 275e0d9 commit 8a52d9f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "taller-de-js-basico",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll",
Expand Down
64 changes: 29 additions & 35 deletions src/__tests__/index.js
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);
});
});
48 changes: 22 additions & 26 deletions src/index.js
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;

0 comments on commit 8a52d9f

Please sign in to comment.