🎨 ✅ add tests & refactor
- add test for getting all tags - add test for transforming resources - output.json -> mockOutput.json
This commit is contained in:
committed by
Unknown
parent
330612ea4c
commit
8273955316
@@ -7,18 +7,13 @@ import {
|
||||
partiallyIncludesElOf,
|
||||
tagsNotEmpty,
|
||||
cleanString,
|
||||
addCleanTitleAndPath,
|
||||
transformToResources,
|
||||
} from '../utils/pure'
|
||||
|
||||
export const state = () => {
|
||||
const resourcesLens = R.lens(R.prop('resources'), R.assoc('resources'))
|
||||
return {
|
||||
resources: R.map(category =>
|
||||
R.over(resourcesLens, R.map(addCleanTitleAndPath(category.slug)), category),
|
||||
categories),
|
||||
tags: getAllTags(categories),
|
||||
}
|
||||
}
|
||||
export const state = () => ({
|
||||
resources: transformToResources(categories),
|
||||
tags: getAllTags(categories),
|
||||
})
|
||||
|
||||
export const getters = {
|
||||
tags: R.prop('tags'),
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import * as P from '../utils/pure.js'
|
||||
import mockCategories from './mockCategories.json'
|
||||
import mockOutput from './mockOutput.json'
|
||||
|
||||
test('includesElOf 1', () => {
|
||||
expect(P.includesElOf([1, 2])([2])).toBeTruthy
|
||||
@@ -27,3 +29,13 @@ test('partiallyIncludesElOf 2', () => {
|
||||
test('partiallyIncludesElOf 3', () => {
|
||||
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)
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
/*eslint-disable */
|
||||
import * as R from 'ramda'
|
||||
|
||||
/// Types
|
||||
/// TYPES ///
|
||||
// const Category = {
|
||||
// title: String,
|
||||
// slug: String,
|
||||
@@ -17,7 +17,7 @@ import * as R from 'ramda'
|
||||
// tags: [String],
|
||||
// }
|
||||
|
||||
/// Functions
|
||||
/// FUNCTIONS ///
|
||||
// isNotEmpty [a] -> Bool
|
||||
export const isNotEmpty = R.compose(R.not, R.isEmpty)
|
||||
|
||||
@@ -54,11 +54,19 @@ export const partiallyIncludesElOf = R.curry((list1, list2) =>
|
||||
)
|
||||
|
||||
// addCleanTitleAndPath :: Object -> Resource
|
||||
export const addCleanTitleAndPath = R.curry((slug, obj) => {
|
||||
const addCleanTitleAndPath = R.curry((slug, obj) => {
|
||||
const cleanTitle = cleanStringAndRemoveSpaces(obj.title)
|
||||
return {
|
||||
...obj,
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user