인아티클 광고 위치 계산 분리
This commit is contained in:
55
tests/content-in-article-ad.test.js
Normal file
55
tests/content-in-article-ad.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
getBlockPlainTextLength,
|
||||
getInArticleAdAfterBlockIds,
|
||||
getInArticleAdTargetRatios,
|
||||
isInArticleAdCandidateBlock
|
||||
} from '../lib/content-in-article-ad.js'
|
||||
|
||||
/**
|
||||
* 테스트용 문단 블록을 만든다.
|
||||
* @param {number} index - 블록 순서
|
||||
* @param {string} text - 본문 텍스트
|
||||
* @returns {Object} 문단 블록
|
||||
*/
|
||||
const createParagraphBlock = (index, text) => ({
|
||||
id: `paragraph-${index}`,
|
||||
type: 'paragraph',
|
||||
text
|
||||
})
|
||||
|
||||
test('블록 텍스트 길이는 배열과 문자열의 공백을 제외해 계산한다', () => {
|
||||
assert.equal(getBlockPlainTextLength({ text: '가 나 다' }), 3)
|
||||
assert.equal(getBlockPlainTextLength({ text: ['첫 줄', '둘째 줄'] }), 5)
|
||||
})
|
||||
|
||||
test('인아티클 광고 목표 비율은 본문 길이 기준으로 반환한다', () => {
|
||||
assert.deepEqual(getInArticleAdTargetRatios(1999), [])
|
||||
assert.deepEqual(getInArticleAdTargetRatios(2000), [0.4])
|
||||
assert.deepEqual(getInArticleAdTargetRatios(6000), [0.35, 0.7])
|
||||
})
|
||||
|
||||
test('후보 블록은 충분한 길이의 문단만 허용한다', () => {
|
||||
assert.equal(isInArticleAdCandidateBlock(createParagraphBlock(1, '충분히 긴 문단입니다'.repeat(2))), true)
|
||||
assert.equal(isInArticleAdCandidateBlock(createParagraphBlock(2, '짧음')), false)
|
||||
assert.equal(isInArticleAdCandidateBlock({ id: 'heading', type: 'heading', text: '충분히 긴 제목입니다' }), false)
|
||||
})
|
||||
|
||||
test('짧은 본문에는 인아티클 광고 삽입 위치를 만들지 않는다', () => {
|
||||
const blocks = Array.from({ length: 12 }, (_, index) => createParagraphBlock(index, '짧은 문단입니다'))
|
||||
|
||||
assert.deepEqual(getInArticleAdAfterBlockIds(blocks), [])
|
||||
})
|
||||
|
||||
test('긴 본문은 중앙 근처 문단 하나를 광고 삽입 위치로 선택한다', () => {
|
||||
const blocks = Array.from({ length: 12 }, (_, index) => createParagraphBlock(index, '가'.repeat(180)))
|
||||
|
||||
assert.deepEqual(getInArticleAdAfterBlockIds(blocks), ['paragraph-4'])
|
||||
})
|
||||
|
||||
test('매우 긴 본문은 충분한 간격을 두고 두 위치를 선택한다', () => {
|
||||
const blocks = Array.from({ length: 24 }, (_, index) => createParagraphBlock(index, '가'.repeat(260)))
|
||||
|
||||
assert.deepEqual(getInArticleAdAfterBlockIds(blocks), ['paragraph-8', 'paragraph-16'])
|
||||
})
|
||||
Reference in New Issue
Block a user