adds tests for markdown draft / published attributes
This commit is contained in:
parent
4273c10a38
commit
cba4f2bd5c
11 changed files with 159 additions and 2 deletions
|
@ -17,7 +17,7 @@ Collections('shallow selector (*.md)', async ({ runtime }) => {
|
|||
}),
|
||||
];
|
||||
// assert they loaded in newest -> oldest order (not alphabetical)
|
||||
assert.equal(urls, ['/post/three', '/post/two', '/post/one']);
|
||||
assert.equal(urls, ['/post/six', '/post/five', '/post/three', '/post/two', '/post/one']);
|
||||
});
|
||||
|
||||
Collections('deep selector (**/*.md)', async ({ runtime }) => {
|
||||
|
@ -29,7 +29,7 @@ Collections('deep selector (**/*.md)', async ({ runtime }) => {
|
|||
return $(this).attr('href');
|
||||
}),
|
||||
];
|
||||
assert.equal(urls, ['/post/nested/a', '/post/three', '/post/two', '/post/one']);
|
||||
assert.equal(urls, ['/post/nested/a', '/post/six', '/post/five', '/post/three', '/post/two', '/post/one']);
|
||||
});
|
||||
|
||||
Collections('generates pagination successfully', async ({ runtime }) => {
|
||||
|
@ -123,4 +123,18 @@ Collections('matches collection filename exactly', async ({ runtime }) => {
|
|||
assert.equal(urls, ['/post/nested/a', '/post/three', '/post/two', '/post/one']);
|
||||
});
|
||||
|
||||
Collections('have the proper amount of elements with respecting published / draft documents', async ({ runtime }) => {
|
||||
const result = await runtime.load('/paginated');
|
||||
if (result.error) throw new Error(result.error);
|
||||
const $ = doc(result.contents);
|
||||
|
||||
|
||||
const start = $('#start');
|
||||
const end = $('#end');
|
||||
const total = $('#total');
|
||||
assert.equal(start.text(), "0");
|
||||
assert.equal(end.text(), "4");
|
||||
assert.equal(total.text(), "5");
|
||||
});
|
||||
|
||||
Collections.run();
|
||||
|
|
|
@ -22,6 +22,12 @@ export async function createCollection() {
|
|||
))}
|
||||
</div>
|
||||
|
||||
<div id="results">
|
||||
<span id="start">{collection.start}</span>
|
||||
<span id="end">{collection.end}</span>
|
||||
<span id="total">{collection.total}</span>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
{collection.url.prev && <a id="prev-page" href={collection.url.prev}>Previous page</a>}
|
||||
{collection.url.next && <a id="next-page" href={collection.url.next}>Next page</a>}
|
||||
|
|
9
packages/astro/test/fixtures/astro-collection/src/pages/post/five.md
vendored
Normal file
9
packages/astro/test/fixtures/astro-collection/src/pages/post/five.md
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Post Five
|
||||
date: 2021-04-17 00:00:00
|
||||
draft: false
|
||||
---
|
||||
|
||||
# Post Five
|
||||
|
||||
I’m the fifth blog post
|
9
packages/astro/test/fixtures/astro-collection/src/pages/post/four.md
vendored
Normal file
9
packages/astro/test/fixtures/astro-collection/src/pages/post/four.md
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Post Four
|
||||
date: 2021-04-16 00:00:00
|
||||
published: false
|
||||
---
|
||||
|
||||
# Post Four
|
||||
|
||||
I’m the fourth blog post
|
9
packages/astro/test/fixtures/astro-collection/src/pages/post/six.md
vendored
Normal file
9
packages/astro/test/fixtures/astro-collection/src/pages/post/six.md
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
title: Post Six
|
||||
date: 2021-04-18 00:00:00
|
||||
published: true
|
||||
---
|
||||
|
||||
# Post Six
|
||||
|
||||
I’m the sixth blog post
|
|
@ -1,7 +1,11 @@
|
|||
---
|
||||
title: Post Two
|
||||
date: 2021-04-14 00:00:00
|
||||
<<<<<<< HEAD
|
||||
author: author-two
|
||||
=======
|
||||
draft: true
|
||||
>>>>>>> dab211b (adds tests for markdown draft / published attributes)
|
||||
---
|
||||
|
||||
# Post Two
|
||||
|
|
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-draft.md
vendored
Normal file
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-draft.md
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
layout: ../layouts/content.astro
|
||||
title: My Blog Post
|
||||
description: This is a post about some stuff.
|
||||
published: true
|
||||
---
|
||||
|
||||
## Interesting Topic
|
||||
|
||||
Hello world!
|
||||
|
||||
```json
|
||||
{
|
||||
"key": "value"
|
||||
}
|
||||
```
|
||||
|
||||
<div id="first">Some content</div>
|
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-no-draft.md
vendored
Normal file
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-no-draft.md
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
layout: ../layouts/content.astro
|
||||
title: My Blog Post
|
||||
description: This is a post about some stuff.
|
||||
draft: false
|
||||
---
|
||||
|
||||
## Interesting Topic
|
||||
|
||||
Hello world!
|
||||
|
||||
```json
|
||||
{
|
||||
"key": "value"
|
||||
}
|
||||
```
|
||||
|
||||
<div id="first">Some content</div>
|
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-published.md
vendored
Normal file
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-published.md
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
layout: ../layouts/content.astro
|
||||
title: My Blog Post
|
||||
description: This is a post about some stuff.
|
||||
published: true
|
||||
---
|
||||
|
||||
## Interesting Topic
|
||||
|
||||
Hello world!
|
||||
|
||||
```json
|
||||
{
|
||||
"key": "value"
|
||||
}
|
||||
```
|
||||
|
||||
<div id="first">Some content</div>
|
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-unpublished.md
vendored
Normal file
18
packages/astro/test/fixtures/plain-markdown/src/pages/post-unpublished.md
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
layout: ../layouts/content.astro
|
||||
title: My Blog Post
|
||||
description: This is a post about some stuff.
|
||||
published: false
|
||||
---
|
||||
|
||||
## Interesting Topic
|
||||
|
||||
Hello world!
|
||||
|
||||
```json
|
||||
{
|
||||
"key": "value"
|
||||
}
|
||||
```
|
||||
|
||||
<div id="first">Some content</div>
|
|
@ -30,6 +30,40 @@ Markdown('Can load a realworld markdown page with Astro', async ({ runtime }) =>
|
|||
assert.equal($('pre').length, 7);
|
||||
});
|
||||
|
||||
Markdown('Cant load a post being unpublished', async ({ runtime }) => {
|
||||
const result = await runtime.load('/post-unpublished');
|
||||
|
||||
assert.type(result.error, 'object')
|
||||
assert.equal(result.error.message, 'Unpublished document');
|
||||
assert.equal(result.statusCode, 404);
|
||||
});
|
||||
|
||||
Markdown('Cant load a post being published', async ({ runtime }) => {
|
||||
const result = await runtime.load('/post-published');
|
||||
if (result.error) throw new Error(result.error);
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
assert.equal($('p').first().text(), 'Hello world!');
|
||||
assert.equal($('#first').text(), 'Some content');
|
||||
assert.equal($('#interesting-topic').text(), 'Interesting Topic');
|
||||
});
|
||||
|
||||
Markdown('Cant load a post being in draft status', async ({ runtime }) => {
|
||||
const result = await runtime.load('/post-draft');
|
||||
if (result.error) throw new Error(result.error);
|
||||
|
||||
assert.equal(result.statusCode, 200);
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
assert.equal($('p').first().text(), 'Hello world!');
|
||||
assert.equal($('#first').text(), 'Some content');
|
||||
assert.equal($('#interesting-topic').text(), 'Interesting Topic');
|
||||
});
|
||||
|
||||
Markdown('Builds markdown pages for prod', async (context) => {
|
||||
await context.build();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue