Skip to content

Commit

Permalink
feat(NcSelect): Allow to filter users by email notation
Browse files Browse the repository at this point in the history
Allows to filter by the email notation like `Jane <[email protected]>`

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Oct 15, 2023
1 parent cef0a48 commit fcf5aeb
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
74 changes: 74 additions & 0 deletions cypress/component/NcSelect.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { mount } from 'cypress/vue2'
import NcSelect from '../../src/components/NcSelect/NcSelect.vue'

describe('NcSelect', () => {
const mountSelect = () => mount(NcSelect, {
propsData: {
userSelect: true,
inputClass: 'cypress-search-input',
options: [
{
id: '0-john',
displayName: 'John',
isNoUser: false,
subname: '[email protected]',
icon: '',
},
{
id: '0-emma',
displayName: 'Emma',
isNoUser: false,
subname: '[email protected]',
icon: '',
},
{
id: '0-olivia',
displayName: 'Olivia',
isNoUser: false,
subname: '[email protected]',
icon: '',
},
],
},
})

it('has options', () => {
mountSelect()

cy.get('.select').click()
cy.contains('.option', 'Olivia').should('exist')
cy.contains('.option', 'John').should('exist')
cy.contains('.option', 'Emma').should('exist')
})

it('can filter by name', () => {
mountSelect()

cy.get('.cypress-search-input').scrollIntoView().type('Em')
cy.contains('.option', 'Emma').should('exist')
cy.document().find('.option').should('have.length', 1)
})

it('can filter by mail', () => {
mountSelect()

cy.get('.cypress-search-input').scrollIntoView().type('olivia@example')
cy.contains('.option', 'Olivia').should('exist')
cy.document().find('.option').should('have.length', 1)
})

it('can filter by mail in ticks', () => {
mountSelect()

// Until this it should not be visible
cy.get('.cypress-search-input').clear().type('O. <')
cy.contains('.option', 'Olivia').should('not.exist')
// now it should match
cy.get('.cypress-search-input').type('olivia')
cy.contains('.option', 'Olivia').should('exist')
// and with full search query it should also exist
cy.get('.cypress-search-input').type('@example.org>')
cy.contains('.option', 'Olivia').should('exist')
cy.document().find('.option').should('have.length', 1)
})
})
11 changes: 8 additions & 3 deletions src/components/NcSelect/NcSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -951,14 +951,19 @@ export default {
},
localFilterBy() {
// Match the email notation like "Jane <[email protected]>" with the email address as matching group
const EMAIL_NOTATION = /[^<]*<([^>]+)/
if (this.filterBy !== null) {
return this.filterBy
}
if (this.userSelect) {
return (option, label, search) => {
return (`${label} ${option.subname}` || '')
.toLocaleLowerCase()
.indexOf(search.toLocaleLowerCase()) > -1
const match = search.match(EMAIL_NOTATION)
return (match && option.subname && option.subname.toLocaleLowerCase().indexOf(match[1].toLocaleLowerCase()) > -1)
|| (`${label} ${option.subname}` || '')
.toLocaleLowerCase()
.indexOf(search.toLocaleLowerCase()) > -1
}
}
return VueSelect.props.filterBy.default
Expand Down

0 comments on commit fcf5aeb

Please sign in to comment.