47 lines
2.7 KiB
TypeScript
47 lines
2.7 KiB
TypeScript
/**
|
|
* 46-github: GitHub Desktop — 深层测试
|
|
* 覆盖: DOM(2)+仓库(3)+徽章(2)+README(4)+代码块(2)+边界(2)+卸载
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
|
|
import { h, render } from 'vue'
|
|
import GitHubComponent from '../../src/apps/github/GitHub.vue'
|
|
import { setupDOM } from '../helpers'
|
|
|
|
describe('46-github', () => {
|
|
let body: HTMLElement
|
|
beforeEach(() => { setupDOM(); const el = document.createElement('div'); el.className = 'window'; document.body.appendChild(el); body = document.createElement('div'); body.className = 'win-body'; el.appendChild(body) })
|
|
afterEach(() => { render(null, body); (body.parentElement as HTMLElement)?.remove() })
|
|
function m() { render(h(GitHubComponent, {}), body) }
|
|
function gh() { return body.querySelector('.gh-body') as HTMLElement }
|
|
|
|
// --- DOM ---
|
|
it('gh-body 容器', () => { m(); expect(gh()).toBeTruthy() })
|
|
it('gh-head 存在', () => { m(); expect(body.querySelector('.gh-head')).toBeTruthy() })
|
|
|
|
// --- 仓库 ---
|
|
it('仓库名含 macos-web', () => { m(); expect(body.querySelector('.gh-repo')?.textContent).toContain('macos-web') })
|
|
it('仓库名含 moonshot', () => { m(); expect(body.querySelector('.gh-repo')?.textContent).toContain('moonshot') })
|
|
it('仓库名是斜杠格式', () => { m(); expect(body.querySelector('.gh-repo')?.textContent).toContain('/') })
|
|
|
|
// --- 徽章 ---
|
|
it('★ 1024', () => { m(); const badges = body.querySelectorAll('.gh-badge'); expect([...badges].some(b => b.textContent?.includes('1024'))).toBe(true) })
|
|
it('⑂ 128', () => { m(); const badges = body.querySelectorAll('.gh-badge'); expect([...badges].some(b => b.textContent?.includes('128'))).toBe(true) })
|
|
|
|
// --- README ---
|
|
it('h2 标题 macos-web', () => { m(); expect(body.querySelector('.gh-readme h2')?.textContent).toBe('macos-web') })
|
|
it('h3 特性', () => { m(); expect(body.querySelector('.gh-readme h3')?.textContent).toBe('特性') })
|
|
it('含描述文本', () => { m(); expect(body.querySelector('.gh-readme')?.textContent).toContain('纯静态') })
|
|
it('含窗口管理器', () => { m(); expect(body.querySelector('.gh-readme')?.textContent).toContain('窗口管理器') })
|
|
|
|
// --- 代码块 ---
|
|
it('.sf-code 存在', () => { m(); expect(body.querySelector('.sf-code')).toBeTruthy() })
|
|
it('代码块含 git clone', () => { m(); expect(body.querySelector('.sf-code')?.textContent).toContain('git clone') })
|
|
|
|
// --- 边界 ---
|
|
it('gh-badges 两个', () => { m(); expect(body.querySelectorAll('.gh-badge').length).toBe(2) })
|
|
it('无 prop 不崩溃', () => { expect(() => render(h(GitHubComponent, {}), body)).not.toThrow() })
|
|
|
|
// --- 卸载 ---
|
|
it('卸载后 DOM 为空', () => { m(); render(null, body); expect(body.children.length).toBe(0) })
|
|
})
|