Skip to content

Commit

Permalink
feat(VCalendar): update parser to return full category (#12638)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan <nquinn@medonesystems.com>
  • Loading branch information
nquinn721 and Nathan committed Nov 19, 2020
1 parent c96245b commit e2200c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('VCalendarCategory', () => {
}
})

it('should test categoryText prop as a string', async () => {
it('should test categoryText prop as a string', () => {
const wrapper = mountFunction({
propsData: {
categories: [{ name: 'Nate' }],
Expand All @@ -35,7 +35,7 @@ describe('VCalendarCategory', () => {
expect(wrapper.find('.v-calendar-category__column-header').text()).toEqual('Nate')
})

it('should test categoryText prop as a function', async () => {
it('should test categoryText prop as a function', () => {
const wrapper = mountFunction({
propsData: {
categories: [{ name: 'Nate', age: 20 }],
Expand All @@ -47,4 +47,18 @@ describe('VCalendarCategory', () => {

expect(wrapper.find('.v-calendar-category__column-header').text()).toEqual('20')
})

it('should pass entire cateogry to interval style method', () => {
function intervalStyle (obj) {
expect(obj.category).toEqual({ name: 'Nate', age: 20, categoryName: 'Nate' })
}

const wrapper = mountFunction({
propsData: {
categories: [{ name: 'Nate', age: 20 }],
categoryText: 'name',
intervalStyle,
},
})
})
})
11 changes: 6 additions & 5 deletions packages/vuetify/src/components/VCalendar/util/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export function getParsedCategories (
): CalendarCategory[] {
if (typeof categories === 'string') return categories.split(/\s*,\s/)
if (Array.isArray(categories)) {
return categories.map((v: CalendarCategory) => {
const categoryName = typeof v === 'string' ? v
: typeof v === 'object' && v && typeof v.categoryName === 'string' ? v.categoryName
: parsedCategoryText(v, categoryText)
return { categoryName }
return categories.map((category: CalendarCategory) => {
if (typeof category === 'string') return { categoryName: category }

const categoryName = typeof category.categoryName === 'string' ? category.categoryName
: parsedCategoryText(category, categoryText)
return { ...category, categoryName }
})
}
return []
Expand Down

0 comments on commit e2200c3

Please sign in to comment.