debian-mirror-gitlab/spec/frontend/read_more_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-03-17 16:20:25 +05:30
import { loadHTMLFixture, resetHTMLFixture, setHTMLFixture } from 'helpers/fixtures';
2018-11-20 20:47:30 +05:30
import initReadMore from '~/read_more';
describe('Read more click-to-expand functionality', () => {
2019-07-07 11:18:12 +05:30
const fixtureName = 'projects/overview.html';
2018-11-20 20:47:30 +05:30
2023-03-17 16:20:25 +05:30
const findTrigger = () => document.querySelector('.js-read-more-trigger');
2022-07-16 23:28:13 +05:30
afterEach(() => {
resetHTMLFixture();
2018-11-20 20:47:30 +05:30
});
describe('expands target element', () => {
2023-03-17 16:20:25 +05:30
beforeEach(() => {
loadHTMLFixture(fixtureName);
});
2018-11-20 20:47:30 +05:30
it('adds "is-expanded" class to target element', () => {
const target = document.querySelector('.read-more-container');
2023-03-17 16:20:25 +05:30
const trigger = findTrigger();
2018-11-20 20:47:30 +05:30
initReadMore();
trigger.click();
expect(target.classList.contains('is-expanded')).toEqual(true);
});
});
2023-03-17 16:20:25 +05:30
describe('given click on nested element', () => {
beforeEach(() => {
setHTMLFixture(`
<p>Target</p>
<button type="button" class="js-read-more-trigger">
<span>Button text</span>
</button>
`);
const trigger = findTrigger();
const nestedElement = trigger.firstElementChild;
initReadMore();
nestedElement.click();
});
2023-06-20 00:43:36 +05:30
it('removes the trigger element', () => {
2023-03-17 16:20:25 +05:30
expect(findTrigger()).toBe(null);
});
});
2018-11-20 20:47:30 +05:30
});