Skip to content

Commit

Permalink
Merge 23ca887 into b76db54
Browse files Browse the repository at this point in the history
  • Loading branch information
notmessenger committed Feb 1, 2018
2 parents b76db54 + 23ca887 commit a3e2f8b
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 4 deletions.
14 changes: 11 additions & 3 deletions addon/components/array-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ export default Component.extend(HookMixin, PropTypeMixin, {
* @returns {String} label
*/
addLabel (bunsenId, cellConfig, bunsenModel) {
const label = get(cellConfig, 'label')
const renderLabel = getLabel(label, bunsenModel, bunsenId)
return `Add ${singularize(renderLabel).toLowerCase()}`
const prefix = 'Add '
let label = get(cellConfig, 'label')

if (label) {
label = `${singularize(label)}`
} else {
const renderLabel = getLabel(label, bunsenModel, bunsenId)
label = `${singularize(renderLabel).toLowerCase()}`
}

return `${prefix}${label}`
},

@readOnly
Expand Down
7 changes: 6 additions & 1 deletion addon/components/cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ export default Component.extend(HookMixin, PropTypeMixin, {
return null
}

const label = get(cellConfig, 'label')
let label = get(cellConfig, 'label')

if (label) {
label = label.charAt(0).toUpperCase() + label.slice(1)
}

return getLabel(label, bunsenModel, nonIndexId)
},

Expand Down
55 changes: 55 additions & 0 deletions tests/dummy/mirage/data/views/array-explicit-label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export default {
version: '2.0',
type: 'form',
cells: [
{
extends: 'main'
}
],
cellDefinitions: {
addr: {
children: [
{
model: 'street'
},
{
model: 'city'
},
{
model: 'state'
},
{
model: 'zip'
}
]
},
main: {
children: [
{
model: 'name',
extends: 'name'
},
{
model: 'addresses',
label: 'HOME Addresses',
arrayOptions: {
itemCell: {
extends: 'addr',
label: 'Address'
}
}
}
]
},
name: {
children: [
{
model: 'first'
},
{
model: 'last'
}
]
}
}
}
2 changes: 2 additions & 0 deletions tests/dummy/mirage/data/views/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import array from './array'
import array2WithConditionals from './array-2-with-conditionals'
import arrayAutoAdd from './array-auto-add'
import arrayCustom from './array-custom'
import arrayExplicitLabel from './array-explicit-label'
import arrayIndexed from './array-indexed'
import arrayIndexed2 from './array-indexed-2'
import arrayInline from './array-inline'
Expand Down Expand Up @@ -31,6 +32,7 @@ export default {
array2WithConditionals,
arrayAutoAdd,
arrayCustom,
arrayExplicitLabel,
arrayIndexed,
arrayIndexed2,
arrayInline,
Expand Down
6 changes: 6 additions & 0 deletions tests/dummy/mirage/fixtures/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export default [
modelIds: ['array'],
view: views.arrayCustom
},
{
id: 'array-explicit-label',
label: 'Array (Explicit Label)',
modelIds: ['array'],
view: views.arrayExplicitLabel
},
{
id: 'array-indexed',
label: 'Array (Indexed)',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
import {expect} from 'chai'
import {describe, it} from 'mocha'

import {expectButtonWithState} from 'dummy/tests/helpers/ember-frost-core'
import selectors from 'dummy/tests/helpers/selectors'
import {setupFormComponentTest} from 'dummy/tests/helpers/utils'

describe(
'Integration: Component / frost-bunsen-form / array Title and "Add" button text with "network elements" label',
function () {
setupFormComponentTest({
bunsenModel: {
type: 'object',
properties: {
name: {
type: 'object',
title: 'Full name',
properties: {
first: {
type: 'string'
},
last: {
type: 'string'
}
},
required: [
'first',
'last'
]
},
addresses: {
type: 'array',
items: {
type: 'object',
properties: {
street: {
type: 'string'
},
city: {
type: 'string'
},
state: {
type: 'string'
},
zip: {
type: 'string'
}
},
required: [
'street',
'city',
'state',
'zip'
]
},
minItems: 1
}
},
required: [
'name',
'addresses'
]
},
bunsenView: {
version: '2.0',
type: 'form',
cells: [
{
extends: 'main'
}
],
cellDefinitions: {
addr: {
children: [
{
model: 'street'
},
{
model: 'city'
},
{
model: 'state'
},
{
model: 'zip'
}
]
},
main: {
children: [
{
model: 'name',
extends: 'name'
},
{
model: 'addresses',
label: 'network elements',
arrayOptions: {
itemCell: {
extends: 'addr',
label: 'Address'
}
}
}
]
},
name: {
children: [
{
model: 'first'
},
{
model: 'last'
}
]
}
}
}
})

it('renders as expected', function () {
const $button = this.$(selectors.frost.button.input.enabled)
const $headings = this.$(selectors.bunsen.section.heading)

expect(
$headings.eq(0).text().trim(),
'renders expected section heading'
).to.equal('Network elements')

expectButtonWithState($button, {
icon: 'round-add',
text: 'Add network element'
})
})
}
)

describe(
'Integration: Component / frost-bunsen-form / array Title and "Add" button text with "IP addresses" label',
function () {
setupFormComponentTest({
bunsenModel: {
type: 'object',
properties: {
name: {
type: 'object',
title: 'Full name',
properties: {
first: {
type: 'string'
},
last: {
type: 'string'
}
},
required: [
'first',
'last'
]
},
addresses: {
type: 'array',
items: {
type: 'object',
properties: {
street: {
type: 'string'
},
city: {
type: 'string'
},
state: {
type: 'string'
},
zip: {
type: 'string'
}
},
required: [
'street',
'city',
'state',
'zip'
]
},
minItems: 1
}
},
required: [
'name',
'addresses'
]
},
bunsenView: {
version: '2.0',
type: 'form',
cells: [
{
extends: 'main'
}
],
cellDefinitions: {
addr: {
children: [
{
model: 'street'
},
{
model: 'city'
},
{
model: 'state'
},
{
model: 'zip'
}
]
},
main: {
children: [
{
model: 'name',
extends: 'name'
},
{
model: 'addresses',
label: 'IP addresses',
arrayOptions: {
itemCell: {
extends: 'addr',
label: 'Address'
}
}
}
]
},
name: {
children: [
{
model: 'first'
},
{
model: 'last'
}
]
}
}
}
})

it('renders as expected', function () {
const $button = this.$(selectors.frost.button.input.enabled)
const $headings = this.$(selectors.bunsen.section.heading)

expect(
$headings.eq(0).text().trim(),
'renders expected section heading'
).to.equal('IP addresses')

expectButtonWithState($button, {
icon: 'round-add',
text: 'Add IP address'
})
})
}
)
Loading

0 comments on commit a3e2f8b

Please sign in to comment.