diff --git a/test/PaginationTest.js b/test/PaginationTest.js index 8f165f6c9..270ed6146 100644 --- a/test/PaginationTest.js +++ b/test/PaginationTest.js @@ -755,3 +755,41 @@ test("Pagination make sure pageNumber is numeric for {{ pageNumber + 1 }} Issue t.is(templates[0].data.pagination.pageNumber, 0); t.not(templates[0].data.pagination.pageNumber, "0"); }); + +test("Pagination mutable global data", async (t) => { + let eleventyConfig = new TemplateConfig(); + let dataObj = new TemplateData( + "./test/stubs/paged-global-data-mutable/", + eleventyConfig + ); + await dataObj.cacheData(); + + let tmpl = getNewTemplate( + "./test/stubs/paged-global-data-mutable/paged-differing-data-set.njk", + "./test/stubs/", + "./dist", + dataObj, + null, + eleventyConfig + ); + + let data = await tmpl.getData(); + let templates = await tmpl.getTemplates(data); + t.is(templates.length, 3); + t.deepEqual(templates[0].data.pagination.items[0], { + key1: "item1", + key2: "item2", + }); + t.deepEqual(templates[1].data.pagination.items[0], { + key3: "item3", + key4: "item4", + }); + t.deepEqual(templates[2].data.pagination.items[0], { + key5: "item5", + key6: "item6", + }); + + t.deepEqual(templates[0].data.item, { key1: "item1", key2: "item2" }); + t.deepEqual(templates[1].data.item, { key3: "item3", key4: "item4" }); + t.deepEqual(templates[2].data.item, { key5: "item5", key6: "item6" }); +}); diff --git a/test/stubs/paged-global-data-mutable/_data/testdata.js b/test/stubs/paged-global-data-mutable/_data/testdata.js new file mode 100644 index 000000000..97bd7a1e4 --- /dev/null +++ b/test/stubs/paged-global-data-mutable/_data/testdata.js @@ -0,0 +1,14 @@ +module.exports = [ + { + key1: "item1", + key2: "item2", + }, + { + key3: "item3", + key4: "item4", + }, + { + key5: "item5", + key6: "item6", + }, +]; diff --git a/test/stubs/paged-global-data-mutable/paged-differing-data-set.njk b/test/stubs/paged-global-data-mutable/paged-differing-data-set.njk new file mode 100644 index 000000000..be59f0db9 --- /dev/null +++ b/test/stubs/paged-global-data-mutable/paged-differing-data-set.njk @@ -0,0 +1,12 @@ +--- +pagination: + data: testdata + size: 1 + alias: item +--- +1:{{ item.key1 }} +2:{{ item.key2 }} +3:{{ item.key3 }} +4:{{ item.key4 }} +5:{{ item.key5 }} +6:{{ item.key6 }} \ No newline at end of file