2020-10-24 23:57:45 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2019-12-26 22:10:19 +05:30
|
|
|
import { setHTMLFixture } from '../../helpers/fixtures';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { updateElementsVisibility, updateFormAction } from '~/repository/utils/dom';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
});
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
describe('updateFormAction', () => {
|
2020-03-13 15:44:24 +05:30
|
|
|
it.each`
|
|
|
|
path
|
|
|
|
${'/test'}
|
|
|
|
${'test'}
|
|
|
|
${'/'}
|
|
|
|
`('updates form action for $path', ({ path }) => {
|
2020-01-01 13:55:28 +05:30
|
|
|
setHTMLFixture('<form class="js-test" action="/"></form>');
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
updateFormAction('.js-test', '/gitlab/create', path);
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(document.querySelector('.js-test').action).toBe(
|
2020-07-28 23:09:34 +05:30
|
|
|
`${TEST_HOST}/gitlab/create/${path.replace(/^\//, '')}`,
|
2020-03-13 15:44:24 +05:30
|
|
|
);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
});
|