import { beChecked, contain, notBeChecked, haveAttribute, haveData, haveText, test, beVisible, notBeVisible, html } from '../../utils'
test('data modified in event listener updates affected attribute bindings',
html`
`,
({ get }) => {
get('span').should(haveAttribute('foo', 'bar'))
get('button').click()
get('span').should(haveAttribute('foo', 'baz'))
}
)
test('can call a method without parenthesis',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('lob'))
}
)
test('event object is not passed if other params are present',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('foo'))
}
)
test('nested data modified in event listener updates affected attribute bindings',
html`
`,
({ get }) => {
get('span').should(haveAttribute('foo', 'bar'))
get('button').click()
get('span').should(haveAttribute('foo', 'baz'))
}
)
test('.passive modifier should disable e.preventDefault()',
html`
`,
({ get }) => {
get('button').click()
get('div').should(haveData('defaultPrevented', false))
}
)
test('.stop modifier',
html`
h1
h2
`,
({ get }) => {
get('div').should(haveData('foo', 'bar'))
get('h2').click()
get('div').should(haveData('foo', 'bar'))
get('h1').click()
get('div').should(haveData('foo', 'baz'))
}
)
test('.stop modifier with a .throttle',
html`
h1
h2
`,
({ get }) => {
get('div').should(haveData('foo', 'bar'))
get('h2').click()
get('h2').click()
get('div').should(haveData('foo', 'bar'))
get('h1').click()
get('div').should(haveData('foo', 'baz'))
}
)
test('.capture modifier',
html`
h1
h2
`,
({ get }) => {
get('div').should(haveData('foo', 'bar'))
get('h2').click()
get('div').should(haveData('foo', 'bob'))
get('div').should(haveData('count', 1))
}
)
test('.capture modifier with @keyup',
html`
`,
({ get }) => {
get('div').should(haveData('foo', 'bar'))
get('input').type('f')
get('div').should(haveData('foo', 'input'))
get('div').should(haveData('count', 1))
}
)
test('.capture modifier with @keyup and specified key',
html`
`,
({ get }) => {
get('div').should(haveData('foo', 'bar'))
get('input').type('{enter}')
get('div').should(haveData('foo', 'input'))
get('div').should(haveData('count', 1))
}
)
test('.self modifier',
html`
content
click
content
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('bar'))
get('h1').click()
get('span').should(haveText('baz'))
}
)
test(
".self.once modifiers",
html`
content
click
content
`,
({ get }) => {
get("span").should(haveText("bar"));
get("button").click();
get("span").should(haveText("bar"));
get("h1").click();
get("span").should(haveText("baz"));
}
);
test('.prevent modifier',
html`
`,
({ get }) => {
get('input').check()
get('input').should(notBeChecked())
}
)
test('.prevent modifier with a .debounce',
html`
`,
({ get }) => {
get('input').check()
get('input').check()
get('input').should(notBeChecked())
}
)
test('.window modifier',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('span').click()
get('span').should(haveText('baz'))
}
)
test('expressions can start with if',
html`
click
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('unbind global event handler when element is removed',
html`
`,
({ get }) => {
get('button').click()
get('span').click()
get('span').should(haveText('1'))
}
)
test('.document modifier',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('span').click()
get('span').should(haveText('baz'))
}
)
test('.once modifier',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('button').click()
get('span').should(haveText('1'))
get('button').click()
get('span').should(haveText('1'))
}
)
test('.once modifier with @keyup',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('1'))
get('input').type('o')
get('span').should(haveText('1'))
}
)
test('.once modifier with @keyup and specified key',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('0'))
get('input').type('{enter}')
get('span').should(haveText('1'))
get('input').type('{enter}')
get('span').should(haveText('1'))
}
)
test('.debounce modifier',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('1'))
get('input').type('ffffffffffff')
get('span').should(haveText('2'))
}
)
test('.throttle modifier',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('1'))
get('input').type('ffffffffffff')
get('span').should(haveText('1'))
}
)
test('keydown modifiers',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('1'))
get('input').type('{enter}')
get('span').should(haveText('3'))
get('input').type(' ')
get('span').should(haveText('5'))
get('input').type('{leftarrow}')
get('span').should(haveText('7'))
get('input').type('{rightarrow}')
get('span').should(haveText('9'))
get('input').type('{uparrow}')
get('span').should(haveText('11'))
get('input').type('{downarrow}')
get('span').should(haveText('13'))
get('input').type('{meta}')
get('span').should(haveText('16'))
get('input').type('{esc}')
get('span').should(haveText('19'))
get('input').type('{ctrl}')
get('span').should(haveText('21'))
get('input').type('/')
get('span').should(haveText('23'))
get('input').type('=')
get('span').should(haveText('25'))
get('input').type('.')
get('span').should(haveText('27'))
get('input').type(',')
get('span').should(haveText('29'))
}
)
test('discerns between space minus underscore',
html`
`,
({get}) => {
get('span').should(haveText('0'))
get('#space').type(' ')
get('span').should(haveText('1'))
get('#space').type('-')
get('span').should(haveText('1'))
get('#minus').type('-')
get('span').should(haveText('2'))
get('#minus').type(' ')
get('span').should(haveText('2'))
get('#underscore').type('_')
get('span').should(haveText('3'))
get('#underscore').type(' ')
get('span').should(haveText('3'))
})
test('keydown combo modifiers',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('0'))
get('input').type('{cmd}{enter}')
get('span').should(haveText('1'))
}
)
test('keydown with specified key and stop modifier only stops for specified key',
html`
`,
({ get }) => {
get('span').should(haveText('0'))
get('input').type('f')
get('span').should(haveText('1'))
get('input').type('{enter}')
get('span').should(haveText('1'))
}
)
test('@click.away',
html`
h1
h2
`,
({ get }) => {
get('span').should(haveText('bar'))
get('h1').click()
get('span').should(haveText('bar'))
get('h2').click()
get('span').should(haveText('baz'))
}
)
test('@click.away.once works after clicking inside',
html`
h1
h2
`,
({ get }) => {
get('span').should(haveText('bar'))
get('h1').click()
get('span').should(haveText('bar'))
get('h2').click()
get('span').should(haveText('baz'))
}
)
test('@click.away with x-show (prevent race condition)',
html`
Show
h1
h2
`,
({ get }) => {
get('h1').should(notBeVisible())
get('button').click()
get('h1').should(beVisible())
}
)
test('event with colon',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('event instance can be passed to method reference',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('.camel modifier correctly binds event listener',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('.camel modifier correctly binds event listener with namespace',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('.dot modifier correctly binds event listener',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('underscores are allowed in event names',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('.dot modifier correctly binds event listener with namespace',
html`
`,
({ get }) => {
get('span').should(haveText('bar'))
get('button').click()
get('span').should(haveText('baz'))
}
)
test('handles await in handlers with invalid right hand expressions',
html`
`,
({ get }) => {
get('span').should(haveText('original'))
get('button').click()
get('span').should(haveText('new string'))
}
)
test(
"handles system modifier keys on key events",
html`
keys[key] = false)"
@keydown.meta.space="keys.meta = true"
@keydown.ctrl.space="keys.ctrl = true"
@keydown.shift.space="keys.shift = true"
@keydown.alt.space="keys.alt = true"
@keydown.cmd.space="keys.cmd = true"
/>
`,({ get }) => {
get("input[name=shift]").as('shift').should(notBeChecked());
get("input[name=ctrl]").as('ctrl').should(notBeChecked());
get("input[name=meta]").as('meta').should(notBeChecked());
get("input[name=alt]").as('alt').should(notBeChecked());
get("input[name=cmd]").as('cmd').should(notBeChecked());
get("input[type=text]").as('input').trigger("keydown", { key: 'space', shiftKey: true });
get('@shift').should(beChecked());
get("@input").trigger("keydown", { key: 'space', ctrlKey: true });
get("@shift").should(notBeChecked());
get("@ctrl").should(beChecked());
get("@input").trigger("keydown", { key: 'space', metaKey: true });
get("@ctrl").should(notBeChecked());
get("@meta").should(beChecked());
get("@cmd").should(beChecked());
get("@input").trigger("keydown", { key: 'space', altKey: true });
get("@meta").should(notBeChecked());
get("@cmd").should(notBeChecked());
get("@alt").should(beChecked());
get("@input").trigger("keydown", { key: 'space' });
get("@alt").should(notBeChecked());
get("@input").trigger("keydown", { key: 'space',
ctrlKey: true, shiftKey: true, metaKey: true, altKey: true });
get("input[name=shift]").as("shift").should(beChecked());
get("input[name=ctrl]").as("ctrl").should(beChecked());
get("input[name=meta]").as("meta").should(beChecked());
get("input[name=alt]").as("alt").should(beChecked());
get("input[name=cmd]").as("cmd").should(beChecked());
}
);
test(
"handles system modifier keys on mouse events",
html`
keys[key] = false)"
@click.shift="keys.shift = true"
@click.ctrl="keys.ctrl = true"
@click.meta="keys.meta = true"
@click.alt="keys.alt = true"
@click.cmd="keys.cmd = true">
change
`,({ get }) => {
get("input[name=shift]").as('shift').should(notBeChecked());
get("input[name=ctrl]").as('ctrl').should(notBeChecked());
get("input[name=meta]").as('meta').should(notBeChecked());
get("input[name=alt]").as('alt').should(notBeChecked());
get("input[name=cmd]").as('cmd').should(notBeChecked());
get("button").as('button').trigger("click", { shiftKey: true });
get('@shift').should(beChecked());
get("@button").trigger("click", { ctrlKey: true });
get("@shift").should(notBeChecked());
get("@ctrl").should(beChecked());
get("@button").trigger("click", { metaKey: true });
get("@ctrl").should(notBeChecked());
get("@meta").should(beChecked());
get("@cmd").should(beChecked());
get("@button").trigger("click", { altKey: true });
get("@meta").should(notBeChecked());
get("@cmd").should(notBeChecked());
get("@alt").should(beChecked());
get("@button").trigger("click", {});
get("@alt").should(notBeChecked());
get("@button").trigger("click", { ctrlKey: true, shiftKey: true, metaKey: true, altKey: true });
get("@shift").as("shift").should(beChecked());
get("@ctrl").as("ctrl").should(beChecked());
get("@meta").as("meta").should(beChecked());
get("@alt").as("alt").should(beChecked());
get("@cmd").as("cmd").should(beChecked());
}
);
test(
"handles all mouse events with modifiers",
html`
keys[key] = false)"
@contextmenu.prevent.shift="keys.shift = true"
@auxclick.ctrl="keys.ctrl = true"
@dblclick.meta="keys.meta = true"
@mouseenter.alt="keys.alt = true"
@mousemove.cmd="keys.cmd = true">
change
`,({ get }) => {
get("input[name=shift]").as('shift').should(notBeChecked());
get("input[name=ctrl]").as('ctrl').should(notBeChecked());
get("input[name=meta]").as('meta').should(notBeChecked());
get("input[name=alt]").as('alt').should(notBeChecked());
get("input[name=cmd]").as('cmd').should(notBeChecked());
get("button").as('button').trigger("contextmenu", { shiftKey: true });
get('@shift').should(beChecked());
get("@button").trigger("click");
get("@button").trigger("auxclick", { ctrlKey: true });
get("@shift").should(notBeChecked());
get("@ctrl").should(beChecked());
get("@button").trigger("click");
get("@button").trigger("dblclick", { metaKey: true });
get("@ctrl").should(notBeChecked());
get("@meta").should(beChecked());
get("@button").trigger("click");
get("@button").trigger("mouseenter", { altKey: true });
get("@meta").should(notBeChecked());
get("@alt").should(beChecked());
get("@button").trigger("click");
get("@button").trigger("mousemove", { metaKey: true });
get("@alt").should(notBeChecked());
get("@cmd").should(beChecked());
}
);