Skip to content

Commit

Permalink
feat((pin 262) crr dd): [sc-22942] FSI Note order for 'View all FSI n…
Browse files Browse the repository at this point in the history
…otes and Actions ' (#349)

* feat: [sc-22942] changed positioning of timeline entry launches menu, added badge topSpacing config

* test: [sc-22942] added construction tests for TimelineEntry

* refactor: [sc-22942] minor refactor and added badge construction tests
  • Loading branch information
jazz-b authored Mar 25, 2024
1 parent f4091f6 commit 3a0c5c4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 10 deletions.
14 changes: 12 additions & 2 deletions lib/builders/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,24 @@ function chipBuilder (builder, definition) {
function badgeBuilder (builder, definition) {
const {
icon,
text
text,
topSpacing
} = definition

const badge = builder
.addTag('q-badge')
.addAttribute('class', 'q-mt-md q-mr-sm q-mb-none q-ml-none')
.addAttribute('multi-line', null)

let classes = 'q-mr-sm q-mb-none q-ml-none'
if (!topSpacing || topSpacing === 'medium') {
classes += ' q-mt-md'
} else if (topSpacing === 'small') {
classes += ' q-mt-sm'
} else if (topSpacing === 'none') {
classes += ' q-mt-none'
}
badge.addAttribute('class', classes)

if (icon) {
badge
.addChildTag('q-icon')
Expand Down
16 changes: 8 additions & 8 deletions lib/builders/TimelineEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ module.exports = function (definition, options) {
.addChildTag('template')
.addAttribute('v-slot:title', null)

if (showLaunches) {
const launchesParent = titleTemplate
.addChildTag('div')
.addAttribute('class', 'float-right')

applyLaunches(launchesParent, definition)
}

const titleDivRow = titleTemplate
.addChildTag('div')
.addAttribute('class', 'row')
Expand All @@ -44,14 +52,6 @@ module.exports = function (definition, options) {
titleCol.content(title)
}

if (showLaunches) {
const launchesParent = titleDivRow
.addChildTag('div')
.addAttribute('class', 'col-auto')

applyLaunches(launchesParent, definition)
}

const subtitleTemplate = entry
.addChildTag('template')
.addAttribute('v-slot:subtitle', null)
Expand Down
68 changes: 68 additions & 0 deletions test/chip-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* eslint-env mocha */

'use strict'
const Chip = require('./../lib/builders/Chip')
const chai = require('chai')
const expect = chai.expect

describe('badge construction tests', function () {
it('just text', function () {
const badge = Chip({
style: 'badge',
icon: null,
text: 'TEXT',
topSpacing: null
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-md">TEXT</q-badge>')
})

it('icon and text', function () {
const badge = Chip({
style: 'badge',
icon: 'repeat',
text: 'TEXT',
topSpacing: null
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-md">TEXT<q-icon name="repeat"></q-icon></q-badge>')
})

it('icon and text with undefined top spacing', function () {
const badge = Chip({
style: 'badge',
icon: 'repeat',
text: 'TEXT',
topSpacing: null
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-md">TEXT<q-icon name="repeat"></q-icon></q-badge>')
})

it('icon and text with medium (default) top spacing', function () {
const badge = Chip({
style: 'badge',
icon: 'repeat',
text: 'TEXT',
topSpacing: 'medium'
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-md">TEXT<q-icon name="repeat"></q-icon></q-badge>')
})

it('icon and text with small top spacing', function () {
const badge = Chip({
style: 'badge',
icon: 'repeat',
text: 'TEXT',
topSpacing: 'small'
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-sm">TEXT<q-icon name="repeat"></q-icon></q-badge>')
})

it('icon and text with no top spacing', function () {
const badge = Chip({
style: 'badge',
icon: 'repeat',
text: 'TEXT',
topSpacing: 'none'
}, null)
expect(badge).to.eql('<q-badge multi-line class="q-mr-sm q-mb-none q-ml-none q-mt-none">TEXT<q-icon name="repeat"></q-icon></q-badge>')
})
})
32 changes: 32 additions & 0 deletions test/timeline-entry-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env mocha */

'use strict'
const TimelineEntry = require('./../lib/builders/TimelineEntry')
const chai = require('chai')
const expect = chai.expect

describe('timeline entry construction tests', function () {
it('just a title', function () {
const timelineEntry = TimelineEntry({
icon: null,
color: null,
title: 'TITLE',
subtitle: null,
showWhen: null,
showLaunches: null
}, null)
expect(timelineEntry).to.eql('<q-timeline-entry><template v-slot:title><div class="row"><div class="col">TITLE</div></div></template><template v-slot:subtitle></template>')
})

it('title and subtitle', function () {
const timelineEntry = TimelineEntry({
icon: null,
color: null,
title: 'TITLE',
subtitle: 'SUBTITLE',
showWhen: null,
showLaunches: null
}, null)
expect(timelineEntry).to.eql('<q-timeline-entry><template v-slot:title><div class="row"><div class="col">TITLE</div></div></template><template v-slot:subtitle>SUBTITLE</template>')
})
})

0 comments on commit 3a0c5c4

Please sign in to comment.