-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from soasada/blog_post_update
Blog post update
- Loading branch information
Showing
12 changed files
with
145 additions
and
50 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
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
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,68 @@ | ||
<template> | ||
<div class="blog-post-create"> | ||
<BorderBottomTitle title="Update a Blog post"/> | ||
|
||
<form @submit.prevent="sendForm"> | ||
<div class="mb-3"> | ||
<label for="input-blog-title" class="form-label">Title</label> | ||
<input type="text" class="form-control" id="input-blog-title" v-model="blogPost.title"> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label for="input-blog-content" class="form-label">Content</label> | ||
<textarea class="form-control" id="input-blog-content" rows="3" v-model="blogPost.content"></textarea> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<label for="input-blog-locale" class="form-label">Locale</label> | ||
<select id="input-blog-locale" class="form-select" v-model="blogPost.locale"> | ||
<option value="es">Spanish</option> | ||
<option value="en">English</option> | ||
<option value="ca">Catalan</option> | ||
</select> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-primary">Update</button> | ||
</form> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import {defineComponent} from 'vue'; | ||
import {useStore} from 'vuex'; | ||
import BorderBottomTitle from '@/layout/BorderBottomTitle.vue'; | ||
import {useRoute, useRouter} from 'vue-router'; | ||
import BlogService from '@/blog/BlogService'; | ||
export default defineComponent({ | ||
name: 'BlogPostUpdate', | ||
components: { | ||
BorderBottomTitle | ||
}, | ||
setup() { | ||
const store = useStore(); | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
const blogId = route.params.blogId as string; | ||
const locale = route.params.locale as string; | ||
const findBlog = store.getters.findBlog; | ||
const blog = findBlog(blogId); | ||
const blogPost = blog.posts[locale]; | ||
const sendForm = () => { | ||
const token = store.getters.getAccessToken; | ||
store.dispatch('clearBlogs'); // this should be inside the service | ||
BlogService.update(blogId, { | ||
title: blogPost.title, | ||
content: blogPost.content, | ||
imageUrl: blog.imageUrl, | ||
locale: blogPost.locale | ||
}, token, () => router.push('/blog')); | ||
}; | ||
return {store, route, router, blogPost, sendForm}; | ||
} | ||
}); | ||
</script> |
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
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
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
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 |
---|---|---|
@@ -1,23 +1,10 @@ | ||
export default class PostResponse { | ||
readonly id: string; | ||
readonly readableId: string; | ||
readonly title: string; | ||
readonly content: string; | ||
readonly locale: string; | ||
readonly createdBy: string; | ||
readonly updatedBy: string; | ||
readonly createdAt: string; | ||
readonly updatedAt: string; | ||
|
||
constructor(readableId: string, title: string, content: string, locale: string, createdBy: string, updatedBy: string, createdAt: string, updatedAt: string) { | ||
this.id = readableId; | ||
this.readableId = readableId; | ||
this.title = title; | ||
this.content = content; | ||
this.locale = locale; | ||
this.createdBy = createdBy; | ||
this.updatedBy = updatedBy; | ||
this.createdAt = createdAt; | ||
this.updatedAt = updatedAt; | ||
} | ||
export default interface PostResponse { | ||
readableId: string; | ||
title: string; | ||
content: string; | ||
locale: string; | ||
createdBy: string; | ||
updatedBy: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
} |
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
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
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
36 changes: 36 additions & 0 deletions
36
kemenu-admin-frontend/tests/unit/upload_image/UploadImage.spec.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,36 @@ | ||
import {mount} from '@vue/test-utils'; | ||
import UploadImage from '@/upload_image/UploadImage.vue'; | ||
import store from '@/store'; | ||
import UploadImageService from '@/upload_image/UploadImageService'; | ||
import {ref} from 'vue'; | ||
|
||
describe('UploadImage.vue', () => { | ||
it('Should emit the URL when an image is uploaded', async () => { | ||
const mockUpload = jest.fn(); | ||
const expectedURL = 'https://example.com'; | ||
mockUpload.mockReturnValueOnce( | ||
new Promise( | ||
(resolve) => { | ||
resolve(expectedURL); | ||
} | ||
) | ||
); | ||
UploadImageService.upload = mockUpload; | ||
const imageUrl = ref(''); | ||
const wrapper = mount(UploadImage, { | ||
props: { | ||
modelValue: imageUrl | ||
}, | ||
global: { | ||
plugins: [store] | ||
} | ||
}); | ||
const input = wrapper.find('input'); | ||
(wrapper.vm as any).file = { | ||
files: [new File([''], 'example.png', {type: 'image/png'})] | ||
}; | ||
await input.trigger('change'); | ||
let emittedElement = wrapper.emitted('update:modelValue')[0] as String[]; | ||
expect(emittedElement[0]).toStrictEqual(expectedURL); | ||
}); | ||
}); |
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