* Add JS tips section to frontend documentation
* Replace document.getElementsByTagName('body') with document.body
* Replace querySelectorAll with faster selecting methods where appropriate
* Replace querySelector with faster selecting methods where appropriate
* Fix typo
* Fix forEach and getElementsByClassName
* Change querySelector* to faster methods in erb files
* Change querySelector* to faster methods in ruby files
* Fix runkit tag
* Various fixes
* Update app/assets/javascripts/initializers/initializeEllipsisMenu.js
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
* Update app/assets/javascripts/utilities/slideSidebar.js
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
* Commenting out flaky spec
Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
import { Application } from 'stimulus';
|
|
import BufferController from '../../controllers/buffer_controller';
|
|
|
|
describe('BufferController', () => {
|
|
beforeEach(() => {
|
|
document.body.innerHTML = `<div data-controller="buffer">
|
|
<h2 data-target="buffer.header"></h2>
|
|
<button data-action="buffer#tagBufferUpdateConfirmed"></button>
|
|
<button data-action="buffer#tagBufferUpdateDismissed"></button>
|
|
<button data-action="buffer#highlightElement"></button>
|
|
</div>`;
|
|
|
|
const application = Application.start();
|
|
application.register('buffer', BufferController);
|
|
});
|
|
|
|
describe('#tagBufferUpdateConfirmed', () => {
|
|
it('adds a badge to the header', () => {
|
|
const button = document.getElementsByTagName('button')[0];
|
|
const header = document.getElementsByTagName('h2')[0];
|
|
|
|
button.click();
|
|
|
|
expect(header.firstChild.textContent).toMatch(/Confirm/);
|
|
});
|
|
});
|
|
|
|
describe('#tagBufferUpdateDismissed', () => {
|
|
it('adds a badge to the header', () => {
|
|
const button = document.getElementsByTagName('button')[1];
|
|
const header = document.getElementsByTagName('h2')[0];
|
|
|
|
button.click();
|
|
|
|
expect(header.firstChild.textContent).toMatch(/Dismiss/);
|
|
});
|
|
});
|
|
|
|
describe('#highlightElement', () => {
|
|
it('adds a class to the controller element', () => {
|
|
const button = document.getElementsByTagName('button')[2];
|
|
const element = document.querySelector("[data-controller='buffer']");
|
|
|
|
button.click();
|
|
|
|
expect(
|
|
element.classList.contains('bg-highlighted', 'border-highlighted'),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
});
|