* 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>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
import { Application } from 'stimulus';
|
|
import ArticleController from '../../controllers/article_controller';
|
|
|
|
describe('ArticleController', () => {
|
|
beforeEach(() => {
|
|
document.body.innerHTML = `<div data-controller="article">
|
|
<div class="card-body">
|
|
<button data-action="article#increaseFeaturedNumber"></button>
|
|
<button data-action="article#decreaseFeaturedNumber"></button>
|
|
<button data-action="article#highlightElement"></button>
|
|
<input data-target="article.featuredNumber"></input>
|
|
</div>
|
|
</div>`;
|
|
|
|
const application = Application.start();
|
|
application.register('article', ArticleController);
|
|
});
|
|
|
|
// Unix timestamp, one hour ago
|
|
const initialValue = Math.round((Date.now() - 3600000) / 1000);
|
|
|
|
describe('#increaseFeaturedNumber', () => {
|
|
it('increases the featured number input', () => {
|
|
const button = document.getElementsByTagName('button')[0];
|
|
const input = document.querySelector(
|
|
"[data-target='article.featuredNumber']",
|
|
);
|
|
|
|
input.value = initialValue;
|
|
button.click();
|
|
|
|
expect(parseInt(input.value, 10)).toBeGreaterThan(initialValue);
|
|
});
|
|
});
|
|
|
|
describe('#decreaseFeaturedNumber', () => {
|
|
it('increases the featured number input', () => {
|
|
const button = document.getElementsByTagName('button')[1];
|
|
const input = document.querySelector(
|
|
"[data-target='article.featuredNumber']",
|
|
);
|
|
|
|
input.value = initialValue;
|
|
button.click();
|
|
|
|
expect(parseInt(input.value, 10)).toBeLessThan(initialValue);
|
|
});
|
|
});
|
|
|
|
describe('#highlightElement', () => {
|
|
it('adds a class to the controller element', () => {
|
|
const button = document.getElementsByTagName('button')[2];
|
|
const element = document.getElementsByClassName('card-body')[0];
|
|
|
|
button.click();
|
|
|
|
expect(
|
|
element.classList.contains('bg-highlighted', 'border-highlighted'),
|
|
).toBe(true);
|
|
});
|
|
});
|
|
});
|