-
Notifications
You must be signed in to change notification settings - Fork 12
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 #37 from andela/ft/167190403-articles-from-tag
Display all Articles With a Specific Tag
- Loading branch information
Showing
15 changed files
with
352 additions
and
18 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/actions/__tests__/__snapshots__/tagAction.spec.js.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tag action tag action test tagAction should return expected value 1`] = `[Function]`; | ||
|
||
exports[`tag action test view articles with tag action should display articles with tag 1`] = ` | ||
Array [ | ||
Object { | ||
"payload": Array [], | ||
"tag": Object {}, | ||
"type": "GET_ARTICLES_WITH_TAG", | ||
}, | ||
] | ||
`; |
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,51 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import nock from 'nock'; | ||
import { getArticlesWithTagFromDb } from '@Actions/tagAction'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
const url = 'https://a-haven-staging.herokuapp.com/api/v1'; | ||
|
||
|
||
describe('tag action', () => { | ||
describe('tag action test', () => { | ||
const tag = { | ||
articleTag: 'javascript', | ||
}; | ||
|
||
const history = { | ||
push: jest.fn(), | ||
}; | ||
|
||
it('tagAction should return expected value', () => { | ||
expect(getArticlesWithTagFromDb(tag, history)).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('test view articles with tag action', () => { | ||
let store; | ||
const response = { | ||
articles: [], | ||
}; | ||
|
||
beforeEach(() => { | ||
store = mockStore({}); | ||
}); | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('should display articles with tag', () => { | ||
nock(url) | ||
.post('/articles/tag/get-article') | ||
.reply(200, response); | ||
|
||
return store.dispatch(getArticlesWithTagFromDb({}, { push: jest.fn() })) | ||
.then(() => { | ||
expect(store.getActions()).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
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 { GET_ARTICLES_WITH_TAG } from '@Actions/types'; | ||
import swal from '@sweetalert/with-react'; | ||
import { axiosInstance } from '@Utils/'; | ||
|
||
|
||
export const getArticlesWithTag = (payload, tag) => ({ | ||
type: GET_ARTICLES_WITH_TAG, | ||
payload, | ||
tag, | ||
}); | ||
|
||
export const getArticlesWithTagFromDb = (tag, history) => async dispatch => { | ||
try { | ||
const response = await axiosInstance.post('/articles/tag/get-article', { tag: { articleTag: tag } }); | ||
|
||
if (response.status === 200) { | ||
dispatch(getArticlesWithTag(response.data.articles, tag)); | ||
history.push('/tags'); | ||
} | ||
} catch (err) { | ||
swal({ | ||
text: err.response.data.error, | ||
icon: 'error', | ||
buttons: false, | ||
timer: 4000, | ||
}); | ||
} | ||
}; |
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,18 @@ | ||
module.exports = { | ||
'@tag': ['articlesTag'], | ||
'User should be able to see articles list on clicking a tag': (browser) => { | ||
browser | ||
.url('http://localhost:9090/articles/Regional-Group-Manager') | ||
.pause(3000) | ||
.assert.visible('div[class="read-article"]') | ||
.pause(500) | ||
.moveToElement('div[class="comment-delete"]', 10, 10) | ||
.waitForElementVisible('div[class="article-tag-div"]') | ||
.pause(3000) | ||
.click('li[class="liTag"]') | ||
.pause(3000) | ||
.waitForElementVisible('articlesList') | ||
.pause(3000) | ||
.end(); | ||
}, | ||
}; |
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,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`tag reducer test should return new state 1`] = ` | ||
Object { | ||
"articles": Array [ | ||
Object {}, | ||
], | ||
"suppliedTag": undefined, | ||
} | ||
`; |
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,19 @@ | ||
export const initState = { | ||
articles: [], | ||
suppliedTag: '', | ||
}; | ||
|
||
const tagReducer = (state = initState, action) => { | ||
switch (action.type) { | ||
case 'GET_ARTICLES_WITH_TAG': | ||
return { | ||
...state, | ||
articles: action.payload, | ||
suppliedTag: action.tag, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default tagReducer; |
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,16 @@ | ||
import { GET_ARTICLES_WITH_TAG } from '@Actions/types'; | ||
import tagReducer, { initState } from './tagReducer'; | ||
|
||
describe('tag reducer test', () => { | ||
it('should return initial state', () => { | ||
expect(tagReducer(undefined, {})).toEqual(initState); | ||
}); | ||
|
||
it('should return new state', () => { | ||
expect(tagReducer(initState, { | ||
type: GET_ARTICLES_WITH_TAG, | ||
payload: [{}], | ||
suppliedTag: 'travel', | ||
})).toMatchSnapshot(); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -196,3 +196,8 @@ | |
align-items: center; | ||
} | ||
} | ||
|
||
.liTag :hover { | ||
cursor: pointer; | ||
transform: scale(1.2); | ||
} |
Oops, something went wrong.