Skip to content

Commit

Permalink
NEW: Advanced Search: Option: Case-Sensitive (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhieb committed Jul 28, 2024
1 parent 39a1b34 commit 85d7ce3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
24 changes: 12 additions & 12 deletions pages/Search/Search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,39 @@ 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()
cy.get(`.num-results`).should(`include.text`, 2)
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`)
cy.get(`#quick-search-form`).submit()
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.
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -259,11 +264,6 @@ describe(`Search`, function() {
.should(`have.text`, `-oʔooʔoe-`)
})

})

describe(`Settings`, function() {


})

describe(`Sorting`, function() {
Expand Down
8 changes: 6 additions & 2 deletions pages/Search/scripts/AdvancedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -24,14 +26,16 @@ 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`)

}

/**
* Save search settings.
*/
save() {
localStorage.setItem(`caseSensitive`, this.caseSensitive.checked)
localStorage.setItem(`language`, this.language.value)
}

Expand Down

0 comments on commit 85d7ce3

Please sign in to comment.