test: make it work again

This commit is contained in:
07akioni 2020-11-03 11:53:37 +08:00
parent 4c292ad77e
commit 739bc6d619
14 changed files with 115 additions and 112 deletions

View File

@ -23,7 +23,8 @@ module.exports = {
files: '*.spec.js',
globals: {
describe: 'readonly',
it: 'readonly'
it: 'readonly',
expect: 'readonly'
}
},
{

View File

@ -58,7 +58,9 @@ module.exports = {
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
// globals: {},
globals: {
__DEV__: false
},
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

View File

@ -26,7 +26,7 @@
"tusimple:release:doc": "npm run tusimple:build:doc && node build-doc/generate-deploy-sh.js && sudo bash build-doc/deploy-doc.sh",
"tusimple:release:doc:no-build": "node build-doc/generate-deploy-sh.js && sudo bash build-doc/deploy-doc.sh"
},
"author": "lecong.zhang",
"author": "07akioni",
"license": "MIT",
"publishConfig": {
"registry": "***REMOVED***"
@ -40,12 +40,15 @@
"README.md"
],
"devDependencies": {
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-node-resolve": "^10.0.0",
"@types/jest": "^26.0.15",
"@vue/compiler-sfc": "^3.0.2",
"@vue/eslint-config-standard": "^5.1.2",
"@vue/test-utils": "^2.0.0-beta.8",
"autoprefixer": "^9.8.6",
"babel-jest": "^26.6.2",
"cross-env": "^5.2.1",
"cssnano": "^4.1.10",
"eslint": "^7.12.1",
@ -61,6 +64,7 @@
"stylelint-config-recommended-scss": "^4.2.0",
"stylelint-scss": "^3.18.0",
"tinycolor2": "^1.4.2",
"typescript": "^4.0.5",
"vite": "^1.0.0-rc.8",
"vue-jest": "^5.0.0-alpha.5",
"vue-router": "^4.0.0-rc.1"

View File

@ -0,0 +1,2 @@
export { default as baseSuffixLight } from './light'
export { default as baseSuffixDark } from './dark'

View File

@ -40,9 +40,9 @@ function setupMutableStyle (
instance,
theme,
dependencyKey,
CNode,
moduleSrcUpdated
CNode
) {
console.log(instance, instance.$naive)
const naive = instance.$naive
const options = instance.$options
const {
@ -132,7 +132,7 @@ function getCssrProps (
}
}
export default function (styles, cssrPropsOption) {
const usecssr = function (styles, cssrPropsOption) {
// collect watchers
const watchers = {}
if (
@ -221,3 +221,5 @@ export default function (styles, cssrPropsOption) {
watch
}
}
export default usecssr

View File

@ -57,6 +57,7 @@ function create ({
setHljs,
setHighlightjs: setHljs,
use (plugin) {
console.log('use naive ui')
plugin.install(naive)
},
install

2
src/locale/index.js Normal file
View File

@ -0,0 +1,2 @@
export { default as zhCN } from './zhCN'
export { default as enUS } from './enUS'

View File

@ -1,11 +1,12 @@
import create from '../../_styles/utils/create-component-base'
import { changeColor } from '../../_utils/color/index'
import suffixStyle from '../../_base/suffix/styles/dark'
import { baseSuffixDark } from '../../_base/suffix/styles'
import { baseDark } from '../../styles/base'
export default create({
name: 'Pagination',
theme: 'dark',
peer: [ suffixStyle ],
peer: [baseSuffixDark, baseDark],
getDerivedVariables ({ base, derived }) {
const {
textColor2Overlay,

View File

@ -0,0 +1,2 @@
export { default as paginationLight } from './light'
export { default as paginationDark } from './dark'

View File

@ -1,10 +1,11 @@
import create from '../../_styles/utils/create-component-base'
import suffixStyle from '../../_base/suffix/styles/dark'
import { baseSuffixLight } from '../../_base/suffix/styles'
import { baseLight } from '../../styles/base'
export default create({
name: 'Pagination',
theme: 'light',
peer: [ suffixStyle ],
peer: [baseSuffixLight, baseLight],
getDerivedVariables ({ base, derived }) {
const {
textColor2,

View File

@ -1,49 +1,33 @@
import Vue from 'vue'
import { expect } from 'chai'
import create from '../../create'
import { enUS } from '../../locale'
import { paginationLight } from '../styles'
import { mount } from '@vue/test-utils'
import Pagination from '../index'
import create from '../../create'
import zhCN from '../../locale/zhCN'
import enUS from '../../locale/enUS'
import { lightStyleScheme, darkStyleScheme } from '../../_deprecated/style-scheme'
import paginationLightStyle from '../styles/light'
import paginationDarkStyle from '../styles/dark'
import baseDarkStyle from '../../styles/base/dark'
import baseLightStyle from '../../styles/base/light'
describe('n-pagination', () => {
const naive = create({
fallbackLocale: enUS,
fallbackTheme: 'light',
styles: [
paginationLight
]
})
describe('props.page', () => {
it('should work', () => {
const naive = create({
locales: [zhCN, enUS],
fallbackLocale: enUS,
fallbackTheme: 'light',
components: [
Pagination
],
styles: [
baseLightStyle,
baseDarkStyle,
paginationLightStyle,
paginationDarkStyle
],
styleSchemes: {
light: lightStyleScheme,
dark: darkStyleScheme
}
})
Vue.use(naive)
const wrapper = mount(Pagination, {
propsData: {
props: {
page: 5,
pageCount: 10
},
global: {
plugins: [naive]
}
})
expect(
wrapper
.find('.n-pagination-item--active')
.text()
).to.equal('5')
).toEqual('5')
})
})
})

View File

@ -1,85 +1,84 @@
import { expect } from 'chai'
import { pagesToShow, mapPagesToPageItems, pageItems } from '../src/utils'
describe('Pagination', function () {
describe('utils', function () {
describe('#pagesToShow', function () {
it('should work when less than 9 total pages', function () {
expect(pagesToShow(1, 1)).to.deep.equal([1])
expect(pagesToShow(1, 2)).to.deep.equal([1, 2])
expect(pagesToShow(2, 2)).to.deep.equal([1, 2])
expect(pagesToShow(1, 3)).to.deep.equal([1, 2, 3])
expect(pagesToShow(2, 3)).to.deep.equal([1, 2, 3])
expect(pagesToShow(3, 3)).to.deep.equal([1, 2, 3])
expect(pagesToShow(1, 4)).to.deep.equal([1, 2, 3, 4])
expect(pagesToShow(2, 4)).to.deep.equal([1, 2, 3, 4])
expect(pagesToShow(3, 4)).to.deep.equal([1, 2, 3, 4])
expect(pagesToShow(4, 4)).to.deep.equal([1, 2, 3, 4])
expect(pagesToShow(1, 5)).to.deep.equal([1, 2, 3, 4, 5])
expect(pagesToShow(2, 5)).to.deep.equal([1, 2, 3, 4, 5])
expect(pagesToShow(3, 5)).to.deep.equal([1, 2, 3, 4, 5])
expect(pagesToShow(4, 5)).to.deep.equal([1, 2, 3, 4, 5])
expect(pagesToShow(5, 5)).to.deep.equal([1, 2, 3, 4, 5])
expect(pagesToShow(1, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(2, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(3, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(4, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(5, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(6, 6)).to.deep.equal([1, 2, 3, 4, 5, 6])
expect(pagesToShow(1, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(2, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(3, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(4, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(5, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(6, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(7, 7)).to.deep.equal([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(1, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(2, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(3, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(4, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(5, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(6, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(7, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(8, 8)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(1, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(2, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(3, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(4, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(5, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(6, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(7, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(8, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(9, 9)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(1, 1)).toEqual([1])
expect(pagesToShow(1, 2)).toEqual([1, 2])
expect(pagesToShow(2, 2)).toEqual([1, 2])
expect(pagesToShow(1, 3)).toEqual([1, 2, 3])
expect(pagesToShow(2, 3)).toEqual([1, 2, 3])
expect(pagesToShow(3, 3)).toEqual([1, 2, 3])
expect(pagesToShow(1, 4)).toEqual([1, 2, 3, 4])
expect(pagesToShow(2, 4)).toEqual([1, 2, 3, 4])
expect(pagesToShow(3, 4)).toEqual([1, 2, 3, 4])
expect(pagesToShow(4, 4)).toEqual([1, 2, 3, 4])
expect(pagesToShow(1, 5)).toEqual([1, 2, 3, 4, 5])
expect(pagesToShow(2, 5)).toEqual([1, 2, 3, 4, 5])
expect(pagesToShow(3, 5)).toEqual([1, 2, 3, 4, 5])
expect(pagesToShow(4, 5)).toEqual([1, 2, 3, 4, 5])
expect(pagesToShow(5, 5)).toEqual([1, 2, 3, 4, 5])
expect(pagesToShow(1, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(2, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(3, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(4, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(5, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(6, 6)).toEqual([1, 2, 3, 4, 5, 6])
expect(pagesToShow(1, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(2, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(3, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(4, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(5, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(6, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(7, 7)).toEqual([1, 2, 3, 4, 5, 6, 7])
expect(pagesToShow(1, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(2, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(3, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(4, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(5, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(6, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(7, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(8, 8)).toEqual([1, 2, 3, 4, 5, 6, 7, 8])
expect(pagesToShow(1, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(2, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(3, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(4, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(5, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(6, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(7, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(8, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
expect(pagesToShow(9, 9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9])
})
it('should work when totalPage is 10', function () {
expect(pagesToShow(1, 10)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(2, 10)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(3, 10)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(4, 10)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(5, 10)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(6, 10)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(7, 10)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(8, 10)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(9, 10)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(10, 10)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(1, 10)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(2, 10)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(3, 10)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(4, 10)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(5, 10)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 10])
expect(pagesToShow(6, 10)).toEqual([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(7, 10)).toEqual([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(8, 10)).toEqual([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(9, 10)).toEqual([1, -2, 4, 5, 6, 7, 8, 9, 10])
expect(pagesToShow(10, 10)).toEqual([1, -2, 4, 5, 6, 7, 8, 9, 10])
})
it('should work when totalPage is 11', function () {
expect(pagesToShow(1, 11)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(2, 11)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(3, 11)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(4, 11)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(5, 11)).to.deep.equal([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(6, 11)).to.deep.equal([1, -2, 4, 5, 6, 7, 8, -1, 11])
expect(pagesToShow(7, 11)).to.deep.equal([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(8, 11)).to.deep.equal([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(9, 11)).to.deep.equal([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(10, 11)).to.deep.equal([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(11, 11)).to.deep.equal([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(1, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(2, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(3, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(4, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(5, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, -1, 11])
expect(pagesToShow(6, 11)).toEqual([1, -2, 4, 5, 6, 7, 8, -1, 11])
expect(pagesToShow(7, 11)).toEqual([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(8, 11)).toEqual([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(9, 11)).toEqual([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(10, 11)).toEqual([1, -2, 5, 6, 7, 8, 9, 10, 11])
expect(pagesToShow(11, 11)).toEqual([1, -2, 5, 6, 7, 8, 9, 10, 11])
})
})
describe('#mapPagesToPageItems', function () {
it('should return corresponding items', function () {
expect(mapPagesToPageItems([-2, -1, 1, 2], 1)).to.deep.equal([
expect(mapPagesToPageItems([-2, -1, 1, 2], 1)).toEqual([
{
type: 'fastBackward',
label: 'fastBackward'
@ -103,7 +102,7 @@ describe('Pagination', function () {
})
describe('#pageItems', function () {
it('should work', function () {
expect(pageItems(6, 11)).to.deep.equal([{
expect(pageItems(6, 11)).toEqual([{
type: 'page',
label: 1,
active: false

2
src/styles/base/index.js Normal file
View File

@ -0,0 +1,2 @@
export { default as baseDark } from './dark'
export { default as baseLight } from './light'

View File

@ -20,11 +20,11 @@ module.exports = {
alias: {
'/@naive-ui/lib/icons/': path.resolve(__dirname, './src/_deprecated/icons'),
'/@naive-ui/': path.resolve(__dirname, './src'),
'src': path.resolve(__dirname, './src')
src: path.resolve(__dirname, './src')
},
define: {
'process.env.NODE_ENV': `'${process.env.NODE_ENV}'`,
'__DEV__': process.env.NODE_ENV !== 'production'
__DEV__: process.env.NODE_ENV !== 'production'
},
rollupPluginVueOptions: {
include: /\.(vue|md|demo.md|demo-entry.md|entry)$/