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 4 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
28 changes: 19 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,22 @@ describe('List Styles', () => {
expect(ls).not.toBe(other)
expect(ls.toDescriptor()).toEqual(other.toDescriptor())
})

test('all unordered lists dont have a start attribute', () => {
const ls = new ListStyles()
ls.init()
if (ls.type === 'unordered') {
Copy link
Contributor

@FrenjaminBanklin FrenjaminBanklin Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the expectation for ls.type to be one or the other, these conditions are unnecessary. In a worst-case scenario, not that I know how this might happen, this conditional could allow the test to pass even if the expectations are not met, since the expectations might not be checked at all.

Also this is just nitpicking, but if unordered is the default behavior, I would keep a test where it is not set (to make sure it's the default behavior) and also a separate test explicitly setting 'unordered' to make sure everything still reacts properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made these changes and took a closer look at the unit test for ordered which was filing with the removal of the condition. I learned ls.init() sets the style to unordered so I removed this line. I added ls.get(indent) as it calls other functions that seem to set up the list including adding the start attribute if it is ordered. I think this function would be called to create a list with defaults so I think it is a better way to test that these three unit tests function properly.
A start attribute is not automatically added when const ls = new ListStyles('ordered') is created so this test was failing before I called ls.get(indent) which returns getStyleWithDefaults(indent, this.type, this.styles[indent]) as seen in list-styles.js

expect(ls.type).toBe('unordered')
expect(ls.start).toBe(undefined)
}
})

test('all ordered lists do have a start attribute', () => {
const ls = new ListStyles('ordered')
ls.init()
if (ls.type === 'ordered') {
expect(ls.type).toBe('ordered')
expect(ls.start).toBe(true)
}
})
})