-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4653 from nextcloud-libraries/feat/allow-to-filte…
…r-by-mail-notation feat(NcSelect): Allow to filter users by email notation
- Loading branch information
Showing
4 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 'john@example.org', | ||
icon: '', | ||
}, | ||
{ | ||
id: '0-emma', | ||
displayName: 'Emma', | ||
isNoUser: false, | ||
subname: 'emma@example.org', | ||
icon: '', | ||
}, | ||
{ | ||
id: '0-olivia', | ||
displayName: 'Olivia', | ||
isNoUser: false, | ||
subname: 'olivia@example.org', | ||
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
tests/unit/components/NcListItemIcon/list-item-icon.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de> | ||
* | ||
* @author Ferdinand Thiessen <opensource@fthiessen.de> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import { shallowMount } from '@vue/test-utils' | ||
import NcListItemIcon from '../../../../src/components/NcListItemIcon/NcListItemIcon.vue' | ||
|
||
describe('NcListItemIcon', () => { | ||
it('highlights the search query', async () => { | ||
const wrapper = shallowMount(NcListItemIcon, { | ||
propsData: { | ||
name: 'J. Doe', | ||
subname: 'privacy@example.com', | ||
search: 'doe', | ||
}, | ||
}) | ||
|
||
const highlights = wrapper.findAllComponents({ name: 'NcHighlight' }) | ||
expect(highlights).toHaveLength(2) | ||
expect(highlights.at(0).props('text')).toBe('J. Doe') | ||
expect(highlights.at(0).props('search')).toBe('doe') | ||
expect(highlights.at(1).props('text')).toBe('privacy@example.com') | ||
expect(highlights.at(1).props('search')).toBe('doe') | ||
}) | ||
|
||
it('highlights the email notation query', async () => { | ||
const wrapper = shallowMount(NcListItemIcon, { | ||
propsData: { | ||
name: 'J. Doe', | ||
subname: 'privacy@example.com', | ||
search: 'Manager <privacy@example.com>', | ||
}, | ||
}) | ||
|
||
const highlights = wrapper.findAllComponents({ name: 'NcHighlight' }) | ||
expect(highlights).toHaveLength(2) | ||
expect(highlights.at(0).props('search')).toBe('Manager') | ||
expect(highlights.at(1).props('search')).toBe('privacy@example.com') | ||
}) | ||
|
||
it('highlights the email notation query even if only partly typed', async () => { | ||
const wrapper = shallowMount(NcListItemIcon, { | ||
propsData: { | ||
name: 'J. Doe', | ||
subname: 'privacy@example.com', | ||
search: 'Manager <privacy', | ||
}, | ||
}) | ||
|
||
const highlights = wrapper.findAllComponents({ name: 'NcHighlight' }) | ||
expect(highlights).toHaveLength(2) | ||
expect(highlights.at(0).props('search')).toBe('Manager') | ||
expect(highlights.at(1).props('search')).toBe('privacy') | ||
}) | ||
|
||
it('does not highlight the email notation query when missing email', async () => { | ||
const wrapper = shallowMount(NcListItemIcon, { | ||
propsData: { | ||
name: 'J. Doe', | ||
subname: 'privacy@example.com', | ||
search: 'Doe <', | ||
}, | ||
}) | ||
|
||
const highlights = wrapper.findAllComponents({ name: 'NcHighlight' }) | ||
expect(highlights).toHaveLength(2) | ||
expect(highlights.at(0).props('search')).toBe('Doe <') | ||
expect(highlights.at(1).props('search')).toBe('Doe <') | ||
}) | ||
|
||
it('does not highlight the email notation query when no user', async () => { | ||
const wrapper = shallowMount(NcListItemIcon, { | ||
propsData: { | ||
name: 'J. Doe', | ||
subname: 'privacy@example.com', | ||
search: 'Doe <privacy@example.com>', | ||
isNoUser: true, | ||
}, | ||
}) | ||
|
||
const highlights = wrapper.findAllComponents({ name: 'NcHighlight' }) | ||
expect(highlights).toHaveLength(2) | ||
expect(highlights.at(0).props('search')).toBe('Doe <privacy@example.com>') | ||
expect(highlights.at(1).props('search')).toBe('Doe <privacy@example.com>') | ||
}) | ||
}) |