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.

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-07-09 08:55:56 +05:30
import htmlProjectsOverview from 'test_fixtures/projects/overview.html';
import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures';
2018-11-20 20:47:30 +05:30
import initReadMore from '~/read_more';
describe('Read more click-to-expand functionality', () => {
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(() => {
2023-07-09 08:55:56 +05:30
setHTMLFixture(htmlProjectsOverview);
2023-03-17 16:20:25 +05:30
});
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
});