Skip to content

Commit

Permalink
refactor(components): add baseUrl prop to QuickSearchForm (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagraber committed Jan 24, 2024
1 parent 04cfe6a commit 190ec30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
14 changes: 5 additions & 9 deletions src/components/QuickSearchForm/QuickSearchForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ import { ref } from 'vue';
const router = useRouter();
const props = withDefaults(defineProps<{ mode: 'dev' | 'prod' }>(), {
mode: 'prod',
const props = withDefaults(defineProps<{ baseUrlForRedirect: string }>(), {
baseUrlForRedirect: 'https://data-sources.pdap.io',
});
const formSchema = [
Expand Down Expand Up @@ -85,13 +85,9 @@ function handleSubmit(values: { location: string; searchTerm: string }) {
if (router.getRoutes().some((route) => route.path.includes('/search/'))) {
router.push(`/search/${searchTerm}/${location}`);
} else {
// Otherwise navigate via window
const baseUrl =
props.mode === 'prod'
? 'https://data-sources.pdap.io'
: 'https://data-sources.pdap.dev';
window.location.assign(`${baseUrl}/search/${searchTerm}/${location}`);
window.location.assign(
`${props.baseUrlForRedirect}/search/${searchTerm}/${location}`
);
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`QuickSearchForm component > Renders a QuickSearchForm 1`] = `
<div class="pdap-flex-container pdap-flex-container-start md:p-0">
<div class="pdap-flex-container pdap-flex-container-start p-0">
<h2 class="mt-0">Search our database</h2>
<p class="pb-4 md:pb-8"> If you have a question to answer, we may already know about helpful data in your area. <routerlink to="/data">Learn more about the data here.</routerlink>
<p class="pb-4 md:pb-8"> If you have a question to answer, we may already know about helpful data in your area. <a href="https://pdap.io/data">Learn more about the data here.</a>
</p>
</div>
<div class="pdap-flex-container pdap-flex-container-center pdap-quick-search-form h-full max-h-[75-vh] justify-start md:p-0">
<div class="pdap-flex-container pdap-flex-container-center pdap-quick-search-form h-full max-h-[75-vh] justify-start p-0">
<form class="pdap-form flex flex-wrap gap-x-4">
<!--v-if-->
<div class="pdap-grid-container pdap-input">
Expand Down
5 changes: 3 additions & 2 deletions src/components/QuickSearchForm/quick-search-form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ describe('QuickSearchForm component', () => {
});
});

test('Form triggers window navigation when rendered in app without /search/ route — dev mode', async () => {
test('Form triggers window navigation when rendered in app without /search/ route — custom baseUrlForRedirect', async () => {
const baseUrlForRedirect = 'https://data-sources.pdap.dev';
getRoutes.mockReturnValueOnce([
{ path: '/' },
{ path: '/foo' },
Expand All @@ -177,7 +178,7 @@ describe('QuickSearchForm component', () => {
const wrapper = mount(QuickSearchForm, {
...base,
props: {
mode: 'dev' as const,
baseUrlForRedirect,
},
});

Expand Down

0 comments on commit 190ec30

Please sign in to comment.