Последняя версия с сервера прошлого разработчика
This commit is contained in:
30
nova/resources/js/__tests__/ActionSelector.spec.js
vendored
Executable file
30
nova/resources/js/__tests__/ActionSelector.spec.js
vendored
Executable file
@@ -0,0 +1,30 @@
|
||||
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'
|
||||
import PortalVue from 'portal-vue'
|
||||
import ActionSelector from '@/components/ActionSelector'
|
||||
import flushPromises from 'flush-promises'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
localVue.use(PortalVue)
|
||||
|
||||
describe('ActionSelector', () => {
|
||||
test('it renders correctly with actions and pivot action', () => {
|
||||
const wrapper = mount(ActionSelector, {
|
||||
localVue,
|
||||
propsData: {
|
||||
selectedResources: [1, 2, 3],
|
||||
resourceName: 'posts',
|
||||
actions: [
|
||||
{ uriKey: 'action-1', name: 'Action 1' },
|
||||
{ uriKey: 'action-2', name: 'Action 2' },
|
||||
],
|
||||
pivotActions: [
|
||||
{ uriKey: 'action-3', name: 'Action 3' },
|
||||
{ uriKey: 'action-4', name: 'Action 4' },
|
||||
],
|
||||
pivotName: 'Pivot',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
24
nova/resources/js/__tests__/__snapshots__/ActionSelector.spec.js.snap
Executable file
24
nova/resources/js/__tests__/__snapshots__/ActionSelector.spec.js.snap
Executable file
@@ -0,0 +1,24 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ActionSelector it renders correctly with actions and pivot action 1`] = `
|
||||
<div>
|
||||
<div class="mr-3">
|
||||
<select data-testid="action-select" class="form-control form-select mr-2">
|
||||
<option value="" disabled="disabled" selected="selected">Select Action</option>
|
||||
<optgroup label="Resource">
|
||||
<option value="action-1">
|
||||
Action 1
|
||||
</option>
|
||||
<option value="action-2">
|
||||
Action 2
|
||||
</option>
|
||||
</optgroup>
|
||||
<!---->
|
||||
</select>
|
||||
<button data-testid="action-confirm" disabled="disabled" class="btn btn-default btn-primary btn-disabled">
|
||||
Run
|
||||
</button>
|
||||
</div>
|
||||
<div class="v-portal" style="display: none;"></div>
|
||||
</div>
|
||||
`;
|
||||
349
nova/resources/js/__tests__/fields/BelongsToField.spec.js
vendored
Executable file
349
nova/resources/js/__tests__/fields/BelongsToField.spec.js
vendored
Executable file
@@ -0,0 +1,349 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import BelongsToField from '@/components/Form/BelongsToField'
|
||||
import flushPromises from 'flush-promises'
|
||||
|
||||
jest.mock('@/storage/BelongsToFieldStorage')
|
||||
|
||||
describe('BelongsToField', () => {
|
||||
test('when creating it fetches all resources on mount if the field is not searchable', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: '',
|
||||
attribute: 'user',
|
||||
searchable: false,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'posts',
|
||||
viaResource: '',
|
||||
viaResourceId: '',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.selectedResourceId).toBe(null)
|
||||
expect(wrapper.vm.isSearchable).toBe(false)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([
|
||||
{ value: 1 },
|
||||
{ value: 2 },
|
||||
{ value: 3 },
|
||||
])
|
||||
expect(wrapper.vm.selectedResource).toEqual(null)
|
||||
})
|
||||
|
||||
test('when creating it doesnt fetch resources on mount if the field is searchable', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: '',
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'posts',
|
||||
viaResource: '',
|
||||
viaResourceId: '',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.selectedResourceId).toEqual(null)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(false)
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([])
|
||||
expect(wrapper.vm.selectedResource).toEqual(null)
|
||||
})
|
||||
|
||||
test('when creating via a related resource it selects the related resource on mount if the field is searchable', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Post',
|
||||
belongsToId: '',
|
||||
attribute: 'post',
|
||||
searchable: true,
|
||||
resourceName: 'posts',
|
||||
},
|
||||
resourceName: 'comments',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.selectedResourceId).toEqual(1)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: { current: 1, first: true, search: '', withTrashed: false },
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([{ value: 1 }])
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
})
|
||||
|
||||
test('if editing an existing resource it selects the related resource on mount if the field is not searchable', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: 1,
|
||||
attribute: 'user',
|
||||
searchable: false,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'posts',
|
||||
viaResource: '',
|
||||
viaResourceId: '',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.editingExistingResource).toBe(true)
|
||||
expect(wrapper.vm.selectedResourceId).toEqual(1)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: 1,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([
|
||||
{ value: 1 },
|
||||
{ value: 2 },
|
||||
{ value: 3 },
|
||||
])
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
})
|
||||
|
||||
test('if editing an existing resource it selects the related resource on mount if the field is searchable', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: 1,
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'posts',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.editingExistingResource).toBe(true)
|
||||
expect(wrapper.vm.selectedResourceId).toEqual(1)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: { current: 1, first: true, search: '', withTrashed: false },
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([{ value: 1 }])
|
||||
expect(wrapper.vm.selectedResourceId).toEqual(1)
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
|
||||
// Ensure it turns off selection of the initial resource after fetching the first time
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(false)
|
||||
})
|
||||
|
||||
test('it determines if its related resource soft deletes', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: 1,
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources can be enabled when a resource supports soft-deleting', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: '',
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
wrapper.vm.enableWithTrashed()
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.withTrashed).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources cannot be enabled when a resource doesnt support soft-deleting', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Author',
|
||||
belongsToId: '',
|
||||
attribute: 'author',
|
||||
searchable: false,
|
||||
resourceName: 'authors', // This resource doesnt support soft-deleting
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources is disabled by default', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: '',
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
// wrapper.vm.enableWithTrashed()
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
})
|
||||
|
||||
test('it determines if its related resource doesnt soft delete', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Author',
|
||||
belongsToId: 1,
|
||||
attribute: 'author',
|
||||
searchable: true,
|
||||
resourceName: 'authors',
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
})
|
||||
|
||||
test('it correctly handles filling the formData object for submit', async () => {
|
||||
const wrapper = shallowMount(BelongsToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'User',
|
||||
belongsToId: 1,
|
||||
attribute: 'user',
|
||||
searchable: true,
|
||||
resourceName: 'users',
|
||||
},
|
||||
resourceName: 'videos',
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
const expectedFormData = new FormData()
|
||||
expectedFormData.append('user', 1)
|
||||
expectedFormData.append('user_trashed', false)
|
||||
|
||||
const formData = new FormData()
|
||||
wrapper.vm.field.fill(formData)
|
||||
|
||||
expect(formData).toEqual(expectedFormData)
|
||||
})
|
||||
})
|
||||
603
nova/resources/js/__tests__/fields/MorphToField.spec.js
vendored
Executable file
603
nova/resources/js/__tests__/fields/MorphToField.spec.js
vendored
Executable file
@@ -0,0 +1,603 @@
|
||||
import Vue from 'vue'
|
||||
import { shallowMount, createLocalVue } from '@vue/test-utils'
|
||||
import MorphToField from '@/components/Form/MorphToField'
|
||||
import flushPromises from 'flush-promises'
|
||||
|
||||
jest.mock('@/storage/MorphToFieldStorage')
|
||||
|
||||
describe('MorphToField', () => {
|
||||
/**
|
||||
* Note: This field doesn't support loading all resources initially unless we're editing or
|
||||
* coming in via a related resource because otherwise we don't know which type to load them for
|
||||
*/
|
||||
test('when creating it has the correct initial state if its not searchable', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: '',
|
||||
morphToType: '',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: '',
|
||||
viaResourceId: '',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(false)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.resourceType).toBe('')
|
||||
expect(wrapper.vm.isSearchable).toBe(false)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: '',
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
expect(wrapper.vm.availableResources).toEqual([])
|
||||
expect(wrapper.vm.selectedResource).toEqual(null)
|
||||
expect(wrapper.vm.selectedResourceId).toBe(null)
|
||||
})
|
||||
|
||||
test('when creating it has the correct initial state if it is searchable', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: true,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: '',
|
||||
morphToType: '',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: '',
|
||||
viaResourceId: '',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(false)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.resourceType).toBe('')
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: '',
|
||||
current: null,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
expect(wrapper.vm.availableResources).toEqual([])
|
||||
expect(wrapper.vm.selectedResource).toEqual(null)
|
||||
expect(wrapper.vm.selectedResourceId).toBe(null)
|
||||
})
|
||||
|
||||
test('when creating via a related resource and is not searchable it loads the related type all related resources and selects the related resource', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: '',
|
||||
morphToType: '',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.resourceType).toBe('posts')
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(false)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: 'posts',
|
||||
current: 1,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([
|
||||
{ value: 1 },
|
||||
{ value: 2 },
|
||||
{ value: 3 },
|
||||
])
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
expect(wrapper.vm.selectedResourceId).toBe(1)
|
||||
})
|
||||
|
||||
test('when creating via a related resource and it is searchable, it only loads the related type and selects the related resource', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: true,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: '',
|
||||
morphToType: '',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(false)
|
||||
expect(wrapper.vm.resourceType).toBe('posts')
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: 'posts',
|
||||
current: 1,
|
||||
first: true,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([{ value: 1 }])
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
expect(wrapper.vm.selectedResourceId).toBe(1)
|
||||
})
|
||||
|
||||
test('when editing an existing resource and the field is not searchable it selects the related resource type and resource and loads all resources', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: 1,
|
||||
morphToType: 'posts',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: '',
|
||||
viaResourceId: null,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(true)
|
||||
expect(wrapper.vm.resourceType).toBe('posts')
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(false)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: 'posts',
|
||||
current: 1,
|
||||
first: false,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([
|
||||
{ value: 1 },
|
||||
{ value: 2 },
|
||||
{ value: 3 },
|
||||
])
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
expect(wrapper.vm.selectedResourceId).toBe(1)
|
||||
})
|
||||
|
||||
test('when editing an existing resource and the field is searchable it selects the related resource type and resource and doesnt load all the resources', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: true,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: 1,
|
||||
morphToType: 'posts',
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: '',
|
||||
viaResourceId: null,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initializingWithExistingResource).toBe(true)
|
||||
expect(wrapper.vm.editingExistingResource).toBe(true)
|
||||
expect(wrapper.vm.resourceType).toBe('posts')
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.isSearchable).toBe(true)
|
||||
expect(wrapper.vm.shouldSelectInitialResource).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
type: 'posts',
|
||||
current: 1,
|
||||
first: true,
|
||||
search: '',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.availableResources).toEqual([{ value: 1 }])
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.selectedResource).toEqual({ value: 1 })
|
||||
expect(wrapper.vm.selectedResourceId).toBe(1)
|
||||
})
|
||||
|
||||
test('it determines if its related resource soft deletes', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
// resourceName: 'users',
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources can be enabled when a resource supports soft-deleting', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
wrapper.vm.enableWithTrashed()
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
expect(wrapper.vm.withTrashed).toBe(true)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: 1,
|
||||
first: false,
|
||||
search: '',
|
||||
type: 'posts',
|
||||
withTrashed: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources cannot be enabled when a resource doesnt support soft-deleting', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'videos',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
expect(wrapper.vm.queryParams).toEqual({
|
||||
params: {
|
||||
current: 1,
|
||||
first: false,
|
||||
search: '',
|
||||
type: 'videos',
|
||||
withTrashed: false,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('including trashed resources in the available resources is disabled by default', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'videos',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.withTrashed).toBe(false)
|
||||
})
|
||||
|
||||
test('it determines if its related resource doesnt soft delete', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(true)
|
||||
|
||||
wrapper.setData({ resourceType: 'videos' })
|
||||
wrapper.vm.determineIfSoftDeletes()
|
||||
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.vm.softDeletes).toBe(false)
|
||||
})
|
||||
|
||||
test('it correctly handles filling the formData object for submit', async () => {
|
||||
const wrapper = shallowMount(MorphToField, {
|
||||
stubs: ['default-field'],
|
||||
propsData: {
|
||||
field: {
|
||||
name: 'Commentable',
|
||||
attribute: 'commentable',
|
||||
searchable: false,
|
||||
morphToRelationship: 'commentable',
|
||||
morphToId: null,
|
||||
morphToType: null,
|
||||
morphToTypes: [
|
||||
{
|
||||
display: 'Post',
|
||||
type: 'App\\Nova\\Post',
|
||||
value: 'posts',
|
||||
},
|
||||
{
|
||||
display: 'Video',
|
||||
type: 'App\\Nova\\Video',
|
||||
value: 'videos',
|
||||
},
|
||||
],
|
||||
},
|
||||
resourceName: '',
|
||||
viaRelationship: '',
|
||||
viaResource: 'posts',
|
||||
viaResourceId: 1,
|
||||
},
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
|
||||
const expectedFormData = new FormData()
|
||||
expectedFormData.append('commentable', 1)
|
||||
expectedFormData.append('commentable_type', 'posts')
|
||||
expectedFormData.append('commentable_trashed', false)
|
||||
|
||||
const formData = new FormData()
|
||||
|
||||
wrapper.vm.field.fill(formData)
|
||||
|
||||
expect(formData).toEqual(expectedFormData)
|
||||
})
|
||||
})
|
||||
66
nova/resources/js/__tests__/views/ResourceIndex.spec.js
vendored
Executable file
66
nova/resources/js/__tests__/views/ResourceIndex.spec.js
vendored
Executable file
@@ -0,0 +1,66 @@
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import { createRenderer } from 'vue-server-renderer'
|
||||
import Index from '@/views/Index.vue'
|
||||
|
||||
// Create a renderer for snapshot testing
|
||||
const renderer = createRenderer()
|
||||
|
||||
// Nova global mock
|
||||
// class Nova {
|
||||
// constructor(config) {}
|
||||
|
||||
// request() {
|
||||
// return {
|
||||
// get() {
|
||||
// return { data: {} }
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// global.Nova = new Nova()
|
||||
|
||||
describe('Index.vue', () => {
|
||||
it('renders', () => {
|
||||
const wrapper = shallowMount(Index, {
|
||||
stubs: ['loading-view', 'cards'],
|
||||
propsData: {
|
||||
resourceName: 'posts',
|
||||
},
|
||||
})
|
||||
renderer.renderToString(wrapper.vm, (err, str) => {
|
||||
if (err) throw new Error(err)
|
||||
expect(str).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
|
||||
it('renders after loading', () => {
|
||||
const wrapper = shallowMount(Index, {
|
||||
stubs: ['loading-view', 'cards'],
|
||||
propsData: {
|
||||
resourceName: 'posts',
|
||||
},
|
||||
})
|
||||
|
||||
expect(wrapper.vm.initialLoading).toEqual(false)
|
||||
})
|
||||
|
||||
it('should show its cards', () => {
|
||||
const $route = { params: { resourceName: 'posts' } }
|
||||
const wrapper = shallowMount(Index, {
|
||||
stubs: ['loading-view', 'cards'],
|
||||
mocks: {
|
||||
$route,
|
||||
},
|
||||
propsData: {
|
||||
resourceName: 'posts',
|
||||
},
|
||||
})
|
||||
|
||||
// wrapper.setData({
|
||||
// cards: [{}],
|
||||
// })
|
||||
|
||||
expect(wrapper.vm.shouldShowCards).toEqual(true)
|
||||
})
|
||||
})
|
||||
46
nova/resources/js/__tests__/views/UpdateAttached.spec.js
vendored
Executable file
46
nova/resources/js/__tests__/views/UpdateAttached.spec.js
vendored
Executable file
@@ -0,0 +1,46 @@
|
||||
import { mount, shallowMount, createLocalVue } from '@vue/test-utils'
|
||||
import UpdateAttached from '@/views/UpdateAttached'
|
||||
// import flushPromises from 'flush-promises'
|
||||
|
||||
describe('UpdateAttached', () => {
|
||||
test('it loads all the available resources if its not searchable', () => {
|
||||
window.Nova = {}
|
||||
window.Nova.config = {
|
||||
resources: [
|
||||
{
|
||||
uriKey: 'users',
|
||||
label: 'Users',
|
||||
singularLabel: 'User',
|
||||
authorizedToCreate: true,
|
||||
searchable: false,
|
||||
},
|
||||
{
|
||||
uriKey: 'roles',
|
||||
label: 'Roles',
|
||||
singularLabel: 'Role',
|
||||
authorizedToCreate: true,
|
||||
searchable: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const wrapper = mount(UpdateAttached, {
|
||||
propsData: {
|
||||
resourceName: 'users',
|
||||
resourceId: 100,
|
||||
relatedResourceName: 'roles',
|
||||
relatedResourceId: 25,
|
||||
// viaResource: {},
|
||||
// viaResourceId: {},
|
||||
// viaRelationship: {},
|
||||
// polymorphic: false,
|
||||
},
|
||||
})
|
||||
|
||||
wrapper.setData({
|
||||
field: {},
|
||||
})
|
||||
|
||||
// expect(wrapper).toMatchSnapshot()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Index.vue renders 1`] = `<loading-view-stub></loading-view-stub>`;
|
||||
@@ -0,0 +1,3 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`UpdateAttached it loads all the available resources if its not searchable 1`] = `<div class="card overflow-hidden"></div>`;
|
||||
Reference in New Issue
Block a user