Fixed test, improved code

main
Boris Sekachev 5 years ago
parent c2479dffbf
commit 4c10fc90f6

@ -61,18 +61,29 @@ export default function UserSelector(props: Props): JSX.Element {
setUsers(initialUsers); setUsers(initialUsers);
}, [initialUsers]); }, [initialUsers]);
const handleSearch = (searchValue: string): void => { useEffect(() => {
if (searchValue) { if (searchPhrase) {
searchUsers(searchValue, setUsers); searchUsers(searchPhrase, setUsers);
} else { } else {
setUsers(initialUsers); setUsers(initialUsers);
} }
}, [searchPhrase]);
const handleSearch = (searchValue: string): void => {
setSearchPhrase(searchValue); setSearchPhrase(searchValue);
}; };
const onBlur = (): void => { const onBlur = (): void => {
if (!searchPhrase && value) { if (!searchPhrase && value) {
onSelect(null); onSelect(null);
} else if (searchPhrase) {
const potentialUsers = users.filter((_user) => _user.username.includes(searchPhrase));
if (potentialUsers.length === 1) {
setSearchPhrase(potentialUsers[0].username);
onSelect(potentialUsers[0]);
} else {
setSearchPhrase(value?.username || '');
}
} }
}; };

@ -37,10 +37,10 @@ context('Value must be a user instance.', () => {
// Before fix: // Before fix:
// The following error originated from your application code, not from Cypress. // The following error originated from your application code, not from Cypress.
// > Value must be a user instance // > Value must be a user instance
cy.get('.cvat-spinner').should('exist'); cy.get('.cvat-spinner', { timeout: 500 }).should('not.exist');
// Remove the user's assignment for next tests. // Remove the user's assignment for next tests.
cy.get('.cvat-task-details-user-block').within(() => { cy.get('.cvat-task-details-user-block').within(() => {
cy.get('[type="text"]').click().clear().type('{Enter}'); cy.get('[type="search"]').click().clear().type('{Enter}');
}); });
}); });
}); });

Loading…
Cancel
Save