🎨 add tests & refactor

- add test for getting all tags
- add test for transforming resources
- output.json -> mockOutput.json
This commit is contained in:
Kevin Van Der Werff
2019-10-22 15:28:11 +02:00
committed by Unknown
parent 330612ea4c
commit 8273955316
4 changed files with 29 additions and 14 deletions

View File

@@ -7,18 +7,13 @@ import {
partiallyIncludesElOf, partiallyIncludesElOf,
tagsNotEmpty, tagsNotEmpty,
cleanString, cleanString,
addCleanTitleAndPath, transformToResources,
} from '../utils/pure' } from '../utils/pure'
export const state = () => { export const state = () => ({
const resourcesLens = R.lens(R.prop('resources'), R.assoc('resources')) resources: transformToResources(categories),
return { tags: getAllTags(categories),
resources: R.map(category => })
R.over(resourcesLens, R.map(addCleanTitleAndPath(category.slug)), category),
categories),
tags: getAllTags(categories),
}
}
export const getters = { export const getters = {
tags: R.prop('tags'), tags: R.prop('tags'),

View File

@@ -1,4 +1,6 @@
import * as P from '../utils/pure.js' import * as P from '../utils/pure.js'
import mockCategories from './mockCategories.json'
import mockOutput from './mockOutput.json'
test('includesElOf 1', () => { test('includesElOf 1', () => {
expect(P.includesElOf([1, 2])([2])).toBeTruthy expect(P.includesElOf([1, 2])([2])).toBeTruthy
@@ -27,3 +29,13 @@ test('partiallyIncludesElOf 2', () => {
test('partiallyIncludesElOf 3', () => { test('partiallyIncludesElOf 3', () => {
expect(P.partiallyIncludesElOf(['aa', 'b'], ['c'])).toBeFalsy expect(P.partiallyIncludesElOf(['aa', 'b'], ['c'])).toBeFalsy
}) })
test('get all tags', () => {
expect(P.getAllTags(mockCategories)).toStrictEqual([
"generator", "grid", "layout", "visual tool", "animation", "educational", "beginner", "career", "ui", "ux", "illustration", "svg", "tips", "tricks",
])
})
test('transform resources', () => {
expect(P.transformToResources(mockCategories)).toStrictEqual(mockOutput)
})

View File

@@ -1,7 +1,7 @@
/*eslint-disable */ /*eslint-disable */
import * as R from 'ramda' import * as R from 'ramda'
/// Types /// TYPES ///
// const Category = { // const Category = {
// title: String, // title: String,
// slug: String, // slug: String,
@@ -17,7 +17,7 @@ import * as R from 'ramda'
// tags: [String], // tags: [String],
// } // }
/// Functions /// FUNCTIONS ///
// isNotEmpty [a] -> Bool // isNotEmpty [a] -> Bool
export const isNotEmpty = R.compose(R.not, R.isEmpty) export const isNotEmpty = R.compose(R.not, R.isEmpty)
@@ -54,11 +54,19 @@ export const partiallyIncludesElOf = R.curry((list1, list2) =>
) )
// addCleanTitleAndPath :: Object -> Resource // addCleanTitleAndPath :: Object -> Resource
export const addCleanTitleAndPath = R.curry((slug, obj) => { const addCleanTitleAndPath = R.curry((slug, obj) => {
const cleanTitle = cleanStringAndRemoveSpaces(obj.title) const cleanTitle = cleanStringAndRemoveSpaces(obj.title)
return { return {
...obj, ...obj,
cleanTitle, cleanTitle,
path: `${slug}?card=${cleanTitle}`, path: `${slug}?card=${cleanTitle}`,
} }
}) })
// transformToResources :: [Object] -> [Resource]
export const transformToResources = categories => {
const resourcesLens = R.lens(R.prop('resources'), R.assoc('resources'))
return R.map(category =>
R.over(resourcesLens, R.map(addCleanTitleAndPath(category.slug)), category),
categories)
}