-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix relationship displayMode incorrectly defaulting to count
- Loading branch information
Showing
3 changed files
with
231 additions
and
24 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,5 @@ | ||
--- | ||
'@keystone-6/core': patch | ||
--- | ||
|
||
Fixes `ui.displayMode` in the `relationship` field incorrectly defaulting to `count` instead of `select` |
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
176 changes: 176 additions & 0 deletions
176
tests/api-tests/relationships/label-search-field-validation.test.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,176 @@ | ||
import { list } from '@keystone-6/core'; | ||
import { allowAll } from '@keystone-6/core/access'; | ||
import { getContext } from '@keystone-6/core/context'; | ||
import { integer, relationship, text } from '@keystone-6/core/fields'; | ||
import { apiTestConfig } from '../utils'; | ||
|
||
const Thing = list({ | ||
access: allowAll, | ||
fields: { | ||
name: text(), | ||
other: text(), | ||
notText: integer(), | ||
}, | ||
}); | ||
|
||
test("labelField that doesn't exist is rejected with displayMode: select", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
labelField: 'doesNotExist', | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.labelField option for field 'A.something' uses 'doesNotExist' but that field doesn't exist."` | ||
); | ||
}); | ||
|
||
test("labelField that doesn't exist is rejected with displayMode: cards", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
displayMode: 'cards', | ||
cardFields: ['name'], | ||
inlineConnect: { labelField: 'doesNotExist' }, | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.inlineConnect.labelField option for field 'A.something' uses 'doesNotExist' but that field doesn't exist."` | ||
); | ||
}); | ||
|
||
test("searchFields that don't exist are rejected with displayMode: select", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
searchFields: ['doesNotExist'], | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.searchFields option for relationship field 'A.something' includes 'doesNotExist' but that field doesn't exist."` | ||
); | ||
}); | ||
|
||
test("searchFields that don't exist are rejected with displayMode: cards", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
displayMode: 'cards', | ||
cardFields: ['name'], | ||
inlineConnect: { labelField: 'name', searchFields: ['doesNotExist'] }, | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.inlineConnect.searchFields option for relationship field 'A.something' includes 'doesNotExist' but that field doesn't exist."` | ||
); | ||
}); | ||
|
||
test("searchFields that aren't searchable are rejected with displayMode: select", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
searchFields: ['notText'], | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.searchFields option for field 'A.something' includes 'notText' but that field doesn't have a contains filter that accepts a GraphQL String"` | ||
); | ||
}); | ||
|
||
test("searchFields that aren't searchable are rejected with displayMode: cards", () => { | ||
expect(() => | ||
getContext( | ||
apiTestConfig({ | ||
lists: { | ||
A: list({ | ||
access: allowAll, | ||
fields: { | ||
something: relationship({ | ||
ref: 'Thing', | ||
ui: { | ||
displayMode: 'cards', | ||
cardFields: ['name'], | ||
inlineConnect: { labelField: 'name', searchFields: ['notText'] }, | ||
}, | ||
}), | ||
}, | ||
}), | ||
Thing, | ||
}, | ||
}), | ||
{} as any | ||
) | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"The ui.searchFields option for field 'A.something' includes 'notText' but that field doesn't have a contains filter that accepts a GraphQL String"` | ||
); | ||
}); |