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

Renamed index.ts to getIndex.ts #557

Merged
merged 3 commits into from
Aug 20, 2020
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
14 changes: 7 additions & 7 deletions __tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('Testing api', () => {
})

test('should have a data-opts object', () => {
expect(typeof sortable.__testing._data(ul, 'opts')).toBe('object')
expect(typeof sortable.__testing.data(ul, 'opts')).toBe('object')
})

test('should have correct options set on options object', () => {
const opts = sortable.__testing._data(ul, 'opts')
const opts = sortable.__testing.data(ul, 'opts')
expect(opts.items).toEqual('li')
expect(opts.placeholderClass).toEqual('test-placeholder')
expect(opts.draggingClass).toEqual('test-dragging')
Expand All @@ -45,7 +45,7 @@ describe('Testing api', () => {
})

test('should have a data-items object', () => {
expect(typeof sortable.__testing._data(ul, 'items')).toBe('string')
expect(typeof sortable.__testing.data(ul, 'items')).toBe('string')
})

test('should have aria-grabbed attributes', () => {
Expand Down Expand Up @@ -83,15 +83,15 @@ describe('Testing api', () => {
})

test('should not have a data-opts object', () => {
expect(typeof sortable.__testing._data(ul, 'opts')).toBe('undefined')
expect(typeof sortable.__testing.data(ul, 'opts')).toBe('undefined')
})

test('should not have a aria-dropeffect attribute', () => {
expect(ul.getAttribute('aria-dropeffect')).toBeNull()
})

test('should not have a data-items object', () => {
expect(sortable.__testing._data(ul, 'items')).not.toBeDefined()
expect(sortable.__testing.data(ul, 'items')).not.toBeDefined()
})

test('should not have an aria-grabbed attribute', () => {
Expand All @@ -117,13 +117,13 @@ describe('Testing api', () => {
})

test('should keep the options of the sortable', () => {
const opts = sortable.__testing._data(ul, 'opts')
const opts = sortable.__testing.data(ul, 'opts')
expect(opts.items).toEqual('li:not(.disabled)')
expect(opts.placeholderClass).toEqual('test-placeholder')
})

test('should keep items attribute of the sortable', () => {
const items = sortable.__testing._data(ul, 'items')
const items = sortable.__testing.data(ul, 'items')
expect(items).toEqual('li:not(.disabled)')
})
})
Expand Down
18 changes: 9 additions & 9 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* global describe,test,expect */
/* eslint-env jest */

import index from '../src/index'
import getIndex from '../src/getIndex'

describe('Testing index', () => {
test('element is undefined', () => {
// setup
const div = window.document.createElement('div')
// assert
expect(() => { index(undefined, div) }).toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(undefined, div) }).toThrow('You must provide an element and a list of elements.')
})

test('elementList is not a valid list', () => {
// setup
const div = window.document.createElement('div')
const div2 = window.document.createElement('div')
// assert
expect(() => { index(div, div2) }).toThrow('You must provide an element and a list of elements.')
expect(() => { index(div, undefined) }).toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(div, div2) }).toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(div, undefined) }).toThrow('You must provide an element and a list of elements.')
})

test('elementList is a nodelist', () => {
Expand All @@ -26,21 +26,21 @@ describe('Testing index', () => {
div.innerHTML = '<div></div>'
const nodeList = div.querySelectorAll('div')
// assert
expect(() => { index(div, nodeList) }).not.toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(div, nodeList) }).not.toThrow('You must provide an element and a list of elements.')
})

test('elementList is a HTMLCollection', () => {
// setup
const div = window.document.createElement('div')
// assert
expect(() => { index(div, document.links) }).not.toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(div, document.links) }).not.toThrow('You must provide an element and a list of elements.')
})

test('elementList is an Array', () => {
// setup
const div = window.document.createElement('div')
// assert
expect(() => { index(div, []) }).not.toThrow('You must provide an element and a list of elements.')
expect(() => { getIndex(div, []) }).not.toThrow('You must provide an element and a list of elements.')
})

test('element is child of div', () => {
Expand All @@ -53,7 +53,7 @@ describe('Testing index', () => {
div.appendChild(span)
div.appendChild(child2)
// assert
expect(index(child1, div.children)).toEqual(0)
expect(index(child2, div.querySelectorAll('div'))).toEqual(1)
expect(getIndex(child1, div.children)).toEqual(0)
expect(getIndex(child2, div.querySelectorAll('div'))).toEqual(1)
})
})
2 changes: 1 addition & 1 deletion __tests__/sortableMethodsTests/_removeItemData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('_removeItemData', () => {
sortable(ul, {
items: 'li'
})
sortable.__testing._removeItemData(li)
sortable.__testing.removeItemData(li)
expect(li.getAttribute('role')).toBeNull()
expect(li.getAttribute('draggable')).toBeNull()
expect(li.getAttribute('aria-grabbed')).toBeNull()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/sortableMethodsTests/_removeItemEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('_removeItemEvents', () => {
expect(typeof store(li).getData('eventdragover')).toBe('function')
expect(typeof store(li).getData('eventdragenter')).toBe('function')
// remove item events
sortable.__testing._removeItemEvents(li)
sortable.__testing.removeItemEvents(li)
// assert
expect(typeof store(li).getData('eventdragover')).toBe('undefined')
expect(typeof store(li).getData('eventdragenter')).toBe('undefined')
Expand Down
10 changes: 5 additions & 5 deletions __tests__/throttle.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* global describe,test,expect */
/* eslint-env jest */
import _throttle from '../src/throttle'
import throttle from '../src/throttle'

describe('Testing throttle', () => {
test('throttle should not allow functions to be called multiple times within the timeframe', () => {
let value = 0
const fn = _throttle(() => {
const fn = throttle(() => {
value++
})
// call function twice immeditatly
Expand All @@ -17,7 +17,7 @@ describe('Testing throttle', () => {

test('throttle should allow functions to be called multiple times after the timeframe', () => {
let value = 0
const fn = _throttle(() => {
const fn = throttle(() => {
value++
}, 10)
// call function twice immeditatly
Expand All @@ -31,11 +31,11 @@ describe('Testing throttle', () => {

test('throttle should fail if no functin is provided', () => {
// assert
expect(() => { _throttle('test', 10) }).toThrowError('You must provide a function as the first argument for throttle.')
expect(() => { throttle('test', 10) }).toThrowError('You must provide a function as the first argument for throttle.')
})

test('throttle should fail if threshold is not a number', () => {
// assert
expect(() => { _throttle(() => { }, '10') }).toThrowError('You must provide a number as the second argument for throttle.')
expect(() => { throttle(() => { }, '10') }).toThrowError('You must provide a number as the second argument for throttle.')
})
})
Loading