From cba4f2bd5c85c1be9979fc54fcfb8664deca1287 Mon Sep 17 00:00:00 2001 From: ewatch Date: Wed, 23 Jun 2021 00:11:01 +0200 Subject: [PATCH] adds tests for markdown draft / published attributes --- packages/astro/test/astro-collection.test.js | 18 ++++++++-- .../src/pages/$paginated.astro | 6 ++++ .../astro-collection/src/pages/post/five.md | 9 +++++ .../astro-collection/src/pages/post/four.md | 9 +++++ .../astro-collection/src/pages/post/six.md | 9 +++++ .../astro-collection/src/pages/post/two.md | 4 +++ .../plain-markdown/src/pages/post-draft.md | 18 ++++++++++ .../plain-markdown/src/pages/post-no-draft.md | 18 ++++++++++ .../src/pages/post-published.md | 18 ++++++++++ .../src/pages/post-unpublished.md | 18 ++++++++++ packages/astro/test/plain-markdown.test.js | 34 +++++++++++++++++++ 11 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 packages/astro/test/fixtures/astro-collection/src/pages/post/five.md create mode 100644 packages/astro/test/fixtures/astro-collection/src/pages/post/four.md create mode 100644 packages/astro/test/fixtures/astro-collection/src/pages/post/six.md create mode 100644 packages/astro/test/fixtures/plain-markdown/src/pages/post-draft.md create mode 100644 packages/astro/test/fixtures/plain-markdown/src/pages/post-no-draft.md create mode 100644 packages/astro/test/fixtures/plain-markdown/src/pages/post-published.md create mode 100644 packages/astro/test/fixtures/plain-markdown/src/pages/post-unpublished.md diff --git a/packages/astro/test/astro-collection.test.js b/packages/astro/test/astro-collection.test.js index 4f685b355..d3b73e5c4 100644 --- a/packages/astro/test/astro-collection.test.js +++ b/packages/astro/test/astro-collection.test.js @@ -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(); diff --git a/packages/astro/test/fixtures/astro-collection/src/pages/$paginated.astro b/packages/astro/test/fixtures/astro-collection/src/pages/$paginated.astro index d7383dffe..a061d4481 100644 --- a/packages/astro/test/fixtures/astro-collection/src/pages/$paginated.astro +++ b/packages/astro/test/fixtures/astro-collection/src/pages/$paginated.astro @@ -22,6 +22,12 @@ export async function createCollection() { ))} +
+ {collection.start} + {collection.end} + {collection.total} +
+