Commit 51195118 authored by Nastassia Danilova's avatar Nastassia Danilova

fetch custom emojis

parent a0bdf1bf
Pipeline #28856 passed with stages
in 7 minutes and 29 seconds
......@@ -33,6 +33,12 @@ const Configs = {
config,
url: '/api/statusnet/config.json'
})
},
async getCustomEmojis ({ config }) {
return utils.request({
config,
url: `/api/v1/custom_emojis`
})
}
}
......
......@@ -5,11 +5,16 @@ const addConfig = (state, { config }) => ({
...state,
...config
})
const addEmojis = (state, { emojis }) => ({
...state,
emojis
})
const clear = (state) => ({
...initialState
})
const reducers = {
addConfig,
addEmojis,
clear
}
......@@ -20,6 +25,12 @@ const actions = {
payload: { config }
}
},
addEmojis: ({ emojis }) => {
return {
type: 'addEmojis',
payload: { emojis }
}
},
clear: () => {
return {
type: 'clear',
......
......@@ -14,6 +14,14 @@ const configThunks = {
await dispatch(Config.actions.addConfig({ config: { [appId]: Object.assign(result[0].data, result[1].data) } }))
return getState()
}
},
fetchCustomEmoji: ({ config }) => {
return async (dispatch, getState) => {
const result = await configsApi.getCustomEmojis({ config: getConfig(getState, config) })
.then(res => apiErrorCatcher(res))
await dispatch(Config.actions.addEmojis({ emojis: result.data }))
return getState()
}
}
}
......
......@@ -56,4 +56,22 @@ describe('Configs api', () => {
expect(res.data).toEqual({ hideUserStats: true, hidePostStats: false })
})
})
describe('/api/v1/custom_emojis', () => {
it('returns list of custom emoji', async () => {
const emojis = [
{ "girlpower": {
"tags": [
"Finmoji"
],
"image_url": "/finmoji/128px/girlpower-128.png"
} }
]
fetch.mockImplementationOnce(fetchMocker(emojis, {
expectedUrl: 'https://pleroma.soykaf.com/api/v1/custom_emojis'
}))
const res = await api.configs.getCustomEmojis({ config })
expect(res.data).toEqual(emojis)
})
})
})
......@@ -8,6 +8,24 @@ describe('Config reducers', () => {
expect(resultState.settings).toEqual(settings)
})
it('add emojis', () => {
const config = {
theme: 'pleroma-dark'
}
const emojis = [
{
"shortcode": "blobaww",
"url": "https://files.mastodon.social/custom_emojis/images/000/011/739/original/blobaww.png",
"static_url": "https://files.mastodon.social/custom_emojis/images/000/011/739/static/blobaww.png",
"visible_in_picker": true,
"category": "Blobs"
}
]
const resultState = Config.reducer(config, Config.actions.addEmojis({ emojis }))
expect(resultState).toEqual({ theme: 'pleroma-dark', emojis })
})
it('clear config', () => {
const config = { theme: 'pleroma-dark' }
const resultState = Config.reducer(config, Config.actions.clear())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment