Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer adds start attribute to unordered lists #1901

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ exports[`List List component with ascending indents 1`] = `
</span>
</span>
<ul
start={1}
style={
Object {
"color": "#000",
Expand Down Expand Up @@ -478,7 +477,6 @@ exports[`List List component with inverse indentation 1`] = `
}
>
<ul
start={1}
style={
Object {
"color": "#000",
Expand Down Expand Up @@ -655,7 +653,6 @@ exports[`List List component with irregular indentation 1`] = `
}
>
<ul
start={1}
style={
Object {
"color": "#000",
Expand Down
31 changes: 25 additions & 6 deletions packages/obonode/obojobo-chunks-list/list-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ const getStyleWithDefaults = function(indent, defaultType, style = null) {
const styleWithDefaults = new ListStyle()

styleWithDefaults.type = style && style.type ? style.type : defaultType
styleWithDefaults.start = style && style.start !== null ? style.start : 1

if (style) {
if (style.type === 'ordered') {
styleWithDefaults.start = style && style.start !== null ? style.start : 1
} else {
styleWithDefaults.start = style.start
}
} else {
styleWithDefaults.start = 1
}

styleWithDefaults.bulletStyle =
style && style.bulletStyle
? style.bulletStyle
Expand All @@ -19,15 +29,24 @@ const getStyleWithDefaults = function(indent, defaultType, style = null) {
class ListStyle {
constructor(opts = {}) {
this.type = opts.type || null
this.start = opts.start || null
if (this.type !== 'unordered') {
this.start = opts.start || null
}
this.bulletStyle = opts.bulletStyle || null
}

toDescriptor() {
return {
type: this.type || null,
start: this.start || null,
bulletStyle: this.bulletStyle || null
if (this.type !== 'unordered') {
return {
type: this.type || null,
start: this.start || null,
bulletStyle: this.bulletStyle || null
}
} else {
return {
type: this.type,
bulletStyle: this.bulletStyle
}
}
}

Expand Down
42 changes: 33 additions & 9 deletions packages/obonode/obojobo-chunks-list/list-styles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ describe('List Styles', () => {
})
})

test('get retrives default values', () => {
test('get retrieves default values', () => {
const ls = new ListStyles()
ls.init()

expect(ls.get(0).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'disc'
})
})
Expand Down Expand Up @@ -119,43 +118,36 @@ describe('List Styles', () => {

expect(ls.get(0).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'disc'
})

expect(ls.get(1).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'circle'
})

expect(ls.get(2).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'square'
})

expect(ls.get(3).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'disc'
})

expect(ls.get(4).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'circle'
})

expect(ls.get(5).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'square'
})

expect(ls.get(6).toDescriptor()).toEqual({
type: 'unordered',
start: 1,
bulletStyle: 'disc'
})
})
Expand Down Expand Up @@ -298,4 +290,36 @@ describe('List Styles', () => {
expect(ls).not.toBe(other)
expect(ls.toDescriptor()).toEqual(other.toDescriptor())
})

test('all lists do not have a start attribute and are unordered as default', () => {
const ls = new ListStyles()
ls.init()

for (const indent in ls.styles) {
ls.get(indent)
expect(ls.type).toBe('unordered')
expect(ls.start).toBe(undefined)
}
})

test('all unordered lists do not have a start attribute', () => {
const ls = new ListStyles('unordered')
ls.init()

for (const indent in ls.styles) {
ls.get(indent)
expect(ls.type).toBe('unordered')
expect(ls.start).toBe(undefined)
}
})

test('all ordered lists do have a start attribute', () => {
const ls = new ListStyles('ordered')

for (const indent in ls.styles) {
ls.get(indent)
expect(ls.type).toBe('ordered')
expect(ls.start).toBe(true)
}
})
})