From 85d7ce3d98b78cbcc1a9d770a91b56b17f419e47 Mon Sep 17 00:00:00 2001 From: "Daniel W. Hieber" Date: Sun, 28 Jul 2024 16:55:33 -0500 Subject: [PATCH] NEW: Advanced Search: Option: Case-Sensitive (#182) #182 --- pages/Search/Search.test.js | 24 ++++++++++++------------ pages/Search/scripts/AdvancedSearch.js | 8 ++++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pages/Search/Search.test.js b/pages/Search/Search.test.js index f30e3418..a1c6ad15 100644 --- a/pages/Search/Search.test.js +++ b/pages/Search/Search.test.js @@ -46,7 +46,7 @@ describe(`Search`, function() { cy.get(`.num-results`).should(`have.text`, `Showing results 1–2 of 2.`) }) - it(`case insensitive (default)`, function() { + it(`Option: Case Sensitive (default)`, function() { cy.visit(`/search`) cy.get(`#search-box`).type(`ATIMW`) cy.get(`#quick-search-form`).submit() @@ -54,22 +54,23 @@ describe(`Search`, function() { cy.get(`#results tbody tr`).should(`have.length`, 2) }) - it(`case sensitive`, function() { + it(`Option: Case Sensitive (checked)`, function() { cy.visit(`/search`) cy.get(`#quick-case-sensitive-box`).check() cy.get(`#search-box`).type(`ATIMW`) cy.get(`#quick-search-form`).submit() cy.get(`.no-results`) + cy.get(`#quick-case-sensitive-box`).should(`be.checked`) }) - it(`diacritic-insensitive (default)`, function() { + it(`Option: Match Diacritics (default)`, function() { cy.visit(`/search`) cy.get(`#search-box`).type(`aštimw`) cy.get(`#quick-search-form`).submit() cy.get(`.num-results`).should(`include.text`, `of 9`) }) - it(`diacritic-sensitive`, function() { + it(`Option: Match Diacritics (checked)`, function() { cy.visit(`/search`) cy.get(`#diacritics-box`).check() cy.get(`#search-box`).type(`aštimw`) @@ -77,7 +78,7 @@ describe(`Search`, function() { cy.get(`.num-results`).should(`include.text`, `of 2`) }) - it(`regular expressions`, function() { + it(`Option: Regular Expressions (checked)`, function() { cy.visit(`/search`) cy.get(`#regex-box`).check() cy.get(`#search-box`).type(`e{{}2}`) // This is how you escape the `{` character in the `.type()` command. @@ -150,10 +151,12 @@ describe(`Search`, function() { it(`Settings`, function() { cy.visit(`/search`) + cy.get(`#quick-case-sensitive-box`).check() cy.get(`#diacritics-box`).check() cy.get(`#regex-box`).check() cy.get(`#quick-language-select`).select(`Cree_East`) cy.reload() + cy.get(`#quick-case-sensitive-box`).should(`be.checked`) cy.get(`#diacritics-box`).should(`be.checked`) cy.get(`#regex-box`).should(`be.checked`) cy.get(`#quick-language-select`).should(`have.value`, `Cree_East`) @@ -194,26 +197,28 @@ describe(`Search`, function() { cy.get(`.num-results`).should(`include.text`, `of 7`) }) - it(`case sensitive`, function() { + it(`Option: Case Sensitive`, function() { cy.visit(`/search`) cy.contains(`label`, `Advanced Search`).click() cy.get(`#advanced-case-sensitive-box`).check() cy.get(`#form-box`).type(`ATIMW`) cy.get(`#advanced-search-form`).submit() cy.get(`.no-results`) + cy.get(`#advanced-case-sensitive-box`).should(`be.checked`) }) it(`Settings`, function() { cy.visit(`/search`) cy.contains(`label`, `Advanced Search`).click() cy.get(`#advanced-language-select`).select(`Cree_East`) + cy.get(`#advanced-case-sensitive-box`).check() cy.reload() cy.get(`#advanced-language-select`).should(`have.value`, `Cree_East`) + cy.get(`#advanced-case-sensitive-box`).should(`be.checked`) }) }) - describe(`Pagination`, function() { it(`defaults`, function() { @@ -259,11 +264,6 @@ describe(`Search`, function() { .should(`have.text`, `-oʔooʔoe-`) }) - }) - - describe(`Settings`, function() { - - }) describe(`Sorting`, function() { diff --git a/pages/Search/scripts/AdvancedSearch.js b/pages/Search/scripts/AdvancedSearch.js index 600cea00..6ac4d1a0 100644 --- a/pages/Search/scripts/AdvancedSearch.js +++ b/pages/Search/scripts/AdvancedSearch.js @@ -6,13 +6,15 @@ export default class AdvancedSearch { * Hook onto DOM elements. */ constructor() { - this.language = document.getElementById(`advanced-language-select`) + this.caseSensitive = document.getElementById(`advanced-case-sensitive-box`) + this.language = document.getElementById(`advanced-language-select`) } /** * Add event listeners. */ listen() { + this.caseSensitive.addEventListener(`input`, this.save.bind(this)) this.language.addEventListener(`input`, this.save.bind(this)) } @@ -24,7 +26,8 @@ export default class AdvancedSearch { if (query.size && !(query.size === 1 && query.has(`advanced`))) return // Restore search settings - this.language.value = localStorage.getItem(`language`) + this.caseSensitive.checked = localStorage.getItem(`caseSensitive`) === `true` + this.language.value = localStorage.getItem(`language`) } @@ -32,6 +35,7 @@ export default class AdvancedSearch { * Save search settings. */ save() { + localStorage.setItem(`caseSensitive`, this.caseSensitive.checked) localStorage.setItem(`language`, this.language.value) }