-
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 #18 from sunquakes/development
Fixed tests coverage.
- Loading branch information
Showing
37 changed files
with
1,351 additions
and
193 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,6 @@ build/ | |
*.njsproj | ||
*.sln | ||
*.sw? | ||
*.db | ||
*.db | ||
|
||
coverage/* |
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,28 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import App from '../src/App.vue' | ||
import router from '../src/router/index' | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) | ||
|
||
test('Test User.vue', async () => { | ||
const wrapper = shallowMount(App, { | ||
propsData: {}, | ||
stubs: ['router-link', 'router-view'], | ||
global: { | ||
plugins: [router] | ||
} | ||
}) | ||
expect(wrapper.exists()).toBe(true) | ||
}) |
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,56 @@ | ||
import { pageList, login, del, edit, add } from '../../src/api/user' | ||
|
||
jest.mock('../../src/db/sqlite3', () => { | ||
return { | ||
page: jest.fn().mockResolvedValue({ | ||
records: [ | ||
{ | ||
id: 1, | ||
username: 'admin', | ||
password: '123456', | ||
nickname: '管理员' | ||
} | ||
], | ||
total: 1 | ||
}), | ||
getOne: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
username: 'admin', | ||
password: 'e10adc3949ba59abbe56e057f20f883e', | ||
nickname: '管理员' | ||
}), | ||
remove: jest.fn().mockResolvedValue(1), | ||
updateById: jest.fn().mockResolvedValue(1), | ||
save: jest.fn().mockResolvedValue(1) | ||
} | ||
}) | ||
|
||
describe('Test user api', () => { | ||
test('Test pageList', async () => { | ||
const res = await pageList(1, 10) | ||
expect(res.total).toBe(1) | ||
}) | ||
|
||
test('Test login', async () => { | ||
let res = await login('admin', '123456') | ||
expect(res.username).toBe('admin') | ||
|
||
res = await login('admin', '1234567') | ||
expect(res).toBeInstanceOf(Error) | ||
}) | ||
|
||
test('Test del', async () => { | ||
const res = await del([['id', '=', 1]]) | ||
expect(res).toBe(1) | ||
}) | ||
|
||
test('Test edit', async () => { | ||
const res = await edit(1, { nickname: '管理员' }) | ||
expect(res).toBe(1) | ||
}) | ||
|
||
test('Test add', async () => { | ||
const res = await add({ username: 'admin', nickname: '管理员' }) | ||
expect(res).toBe(1) | ||
}) | ||
}) |
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,43 @@ | ||
import { mount } from '@vue/test-utils' | ||
import Antd from 'ant-design-vue' | ||
import Layout from '../../src/components/Layout.vue' | ||
import BreadCrumb from '../../src/components/layout/BreadCrumb.vue' | ||
import Footer from '../../src/components/layout/Footer.vue' | ||
import Header from '../../src/components/layout/Header.vue' | ||
import Logo from '../../src/components/layout/Logo.vue' | ||
import Menu from '../../src/components/layout/Menu.vue' | ||
import i18n from '../../src/i18n' | ||
import router from '../../src/router/index' | ||
import store from '../../src/store/index' | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) | ||
|
||
test('Test Layout.vue', async () => { | ||
await router.push({ name: 'User' }) | ||
const wrapper = mount(Layout, { | ||
propsData: {}, | ||
global: { | ||
plugins: [Antd, router, store, i18n], | ||
components: { | ||
BreadCrumb, | ||
Footer, | ||
Header, | ||
Logo, | ||
Menu | ||
} | ||
} | ||
}) | ||
expect(wrapper.exists()).toBe(true) | ||
}) |
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,54 @@ | ||
import sqlite3 from 'sqlite3' | ||
import { mount } from '@vue/test-utils' | ||
import Login from '../../src/components/Login.vue' | ||
import Antd from 'ant-design-vue' | ||
import store from '../../src/store' | ||
import i18n from '../../src/i18n' | ||
|
||
jest.mock('sqlite3') | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) | ||
|
||
describe('Test Login.vue', () => { | ||
const wrapper = mount(Login, { | ||
propsData: {}, | ||
global: { | ||
plugins: [Antd, store, i18n] | ||
} | ||
}) | ||
|
||
test('Mount component', async () => { | ||
expect(wrapper.exists()).toBe(true) | ||
}) | ||
|
||
test('Submit the form', async () => { | ||
// Mock database instance | ||
sqlite3.Database = jest.fn().mockImplementation(() => { | ||
return { | ||
get: jest.fn(function (sql, callback) { | ||
callback(undefined, { id: 1, content: 'Hello World!', count: 1 }) | ||
}) | ||
} | ||
}) | ||
|
||
// Input username and password. | ||
const usernameInput = wrapper.find('input[id="normal_login_username"]') | ||
const passwordInput = wrapper.find('input[id="normal_login_password"]') | ||
await usernameInput.setValue('admin') | ||
await passwordInput.setValue('admin') | ||
|
||
await wrapper.find('form').trigger('submit') | ||
}) | ||
}) |
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,28 @@ | ||
import { shallowMount } from '@vue/test-utils' | ||
import User from '../../src/components/User.vue' | ||
import Antd from 'ant-design-vue' | ||
import i18n from '../../src/i18n' | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // Deprecated | ||
removeListener: jest.fn(), // Deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) | ||
|
||
test('Test User.vue', async () => { | ||
const wrapper = shallowMount(User, { | ||
propsData: {}, | ||
global: { | ||
plugins: [Antd, i18n] | ||
} | ||
}) | ||
expect(wrapper.exists()).toBe(true) | ||
}) |
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 @@ | ||
module.exports = {} |
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,7 @@ | ||
import { datetime } from '../../src/utils/date' | ||
describe('Test date utils', () => { | ||
test('Test datetime', async () => { | ||
const date = new Date('2024-05-29T00:00:00Z') | ||
expect(datetime(date)).toBe('2024-05-29 00:00:00') | ||
}) | ||
}) |
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,4 +1,4 @@ | ||
module.exports = { | ||
presets: [['@babel/preset-env', { targets: { node: 'current' } }]], | ||
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'], | ||
plugins: ['babel-plugin-rewire'] | ||
} |
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,9 +1,21 @@ | ||
module.exports = { | ||
transform: { | ||
'\\.js$': 'babel-jest' | ||
'\\.[jt]sx?$': 'babel-jest', | ||
'^[^.]+.vue$': '@vue/vue3-jest' | ||
}, | ||
testPathIgnorePatterns: ['<rootDir>/node_modules/'], | ||
collectCoverage: true, | ||
collectCoverageFrom: ['src/db/sqlite3.js'], | ||
collectCoverageFrom: ['src/**/**.vue', 'src/**/**.js', 'src/**/**.ts'], | ||
coverageDirectory: 'coverage', | ||
coverageReporters: ['text', 'lcov'] | ||
coverageProvider: 'v8', | ||
coverageReporters: ['text', 'lcov'], | ||
moduleFileExtensions: ['vue', 'js', 'ts'], | ||
testEnvironment: 'jsdom', | ||
testEnvironmentOptions: { | ||
customExportConditions: ['node', 'node-addons'] | ||
}, | ||
coveragePathIgnorePatterns: ['.d.ts'], | ||
moduleNameMapper: { | ||
'\\.(css|less)$': '<rootDir>/__test__/styleMock.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
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,5 +1,7 @@ | ||
sonar.organization=sunquakes | ||
sonar.projectKey=sunquakes_electron-kits | ||
|
||
sonar.exclusions=src/lang/**.js | ||
sonar.tests=__test__ | ||
sonar.sources=src | ||
sonar.exclusions=src/lang/**.ts,coverage/** | ||
sonar.javascript.lcov.reportPaths=coverage/lcov.info |
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,14 @@ | ||
export async function pageList( | ||
current: number, | ||
pageSize: number, | ||
where: string[][], | ||
orderBy: string | ||
): Promise<any> | ||
|
||
export async function login(username: string, password: string): Promise<any> | ||
|
||
export async function del(where: string[][]): Promise<any> | ||
|
||
export async function edit(id: number, data: any): Promise<any> | ||
|
||
export async function add(data: any): Promise<any> |
Oops, something went wrong.