import { haveText, html, test } from '../../utils'
test('basic drag sorting works',
[html`
`],
({ get }) => {
get('ul li').eq(0).should(haveText('foo'))
get('ul li').eq(1).should(haveText('bar'))
get('ul li').eq(2).should(haveText('baz'))
// Unfortunately, github actions doesn't like "async/await" here
// so we need to use .then() throughout this entire test...
get('#1').drag('#3').then(() => {
get('ul li').eq(0).should(haveText('bar'))
get('ul li').eq(1).should(haveText('baz'))
get('ul li').eq(2).should(haveText('foo'))
get('#3').drag('#1').then(() => {
get('ul li').eq(0).should(haveText('bar'))
get('ul li').eq(1).should(haveText('foo'))
get('ul li').eq(2).should(haveText('baz'))
})
})
},
)
test('can use a custom handle',
[html`
- handle - foo
- handle - bar
`],
({ get }) => {
get('ul li').eq(0).should(haveText('handle - foo'))
get('ul li').eq(1).should(haveText('handle - bar'))
get('#1 span').drag('#2').then(() => {
get('ul li').eq(0).should(haveText('handle - bar'))
get('ul li').eq(1).should(haveText('handle - foo'))
})
},
)
// Skipping this because it passes locally but not in CI...
test.skip('can move items between groups',
[html`
`],
({ get }) => {
get('ul li').eq(0).should(haveText('foo'))
get('ul li').eq(1).should(haveText('bar'))
get('ol li').eq(0).should(haveText('oof'))
get('ol li').eq(1).should(haveText('rab'))
get('#1').drag('#4').then(() => {
get('ul li').eq(0).should(haveText('bar'))
get('ol li').eq(0).should(haveText('oof'))
get('ol li').eq(1).should(haveText('foo'))
get('ol li').eq(2).should(haveText('rab'))
})
},
)
test('sort handle method',
[html`
`],
({ get }) => {
get('#1').drag('#3').then(() => {
get('h1').should(haveText('1-2'))
get('#3').drag('#1').then(() => {
get('h1').should(haveText('3-2'))
})
})
},
)
test('can access key and position in handler',
[html`
`],
({ get }) => {
get('#1').drag('#3').then(() => {
get('h1').should(haveText('2-1'))
get('#3').drag('#1').then(() => {
get('h1').should(haveText('2-3'))
})
})
},
)
test('can use custom sortablejs configuration',
[html`
`],
({ get }) => {
get('ul li').eq(0).should(haveText('foo'))
get('ul li').eq(1).should(haveText('bar'))
get('ul li').eq(2).should(haveText('baz'))
get('#1').drag('#3').then(() => {
get('ul li').eq(0).should(haveText('foo'))
get('ul li').eq(1).should(haveText('bar'))
get('ul li').eq(2).should(haveText('baz'))
get('#3').drag('#1').then(() => {
get('ul li').eq(0).should(haveText('baz'))
get('ul li').eq(1).should(haveText('foo'))
get('ul li').eq(2).should(haveText('bar'))
})
})
},
)
test('works with Livewire morphing',
[html`
`],
({ get }) => {
get('#1').drag('#3').then(() => {
// This is the easiest way I can think of to assert the order of HTML comments doesn't change...
get('ul').should('have.html', `\n \n \n bar\n baz\n \n foo`)
})
},
)