Skip to content

Commit e0efbcf

Browse files
committed
Adding snapshot tests for components
1 parent 6f856f6 commit e0efbcf

File tree

10 files changed

+131
-14
lines changed

10 files changed

+131
-14
lines changed

volume/blog-frontend/tests/unit/components/__snapshots__/App.spec.js.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
exports[`App is a valid component 1`] = `
44
<div>
5+
<div>
6+
<p>not registred</p> <button>Login</button>
7+
</div>
58
<nav>
69
<ul>
7-
<li><a href="#/login" class="router-link">Login</a></li>
810
<li><a href="#/blogs" class="router-link">List Blogs</a></li>
911
<li><a href="#/blogs/new" class="router-link">Create Blog</a></li>
1012
</ul>
1113
</nav>
1214
<!---->
15+
<modal name="modal" width="300" height="300"><b></b></modal>
1316
</div>
1417
`;

volume/blog-frontend/tests/unit/components/blog/create-blog/CreateBlog.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ describe('CreateBlog.vue', () => {
66
const wrapper = shallowMount(CreateBlog)
77

88
expect(wrapper.isVueInstance()).toBeTruthy()
9+
expect(wrapper).toMatchSnapshot()
10+
911
})
1012
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CreateBlog.vue is a valid component 1`] = `
4+
<div>
5+
<p>Create Blog</p>
6+
<div><label> Name: </label> <input type="text"></div>
7+
<div><label> Visibility: </label> <select>
8+
<option selected="selected" value="false">public</option>
9+
<option value="true">private</option>
10+
</select></div> <button>Create</button>
11+
</div>
12+
`;

volume/blog-frontend/tests/unit/components/blog/list-blog/__snapshots__/ListBlog.spec.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,23 @@ exports[`ListBlog.vue render blogs 1`] = `
99
<th>id</th>
1010
<th>name</th>
1111
<th>private</th>
12-
<th>show</th>
13-
<th>Delete</th>
12+
<th>owner</th>
1413
</tr>
1514
</thead>
1615
<tbody>
1716
<tr>
1817
<td>1</td>
1918
<td>mockName1</td>
2019
<td>true</td>
20+
<td></td>
2121
<td><button class="ListBlog__showBlog-button-js">Show</button></td>
2222
<td><button class="ListBlog__deleteBlog-button-js">Delete</button></td>
2323
</tr>
2424
<tr>
2525
<td>2</td>
2626
<td>mockName2</td>
2727
<td>false</td>
28+
<td></td>
2829
<td><button class="ListBlog__showBlog-button-js">Show</button></td>
2930
<td><button class="ListBlog__deleteBlog-button-js">Delete</button></td>
3031
</tr>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import ShowBlog from '@/components/blog/show-blog/ShowBlog'
3+
4+
describe('ShowBlog.vue', () => {
5+
it('is a valid component', () => {
6+
const mockBlog = {
7+
name: "mockName",
8+
title: "mockTitle",
9+
private: "mockPrivate",
10+
11+
posts: [
12+
{ id: 1, owner: "mockOwner", title: "mockTitle1", is_private: true },
13+
{ id: 2, owner: "mockOwner", title: "mockTitle2", is_private: false },
14+
]
15+
}
16+
const wrapper = shallowMount(ShowBlog, {
17+
methods: { getBlog: jest.fn() },
18+
propsData: { id: 1 },
19+
data() { return { blog: mockBlog } }
20+
});
21+
22+
expect(wrapper.isVueInstance()).toBeTruthy()
23+
expect(wrapper).toMatchSnapshot()
24+
})
25+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ShowBlog.vue is a valid component 1`] = `
4+
<div>
5+
<div>
6+
<h3> Blog Name: mockName </h3>
7+
</div>
8+
<table>
9+
<thead>
10+
<tr>
11+
<th>id</th>
12+
<th>title</th>
13+
<th>owner</th>
14+
<th>private</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
<tr>
19+
<td>1</td>
20+
<td>mockTitle1</td>
21+
<td>mockOwner</td>
22+
<td>true</td>
23+
<td><button>Show post</button></td>
24+
<td><button>Delete post</button></td>
25+
</tr>
26+
<tr>
27+
<td>2</td>
28+
<td>mockTitle2</td>
29+
<td>mockOwner</td>
30+
<td>false</td>
31+
<td><button>Show post</button></td>
32+
<td><button>Delete post</button></td>
33+
</tr>
34+
</tbody>
35+
</table> <button>Create Post</button>
36+
</div>
37+
`;

volume/blog-frontend/tests/unit/components/login/Login.spec.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ describe('Login.vue', () => {
1818
const mockToken = "mockToken"
1919

2020
it('is a valid component', () => {
21-
const wrapper = mount(Login)
21+
const wrapper = mount(Login, {
22+
stubs: {
23+
modal: true
24+
}
25+
})
2226

2327
expect(wrapper.isVueInstance()).toBeTruthy()
2428
expect(wrapper).toMatchSnapshot()
@@ -29,7 +33,11 @@ describe('Login.vue', () => {
2933
const doLoginSpy = jest.fn()
3034
Login.methods.doLogin = doLoginSpy
3135

32-
const wrapper = mount(Login)
36+
const wrapper = mount(Login, {
37+
stubs: {
38+
modal: true
39+
}
40+
})
3341

3442
beforeEach(() => {
3543
// fill username
@@ -60,24 +68,22 @@ describe('Login.vue', () => {
6068
const wrapper = mount(Login, {
6169
localVue,
6270
router,
63-
store
71+
store,
72+
stubs: {
73+
modal: true
74+
}
6475
})
6576

77+
const user = { token: "token", username: "username", userId: "userId", accessLevel: "accessLevel" }
6678
beforeEach(() => {
6779
const response = {
68-
data: {
69-
token: mockToken,
70-
username: mockUsername
71-
}
80+
data: user
7281
}
7382
wrapper.vm.onLoginSuccess(response)
7483
});
7584

7685
it('should save username in store', () => {
77-
expect(store.state.username).toEqual(mockUsername)
78-
})
79-
it('should save token in store', () => {
80-
expect(store.state.authToken).toEqual(mockToken)
86+
expect(store.state.user).toEqual(user)
8187
})
8288
})
8389
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import CreateBlog from '@/components/blog/create-blog/CreateBlog'
3+
4+
describe('CreateBlog.vue', () => {
5+
it('is a valid component', () => {
6+
const wrapper = shallowMount(CreateBlog)
7+
8+
expect(wrapper.isVueInstance()).toBeTruthy()
9+
})
10+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import CreatePost from '@/components/post/create-post/CreatePost'
3+
4+
describe('CreatePost.vue', () => {
5+
it('is a valid component', () => {
6+
const wrapper = shallowMount(CreatePost, {
7+
propsData: { blogId: 1 },
8+
});
9+
10+
expect(wrapper.isVueInstance()).toBeTruthy()
11+
expect(wrapper).toMatchSnapshot()
12+
})
13+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CreatePost.vue is a valid component 1`] = `
4+
<div>
5+
<p>Create Post</p>
6+
<div><label> title: </label> <input type="text"></div> <button>Create</button>
7+
</div>
8+
`;

0 commit comments

Comments
 (0)