From 40fee069c96da64aa3d3b2d5499f65826f9c4581 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Mon, 6 Dec 2021 15:11:54 +0000 Subject: [PATCH] Moved locale testing out of casper fixture (#13850) refs: https://github.com/TryGhost/Toolbox/issues/137#issuecomment-986829141 - Moving the weird customisation of Casper out of the test fixture - Created a standalone theme for testing locales instead - This should make it easier for us to update our Casper fixture --- test/e2e-api/admin/themes.test.js | 25 ++++++++++++------- test/unit/frontend/helpers/t.test.js | 8 +++--- .../{casper => locale-theme}/locales/de.json | 0 .../{casper => locale-theme}/locales/en.json | 0 .../fixtures/themes/locale-theme/package.json | 12 +++++++++ 5 files changed, 32 insertions(+), 13 deletions(-) rename test/utils/fixtures/themes/{casper => locale-theme}/locales/de.json (100%) rename test/utils/fixtures/themes/{casper => locale-theme}/locales/en.json (100%) create mode 100644 test/utils/fixtures/themes/locale-theme/package.json diff --git a/test/e2e-api/admin/themes.test.js b/test/e2e-api/admin/themes.test.js index dda10afa41..b153dd8003 100644 --- a/test/e2e-api/admin/themes.test.js +++ b/test/e2e-api/admin/themes.test.js @@ -47,7 +47,7 @@ describe('Themes API', function () { const jsonResponse = res.body; should.exist(jsonResponse.themes); localUtils.API.checkResponse(jsonResponse, 'themes'); - jsonResponse.themes.length.should.eql(6); + jsonResponse.themes.length.should.eql(7); localUtils.API.checkResponse(jsonResponse.themes[0], 'theme'); jsonResponse.themes[0].name.should.eql('broken-theme'); @@ -65,19 +65,24 @@ describe('Themes API', function () { jsonResponse.themes[2].active.should.be.false(); localUtils.API.checkResponse(jsonResponse.themes[3], 'theme'); - jsonResponse.themes[3].name.should.eql('price-data-test-theme'); + jsonResponse.themes[3].name.should.eql('locale-theme'); jsonResponse.themes[3].package.should.be.an.Object().with.properties('name', 'version'); jsonResponse.themes[3].active.should.be.false(); localUtils.API.checkResponse(jsonResponse.themes[4], 'theme'); - jsonResponse.themes[4].name.should.eql('test-theme'); + jsonResponse.themes[4].name.should.eql('price-data-test-theme'); jsonResponse.themes[4].package.should.be.an.Object().with.properties('name', 'version'); jsonResponse.themes[4].active.should.be.false(); localUtils.API.checkResponse(jsonResponse.themes[5], 'theme'); - jsonResponse.themes[5].name.should.eql('test-theme-channels'); - jsonResponse.themes[5].package.should.be.false(); + jsonResponse.themes[5].name.should.eql('test-theme'); + jsonResponse.themes[5].package.should.be.an.Object().with.properties('name', 'version'); jsonResponse.themes[5].active.should.be.false(); + + localUtils.API.checkResponse(jsonResponse.themes[6], 'theme'); + jsonResponse.themes[6].name.should.eql('test-theme-channels'); + jsonResponse.themes[6].package.should.be.false(); + jsonResponse.themes[6].active.should.be.false(); }); it('Can download a theme', async function () { @@ -124,7 +129,7 @@ describe('Themes API', function () { should.exist(jsonResponse3.themes); localUtils.API.checkResponse(jsonResponse3, 'themes'); - jsonResponse3.themes.length.should.eql(7); + jsonResponse3.themes.length.should.eql(8); // Casper should be present and still active const casperTheme = _.find(jsonResponse3.themes, {name: 'casper'}); @@ -143,6 +148,7 @@ describe('Themes API', function () { 'broken-theme', 'casper', 'casper-1.4', + 'locale-theme', 'price-data-test-theme', 'test-theme', 'test-theme-channels', @@ -167,7 +173,7 @@ describe('Themes API', function () { tmpFolderContents.splice(i, 1); } } - tmpFolderContents.should.be.an.Array().with.lengthOf(10); + tmpFolderContents.should.be.an.Array().with.lengthOf(11); tmpFolderContents.should.eql([ 'broken-theme', @@ -175,6 +181,7 @@ describe('Themes API', function () { 'casper-1.4', 'casper.zip', 'invalid.zip', + 'locale-theme', 'price-data-test-theme', 'test-theme', 'test-theme-channels', @@ -192,7 +199,7 @@ describe('Themes API', function () { should.exist(jsonResponse2.themes); localUtils.API.checkResponse(jsonResponse2, 'themes'); - jsonResponse2.themes.length.should.eql(6); + jsonResponse2.themes.length.should.eql(7); // Casper should be present and still active const casperTheme = _.find(jsonResponse2.themes, {name: 'casper'}); @@ -234,7 +241,7 @@ describe('Themes API', function () { should.exist(jsonResponse.themes); localUtils.API.checkResponse(jsonResponse, 'themes'); - jsonResponse.themes.length.should.eql(6); + jsonResponse.themes.length.should.eql(7); const casperTheme = _.find(jsonResponse.themes, {name: 'casper'}); should.exist(casperTheme); diff --git a/test/unit/frontend/helpers/t.test.js b/test/unit/frontend/helpers/t.test.js index d3a0b00b98..433365936c 100644 --- a/test/unit/frontend/helpers/t.test.js +++ b/test/unit/frontend/helpers/t.test.js @@ -15,7 +15,7 @@ describe('{{t}} helper', function () { }); it('theme translation is DE', function () { - themeI18n.init({activeTheme: 'casper', locale: 'de'}); + themeI18n.init({activeTheme: 'locale-theme', locale: 'de'}); let rendered = t.call({}, 'Top left Button', { hash: {} @@ -25,7 +25,7 @@ describe('{{t}} helper', function () { }); it('theme translation is EN', function () { - themeI18n.init({activeTheme: 'casper', locale: 'en'}); + themeI18n.init({activeTheme: 'locale-theme', locale: 'en'}); let rendered = t.call({}, 'Top left Button', { hash: {} @@ -35,7 +35,7 @@ describe('{{t}} helper', function () { }); it('[fallback] no theme translation file found for FR', function () { - themeI18n.init({activeTheme: 'casper', locale: 'fr'}); + themeI18n.init({activeTheme: 'locale-theme', locale: 'fr'}); let rendered = t.call({}, 'Top left Button', { hash: {} @@ -45,7 +45,7 @@ describe('{{t}} helper', function () { }); it('[fallback] no theme files at all, use key as translation', function () { - themeI18n.init({activeTheme: 'casper-1.4', locale: 'de'}); + themeI18n.init({activeTheme: 'locale-theme-1.4', locale: 'de'}); let rendered = t.call({}, 'Top left Button', { hash: {} diff --git a/test/utils/fixtures/themes/casper/locales/de.json b/test/utils/fixtures/themes/locale-theme/locales/de.json similarity index 100% rename from test/utils/fixtures/themes/casper/locales/de.json rename to test/utils/fixtures/themes/locale-theme/locales/de.json diff --git a/test/utils/fixtures/themes/casper/locales/en.json b/test/utils/fixtures/themes/locale-theme/locales/en.json similarity index 100% rename from test/utils/fixtures/themes/casper/locales/en.json rename to test/utils/fixtures/themes/locale-theme/locales/en.json diff --git a/test/utils/fixtures/themes/locale-theme/package.json b/test/utils/fixtures/themes/locale-theme/package.json new file mode 100644 index 0000000000..8bbbc6672d --- /dev/null +++ b/test/utils/fixtures/themes/locale-theme/package.json @@ -0,0 +1,12 @@ +{ + "name": "locale-theme", + "description": "A fake theme for testing locales.", + "version": "1.0.0", + "engines": { + "ghost-api": "v4" + }, + "license": "MIT", + "config": { + "posts_per_page": 5 + } +}