2021-01-14 19:10:45 -05:00
|
|
|
import { setHTMLFixture } from 'helpers/fixtures';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2019-11-25 13:06:04 -05:00
|
|
|
import { updateElementsVisibility, updateFormAction } from '~/repository/utils/dom';
|
2019-11-12 13:06:57 -05:00
|
|
|
|
|
|
|
describe('updateElementsVisibility', () => {
|
|
|
|
it('adds hidden class', () => {
|
|
|
|
setHTMLFixture('<div class="js-test"></div>');
|
|
|
|
|
|
|
|
updateElementsVisibility('.js-test', false);
|
|
|
|
|
|
|
|
expect(document.querySelector('.js-test').classList).toContain('hidden');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('removes hidden class', () => {
|
|
|
|
setHTMLFixture('<div class="hidden js-test"></div>');
|
|
|
|
|
|
|
|
updateElementsVisibility('.js-test', true);
|
|
|
|
|
|
|
|
expect(document.querySelector('.js-test').classList).not.toContain('hidden');
|
|
|
|
});
|
|
|
|
});
|
2019-11-25 13:06:04 -05:00
|
|
|
|
|
|
|
describe('updateFormAction', () => {
|
2020-02-10 10:08:54 -05:00
|
|
|
it.each`
|
|
|
|
path
|
|
|
|
${'/test'}
|
|
|
|
${'test'}
|
|
|
|
${'/'}
|
|
|
|
`('updates form action for $path', ({ path }) => {
|
2019-11-25 13:06:04 -05:00
|
|
|
setHTMLFixture('<form class="js-test" action="/"></form>');
|
|
|
|
|
2020-02-10 10:08:54 -05:00
|
|
|
updateFormAction('.js-test', '/gitlab/create', path);
|
2019-11-25 13:06:04 -05:00
|
|
|
|
2020-02-10 10:08:54 -05:00
|
|
|
expect(document.querySelector('.js-test').action).toBe(
|
2020-07-10 05:09:01 -04:00
|
|
|
`${TEST_HOST}/gitlab/create/${path.replace(/^\//, '')}`,
|
2020-02-10 10:08:54 -05:00
|
|
|
);
|
2019-11-25 13:06:04 -05:00
|
|
|
});
|
|
|
|
});
|