Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzanne Rozier committed Sep 11, 2019
1 parent 6d258f5 commit 6b1bcd0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,7 @@ describe('The SummaryCounter component', () => {
it('can display count of schools attended', () => {
const expected = {
name: 'summary',
schools: () => [
{
to: {
month: '6',
day: '1',
year: '1982',
},
from: {
month: '6',
day: '1',
year: '1980',
},
},
{
to: {
month: '6',
day: '1',
year: '1984',
},
from: {
month: '6',
day: '1',
year: '1982',
},
},
],
schoolCount: 2,
}
const component = mount(<SummaryCounter {...expected} />)
expect(component.find('.schools.total').text()).toEqual('2')
Expand All @@ -50,13 +25,7 @@ describe('The SummaryCounter component', () => {
it('can display count of diplomas received', () => {
const expected = {
name: 'summary',
diplomas: () => [
{
month: '6',
day: '1',
year: '1982',
},
],
diplomaCount: 1,
}
const component = mount(<SummaryCounter {...expected} />)
expect(component.find('.schools.total').text()).toEqual('0')
Expand Down
42 changes: 22 additions & 20 deletions src/models/validators/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,32 @@ const accordionValidator = (value, options, key, attributes, globalOptions) => {
errors.push(INVALID_BRANCH)
}

if (!items || (items && items.length < 1)) return MISSING_ITEMS
if (!items || (items && items.length < 1)) {
errors.push(MISSING_ITEMS)
} else {
// Validate item length
if (length) {
const lengthErrors = validateModel({ items }, { items: { length } }, { ...globalOptions })
if (lengthErrors !== true) errors = [...errors, ...lengthErrors]
}

// Validate item length
if (length) {
const lengthErrors = validateModel({ items }, { items: { length } }, { ...globalOptions })
if (lengthErrors !== true) errors = [...errors, ...lengthErrors]
}

let itemsErrors = []
for (let i = 0; i < items.length; i += 1) {
const { Item, uuid } = items[i]
const itemId = uuid || i
if (!Item) itemsErrors = itemsErrors.concat(`${itemId}.${INVALID_ITEM}`)
let itemsErrors = []
for (let i = 0; i < items.length; i += 1) {
const { Item, uuid } = items[i]
const itemId = uuid || i
if (!Item) itemsErrors = itemsErrors.concat(`${itemId}.${INVALID_ITEM}`)

const itemErrors = validateModel(Item, validator, { ...globalOptions, ...options })
if (itemErrors !== true) itemsErrors = itemsErrors.concat(itemErrors.map(e => `${itemId}.${e}`))
}
const itemErrors = validateModel(Item, validator, { ...globalOptions, ...options })
if (itemErrors !== true) itemsErrors = itemsErrors.concat(itemErrors.map(e => `${itemId}.${e}`))
}

if (itemsErrors.length) errors = [...errors, ...itemsErrors]
if (itemsErrors.length) errors = [...errors, ...itemsErrors]

// Optional function to test against all of the items
if (itemsValidator) {
const itemsValidatorErrors = itemsValidator(items)
if (itemsValidatorErrors) errors = [...errors, ...itemsValidatorErrors]
// Optional function to test against all of the items
if (itemsValidator) {
const itemsValidatorErrors = itemsValidator(items)
if (itemsValidatorErrors) errors.push(itemsValidatorErrors)
}
}

if (errors.length) return errors
Expand Down

0 comments on commit 6b1bcd0

Please sign in to comment.