Skip to content

Commit 0431e1c

Browse files
committed
test: public api
1 parent 76fb2ab commit 0431e1c

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,63 @@ describe('enhancer', () => {
194194
})
195195
})
196196

197+
describe('public api', () => {
198+
test('dirname', async () => {
199+
const dirname = 'docs'
200+
const { relative, filePath } = getDocument('README.md')
201+
const markdown = getMarkdown()
202+
const page = await setupPage({ filePath, relative }, { markdown })
203+
expect(page.dirname).toBe(dirname)
204+
})
205+
206+
test('filename', async () => {
207+
const filename = 'README'
208+
const { relative, filePath } = getDocument(`${filename}.md`)
209+
const markdown = getMarkdown()
210+
const page = await setupPage({ filePath, relative }, { markdown })
211+
expect(page.filename).toBe(filename)
212+
})
213+
214+
test('slug', async () => {
215+
const markdown = getMarkdown()
216+
const dirname = 'docs'
217+
const indexPageFixture = getDocument('README.md')
218+
const indexPage = await setupPage(
219+
{ filePath: indexPageFixture.filePath, relative: indexPageFixture.relative }, { markdown }
220+
)
221+
expect(indexPage.slug).toBe(dirname)
222+
223+
const filename = 'alpha'
224+
const pageFixture = getDocument(`${filename}.md`)
225+
const page = await setupPage(
226+
{ filePath: pageFixture.filePath, relative: pageFixture.relative }, { markdown }
227+
)
228+
expect(page.slug).toBe(filename)
229+
})
230+
231+
test('strippedFilename', async () => {
232+
const { relative, filePath } = getDocument('2020-01-01-date.md')
233+
const markdown = getMarkdown()
234+
const page = await setupPage({ filePath, relative }, { markdown })
235+
expect(page.strippedFilename).toBe('date')
236+
})
237+
238+
test('date', async () => {
239+
const frontmatter = { date: '2020-01-01' }
240+
const dateInFrontmatterPage = await setupPage({ path: '/', frontmatter })
241+
expect(dateInFrontmatterPage.date).toBe('2020-01-01')
242+
243+
const { relative, filePath } = getDocument('2020-01-01-date.md')
244+
const markdown = getMarkdown()
245+
const dateInPathPage = await setupPage({ filePath, relative }, { markdown })
246+
expect(dateInPathPage.date).toBe('2020-01-01')
247+
})
248+
})
249+
197250
// TODO permalink - driven by global pattern
198251
// TODO I18n
199-
// TODO Meta
200252
// TODO Add a page with explicit content
201253
// TODO Excerpt
202254
// TODO SFC
203255
// TODO Headers
204256

205-
// TODO get date
206-
// TODO get strippedFilename
207-
// TODO get slug
208-
// TODO get filename
209-
// TODO get dirname
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Date

0 commit comments

Comments
 (0)