-
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.
- Loading branch information
Showing
6 changed files
with
2,812 additions
and
883 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 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`useEllipsis > should 1`] = `"<div>NOI is a h...</div>"`; |
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
import { ref, nextTick } from 'vue' | ||
import { describe, expect, it, test, beforeAll, afterAll } from 'vitest' | ||
import { mount } from '@vue/test-utils' | ||
import { useEllipsis } from '.' | ||
// basic usage | ||
// | ||
/** | ||
* 1. 正常渲染 | ||
* 3. content & ellipsisContent | ||
* 4. custom ellipsisText | ||
* 5. position | ||
* 6. rows | ||
* 7. 响应式,改变窗口resize,或者响应式容器,或者改变content | ||
* 8. 不同的行号 & 不同的字体大小 | ||
*/ | ||
const originGetComputedStyle = window.getComputedStyle | ||
|
||
const lineHeight = 20 | ||
|
||
const content = 'NOI is a hight performance/light weight headless UI library.' | ||
|
||
beforeAll(() => { | ||
window.getComputedStyle = (el) => ({ | ||
...originGetComputedStyle(el), | ||
get lineHeight() { | ||
return `${lineHeight}px` | ||
}, | ||
}) | ||
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', { | ||
get() { | ||
if (this.innerText.length < 10) { | ||
return lineHeight | ||
} | ||
if (this.innerText.includes('...')) { | ||
const row = Math.ceil( | ||
(this.innerText.replace(/\.\.\./g, '中').length / content.length) * 4 | ||
) | ||
return lineHeight * row | ||
} | ||
return lineHeight * 4 | ||
}, | ||
set() {}, | ||
configurable: true, | ||
}) | ||
}) | ||
|
||
afterAll(() => { | ||
window.getComputedStyle = originGetComputedStyle | ||
}) | ||
|
||
describe('useEllipsis', () => { | ||
it('should be defined', () => { | ||
expect(useEllipsis).toBeDefined() | ||
}) | ||
|
||
test('should ', async () => { | ||
const wrapper = mount({ | ||
setup() { | ||
const sourceContent = ref(content) | ||
const ellipsisRef = ref<HTMLElement>() | ||
const { content: ellipsisContent } = useEllipsis(ellipsisRef, { | ||
content: sourceContent, | ||
}) | ||
return () => <div ref={ellipsisRef}>{ellipsisContent.value}</div> | ||
}, | ||
}) | ||
|
||
await nextTick() | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
}) |
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
Oops, something went wrong.