Skip to content

Commit

Permalink
chore: change EOL to LF
Browse files Browse the repository at this point in the history
  • Loading branch information
dulerong committed Nov 23, 2021
1 parent 4e55789 commit 175a39b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 82 deletions.
138 changes: 69 additions & 69 deletions app/javascript/adminterface/lib/__tests__/detached_dropdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import DetachedDropdownClass from '../detached_dropdown'

describe('DetachedDropdown', () => {
const element = document.createElement('div')
const options = {
title: '.title-menu'
}

beforeEach(() => {
global.adminterface = {
addObserver: jest.fn()
}
})

test('constructor initiates properties and call bind correctly', () => {
const spyOnBind = jest.spyOn(DetachedDropdownClass.prototype, '_bind')
spyOnBind.mockImplementation(() => {})
const DetachedDropdown = new DetachedDropdownClass(element, options)

expect(DetachedDropdown.element).toEqual(element)
expect(DetachedDropdown.options).toEqual({
menu: '.dropdown-menu',
...options
})
expect(spyOnBind).toHaveBeenCalledTimes(1)
spyOnBind.mockRestore()
})

test('bind method calls adminterface correctly', () => {
const DetachedDropdown = new DetachedDropdownClass(element, options)

expect(global.adminterface.addObserver).toHaveBeenCalledWith(
element,
DetachedDropdown,
DetachedDropdown.constructor.name
)
})

test('bind method add event listener correctly', () => {
const DetachedDropdown = new DetachedDropdownClass(element, options)
const spyOnAddEventListener = jest.spyOn(
DetachedDropdown.element,
'addEventListener'
)
DetachedDropdown._bind()

expect(spyOnAddEventListener).toHaveBeenCalledTimes(2)
expect(spyOnAddEventListener.mock.calls).toEqual([
['show.bs.dropdown', expect.any(Function)],
['hidden.bs.dropdown', expect.any(Function)]
])
})

test('append method calls native WEB API append correctly', () => {
const testDiv = document.createElement('div')
const testP = document.createElement('p')
testDiv.append('Some text', testP)

const DetachedDropdown = new DetachedDropdownClass(element, options)
const spyOnAppend = jest.spyOn(document.body, 'append')

DetachedDropdown._append(document.body, testP)

expect(spyOnAppend).toHaveBeenCalledTimes(1)
expect(spyOnAppend).toHaveBeenCalledWith(
testP.parentElement.removeChild(testP)
)
})
})
import DetachedDropdownClass from '../detached_dropdown'

describe('DetachedDropdown', () => {
const element = document.createElement('div')
const options = {
title: '.title-menu'
}

beforeEach(() => {
global.adminterface = {
addObserver: jest.fn()
}
})

test('constructor initiates properties and call bind correctly', () => {
const spyOnBind = jest.spyOn(DetachedDropdownClass.prototype, '_bind')
spyOnBind.mockImplementation(() => {})
const DetachedDropdown = new DetachedDropdownClass(element, options)

expect(DetachedDropdown.element).toEqual(element)
expect(DetachedDropdown.options).toEqual({
menu: '.dropdown-menu',
...options
})
expect(spyOnBind).toHaveBeenCalledTimes(1)
spyOnBind.mockRestore()
})

test('bind method calls adminterface correctly', () => {
const DetachedDropdown = new DetachedDropdownClass(element, options)

expect(global.adminterface.addObserver).toHaveBeenCalledWith(
element,
DetachedDropdown,
DetachedDropdown.constructor.name
)
})

test('bind method add event listener correctly', () => {
const DetachedDropdown = new DetachedDropdownClass(element, options)
const spyOnAddEventListener = jest.spyOn(
DetachedDropdown.element,
'addEventListener'
)
DetachedDropdown._bind()

expect(spyOnAddEventListener).toHaveBeenCalledTimes(2)
expect(spyOnAddEventListener.mock.calls).toEqual([
['show.bs.dropdown', expect.any(Function)],
['hidden.bs.dropdown', expect.any(Function)]
])
})

test('append method calls native WEB API append correctly', () => {
const testDiv = document.createElement('div')
const testP = document.createElement('p')
testDiv.append('Some text', testP)

const DetachedDropdown = new DetachedDropdownClass(element, options)
const spyOnAppend = jest.spyOn(document.body, 'append')

DetachedDropdown._append(document.body, testP)

expect(spyOnAppend).toHaveBeenCalledTimes(1)
expect(spyOnAppend).toHaveBeenCalledWith(
testP.parentElement.removeChild(testP)
)
})
})
26 changes: 13 additions & 13 deletions app/javascript/adminterface/lib/__tests__/has_many.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div data-sortable="address">
<form class="has-many-list">
<fieldset class="has_many_fields">
<input type="checkbox" name="[_destroy]" checked>
<input type="text" name="[address]" value="Tokyo">
<a class="button has_many_remove"></a>
<a
class="button has_many_add"
data-html="<div></div>"
data-placeholder="script"
></a>
</fieldset>
</form>
<div data-sortable="address">
<form class="has-many-list">
<fieldset class="has_many_fields">
<input type="checkbox" name="[_destroy]" checked>
<input type="text" name="[address]" value="Tokyo">
<a class="button has_many_remove"></a>
<a
class="button has_many_add"
data-html="<div></div>"
data-placeholder="script"
></a>
</fieldset>
</form>
</div>

0 comments on commit 175a39b

Please sign in to comment.