-
Notifications
You must be signed in to change notification settings - Fork 49
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 #46 from randombenj/feature/frontend-tests
Add frontend tests
- Loading branch information
Showing
8 changed files
with
1,962 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: '@vue/cli-plugin-unit-jest' | ||
} |
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,8 @@ | ||
/* eslint-disable no-undef */ | ||
const mockAxios = jest.genMockFromModule('axios') | ||
|
||
// this is the key to fix the axios.create() undefined error! | ||
mockAxios.create = jest.fn(() => mockAxios) | ||
mockAxios.defaults.baseURL = 'https://do.cat' | ||
|
||
export default mockAxios |
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 { shallowMount } from '@vue/test-utils' | ||
|
||
import ProjectRepository from '@/repositories/ProjectRepository' | ||
|
||
import Project from '@/components/Project.vue' | ||
|
||
ProjectRepository.getProjectLogoURL = (project) => `/api/${project}` | ||
ProjectRepository.getVersions = () => [ | ||
{ name: '1.0.0', type: 'directory' }, | ||
{ name: 'latest', type: 'directory' } | ||
] | ||
|
||
const project = 'awesome-project' | ||
const wrapper = shallowMount(Project, { | ||
propsData: { project }, | ||
stubs: { | ||
'router-link': true, | ||
'md-card': true, | ||
'md-card-header': true, | ||
'md-avatar': true | ||
} | ||
}) | ||
|
||
describe('Project.vue', () => { | ||
it('finds the latest version', () => { | ||
expect(wrapper.vm.$data.latestVersion).toMatch('latest') | ||
}) | ||
|
||
it('gets the correct logo url', () => { | ||
expect(wrapper.vm.$data.logoURL).toMatch('/api/awesome-project') | ||
}) | ||
|
||
it('fetches all versions correctly', () => { | ||
expect(wrapper.vm.$data.versions).toEqual(ProjectRepository.getVersions()) | ||
}) | ||
}) |
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,58 @@ | ||
import mockAxios from 'axios' | ||
|
||
import ProjectRepository from '@/repositories/ProjectRepository' | ||
|
||
afterEach(() => { | ||
mockAxios.get.mockClear() | ||
}) | ||
|
||
describe('ProjectRepository', () => { | ||
it('should return the correct logo URL', () => { | ||
expect(ProjectRepository.getProjectLogoURL('awesome-project')) | ||
.toMatch('https://do.cat/doc/awesome-project/logo.jpg') | ||
}) | ||
|
||
it('should return the correct docs URL', () => { | ||
expect(ProjectRepository.getProjectDocsURL('pet-project', '1.0.0')) | ||
.toMatch('https://do.cat/doc/pet-project/1.0.0/') | ||
}) | ||
|
||
it('should get all projects', async () => { | ||
const projects = [ | ||
{ name: 'awesome-project' }, | ||
{ name: 'pet-project' } | ||
] | ||
mockAxios.get.mockImplementationOnce(() => | ||
Promise.resolve({ data: projects }) | ||
) | ||
|
||
const result = (await ProjectRepository.get()).data | ||
|
||
expect(mockAxios.get).toHaveBeenCalledTimes(1) | ||
expect(result).toEqual(projects) | ||
}) | ||
|
||
it('should get all versions of a project', async () => { | ||
const versions = [ | ||
{ name: '1.0', type: 'directory' }, | ||
{ name: '2.0', type: 'directory' }, | ||
{ name: 'image.png', type: 'file' } | ||
] | ||
mockAxios.get.mockImplementationOnce(() => | ||
Promise.resolve({ data: versions }) | ||
) | ||
|
||
const result = await ProjectRepository.getVersions('awesome--project') | ||
|
||
expect(mockAxios.get).toHaveBeenCalledTimes(1) | ||
expect(result).toEqual(versions.filter((version) => version.type == 'directory')) | ||
}) | ||
|
||
it('should upload new documentation', async () => { | ||
mockAxios.post.mockImplementationOnce() | ||
|
||
await ProjectRepository.upload('awesome--project', '4.0', { data: true }) | ||
|
||
expect(mockAxios.post).toHaveBeenCalledTimes(1) | ||
}) | ||
}) |
Oops, something went wrong.