Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Jan 30, 2024
1 parent d210c50 commit 6d15d1e
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/tests/Feature/DemoRoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ public static function demoRoutes(): array
['/blade-method-callbacks'],
['/blade-method'],
['/change-blade-prop'],
['/component-import'],
['/dynamic'],
['/dynamic-component-import'],
['/emit'],
['/form'],
['/props-in-template'],
['/refresh-state'],
['/refresh'],
['/regular-view'],
['/slot'],
['/to-vue-prop'],
['/two-way-binding'],
];
}
Expand Down
7 changes: 7 additions & 0 deletions app/tests/Unit/Console/BuildComponentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public function it_builds_the_components()
'ComponentToVueProp',
'ComponentComponentImport',
'ComponentDynamicComponentImport',
'ComponentChild',
'ComponentEmit',
'ComponentPropsInTemplate',
'ComponentRoot',
'Emit',
'PropsInTemplate',
'Slot',
] as $component) {
$this->assertFileExists(resource_path('js/splade/Splade'.$component.'.vue'));
$this->assertMatchesVueSnapshot($filesytem->get(resource_path('js/splade/Splade'.$component.'.vue')));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup>
import {} from 'vue'
const props = defineProps({
spladeBridge: Object,
spladeTemplateId: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({ spladeBridge: Object, spladeTemplateId: String })
const childVar = ref("What's that, Hawaiian Noises?")
const spladeRender = {
name: 'SpladeComponentChildRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeBridge: Object, spladeTemplateId: String },
data: () => ({ childVar }),
}
</script>
<template>
<spladeRender :splade-bridge="spladeBridge" :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup>
const props = defineProps({ spladeBridge: Object, spladeTemplateId: String })
const emit = defineEmits(['trigger'])
const trigger = () => {
emit('trigger')
}
const spladeRender = {
name: 'SpladeComponentEmitRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeBridge: Object, spladeTemplateId: String },
data: () => ({ emit, trigger }),
}
</script>
<template>
<spladeRender :splade-bridge="spladeBridge" :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({
spladeBridge: Object,
spladeTemplateId: String,
title: { type: String, required: false, default: 'Default title' },
})
const subtitle = ref('Default subtitle')
const spladeRender = {
name: 'SpladeComponentPropsInTemplateRender',
template: spladeTemplates[props.spladeTemplateId],
props: {
spladeBridge: Object,
spladeTemplateId: String,
title: { type: String, required: false, default: 'Default title' },
},
data: () => ({ subtitle }),
}
</script>
<template>
<spladeRender :title="title" :splade-bridge="spladeBridge" :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({ spladeBridge: Object, spladeTemplateId: String })
const rootCounter = ref(0)
const emit = defineEmits(['incremented'])
function increment() {
rootCounter.value++
emit('incremented')
}
const spladeRender = {
name: 'SpladeComponentRootRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeBridge: Object, spladeTemplateId: String },
data: () => ({ emit, increment, rootCounter }),
}
</script>
<template>
<spladeRender :splade-bridge="spladeBridge" :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({ spladeTemplateId: String })
const show = ref(false)
function toggle() {
show.value = !show.value
}
const spladeRender = {
name: 'SpladeEmitRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeTemplateId: String },
data: () => ({ show, toggle }),
}
</script>
<template>
<spladeRender :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({ spladeTemplateId: String })
const title = ref('Default title')
function updateTitle() {
title.value = 'New title'
}
const spladeRender = {
name: 'SpladePropsInTemplateRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeTemplateId: String },
data: () => ({ title, updateTitle }),
}
</script>
<template>
<spladeRender :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script setup>
import { ref } from 'vue'
const props = defineProps({ spladeTemplateId: String })
const layoutCounter = ref(0)
const spladeRender = {
name: 'SpladeSlotRender',
template: spladeTemplates[props.spladeTemplateId],
props: { spladeTemplateId: String },
data: () => ({ layoutCounter }),
}
</script>
<template>
<spladeRender :splade-template-id="spladeTemplateId">
<template v-for="(_, slot) of $slots" #[slot]="scope"><slot :name="slot" v-bind="scope" /></template>
</spladeRender>
</template>
4 changes: 2 additions & 2 deletions src/BladeViewExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ protected function renderImports(): string
->sort()
->implode(',');

return <<<JS
return $vueFunctionsImports ? <<<JS
import { {$vueFunctionsImports} } from 'vue';
JS;
JS : '';
}

/**
Expand Down

0 comments on commit 6d15d1e

Please sign in to comment.