linting, js test troubleshooting

This commit is contained in:
wrenny-ko 2024-08-27 17:26:59 -04:00
parent a4cad4e534
commit c361118472
2 changed files with 22 additions and 1 deletions

View file

@ -58,6 +58,8 @@ describe('Image upload form', () => {
let scraperError: HTMLDivElement; let scraperError: HTMLDivElement;
let fetchButton: HTMLButtonElement; let fetchButton: HTMLButtonElement;
let tagsEl: HTMLTextAreaElement; let tagsEl: HTMLTextAreaElement;
let tagsinputEl: HTMLDivElement;
let tagEl: HTMLSpanElement;
let sourceEl: HTMLInputElement; let sourceEl: HTMLInputElement;
let descrEl: HTMLTextAreaElement; let descrEl: HTMLTextAreaElement;
@ -77,6 +79,18 @@ describe('Image upload form', () => {
<input id="image_sources_0_source" name="image[sources][0][source]" type="text" class="js-source-url" /> <input id="image_sources_0_source" name="image[sources][0][source]" type="text" class="js-source-url" />
<textarea id="image_tag_input" name="image[tag_input]" class="js-image-tags-input"></textarea> <textarea id="image_tag_input" name="image[tag_input]" class="js-image-tags-input"></textarea>
<div class="js-taginput">
<span class="tag">
"safe x"
</span>
<span class="tag">
"pony x"
</span>
<span class="tag">
"tag3 x"
</span>
</div>
<button id="tagsinput-save" type="button" class="button"/>
<textarea id="image_description" name="image[description]" class="js-image-descr-input"></textarea> <textarea id="image_description" name="image[description]" class="js-image-descr-input"></textarea>
</form>`, </form>`,
); );
@ -87,6 +101,8 @@ describe('Image upload form', () => {
remoteUrl = assertNotUndefined($$<HTMLInputElement>('.js-scraper')[1]); remoteUrl = assertNotUndefined($$<HTMLInputElement>('.js-scraper')[1]);
scraperError = assertNotUndefined($$<HTMLInputElement>('.js-scraper')[2]); scraperError = assertNotUndefined($$<HTMLInputElement>('.js-scraper')[2]);
tagsEl = assertNotNull($<HTMLTextAreaElement>('.js-image-tags-input')); tagsEl = assertNotNull($<HTMLTextAreaElement>('.js-image-tags-input'));
tagsinputEl = assertNotNull($<HTMLDivElement>('.js-taginput'));
tagEl = assertNotNull($<HTMLSpanElement>('.tag')); // ensure at least one exists
sourceEl = assertNotNull($<HTMLInputElement>('.js-source-url')); sourceEl = assertNotNull($<HTMLInputElement>('.js-source-url'));
descrEl = assertNotNull($<HTMLTextAreaElement>('.js-image-descr-input')); descrEl = assertNotNull($<HTMLTextAreaElement>('.js-image-descr-input'));
fetchButton = assertNotNull($<HTMLButtonElement>('#js-scraper-preview')); fetchButton = assertNotNull($<HTMLButtonElement>('#js-scraper-preview'));

View file

@ -174,12 +174,13 @@ function setupImageUpload() {
function createTagError(message) { function createTagError(message) {
const buttonAfter = $('#tagsinput-save'); const buttonAfter = $('#tagsinput-save');
const errorElement = makeEl('span', { className: 'help-block tag-error' }); const errorElement = makeEl('span', { className: 'help-block tag-error' });
errorElement.innerText = message; errorElement.innerText = message;
buttonAfter.parentElement.insertBefore(errorElement, buttonAfter); buttonAfter.parentElement.insertBefore(errorElement, buttonAfter);
} }
function clearTagErrors() { function clearTagErrors() {
const tagErrorElements = document.getElementsByClassName('tag-error'); const tagErrorElements = $$('.tag-error');
// remove() causes the length to decrease // remove() causes the length to decrease
while (tagErrorElements.length > 0) { while (tagErrorElements.length > 0) {
@ -192,14 +193,17 @@ function setupImageUpload() {
// return false if any check fails // return false if any check fails
function validateTags() { function validateTags() {
const tags = $$('.tag'); const tags = $$('.tag');
if (tags.length === 0) { if (tags.length === 0) {
createTagError('Tag input must contain at least 3 tags'); createTagError('Tag input must contain at least 3 tags');
return false; return false;
} }
const tagsArr = []; const tagsArr = [];
for (const i in tags) { for (const i in tags) {
let tag = tags[i].innerText; let tag = tags[i].innerText;
tag = tag.substring(0, tag.length - 2); // remove " x" from the end tag = tag.substring(0, tag.length - 2); // remove " x" from the end
tagsArr.push(tag); tagsArr.push(tag);
} }
@ -211,6 +215,7 @@ function setupImageUpload() {
let hasRating = false; let hasRating = false;
let hasSafe = false; let hasSafe = false;
let hasOtherRating = false; let hasOtherRating = false;
tagsArr.forEach(tag => { tagsArr.forEach(tag => {
if (ratingsTags.includes(tag)) { if (ratingsTags.includes(tag)) {
hasRating = true; hasRating = true;