Skip to content

Commit

Permalink
Add space name validation back into space picker create
Browse files Browse the repository at this point in the history
  • Loading branch information
poltak committed Jul 23, 2024
1 parent 63f3d3e commit 29e95cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 13 additions & 16 deletions src/custom-lists/ui/CollectionPicker/logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as DATA from './logic.test.data'
import type { KeyEvent } from 'src/common-ui/GenericPicker/types'
import {
EMPTY_SPACE_NAME_ERR_MSG,
NON_UNIQ_SPACE_NAME_ERR_MSG,
BAD_CHAR_SPACE_NAME_ERR_MSG,
} from '@worldbrain/memex-common/lib/utils/space-name-validation'
import { SPECIAL_LIST_IDS } from '@worldbrain/memex-common/lib/storage/modules/lists/constants'
Expand Down Expand Up @@ -590,17 +589,17 @@ describe('SpacePickerLogic', () => {
expect(entryPickerLogic.validateSpaceName(' test [] ').valid).toBe(
false,
)
// expect(testLogic.state.renameListErrorMessage).toEqual(
// BAD_CHAR_SPACE_NAME_ERR_MSG,
// )
// expect(
// entryPickerLogic.validateSpaceName(
// DATA.TEST_USER_LIST_SUGGESTIONS[0]?.name,
// ).valid,
// ).toBe(false)
// expect(testLogic.state.renameListErrorMessage).toEqual(
// NON_UNIQ_SPACE_NAME_ERR_MSG,
// )
expect(testLogic.state.renameListErrorMessage).toEqual(
BAD_CHAR_SPACE_NAME_ERR_MSG,
)

// Non-unique space names should still work
expect(
entryPickerLogic.validateSpaceName(
DATA.TEST_USER_LIST_SUGGESTIONS[0]?.name,
).valid,
).toBe(true)
expect(testLogic.state.renameListErrorMessage).toEqual(null)
})

it('should show default entries again after clearing the search query', async ({
Expand Down Expand Up @@ -694,7 +693,7 @@ describe('SpacePickerLogic', () => {
)
expect(testLogic.state.renameListErrorMessage).toEqual(null)

// Attempt to re-use another list name - should set error
// Attempt to re-use another list name - should _work_
await testLogic.processEvent('renameList', {
listId: DATA.TEST_USER_LIST_SUGGESTIONS[1].localId,
name: DATA.TEST_USER_LIST_SUGGESTIONS[0].name,
Expand All @@ -703,9 +702,7 @@ describe('SpacePickerLogic', () => {
expect(normalizedStateToArray(testLogic.state.listEntries)).toEqual(
DATA.TEST_USER_LIST_SUGGESTIONS,
)
expect(testLogic.state.renameListErrorMessage).toEqual(
NON_UNIQ_SPACE_NAME_ERR_MSG,
)
expect(testLogic.state.renameListErrorMessage).toEqual(null)

// Attempt to use a list name with invalid characters - also should set error
await testLogic.processEvent('renameList', {
Expand Down
4 changes: 4 additions & 0 deletions src/custom-lists/ui/CollectionPicker/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,10 @@ export default class SpacePickerLogic extends UILogic<

for (let i = 0; i < entry.length; i++) {
const item = entry[i]
const { valid } = this.validateSpaceName(item.name)
if (!valid) {
return
}
if (item.unifiedId == null) {
try {
parentLocalId = this.dependencies.annotationsCache.lists
Expand Down

0 comments on commit 29e95cd

Please sign in to comment.