File size: 5,525 Bytes
f1bab00 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | /*!
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
var fs = require('fs'),
path = require('../../../../tests/lib/screenshot-testing/support/path');
describe("CustomLogoUpload", function () {
const contentSelector = 'div[vue-entry="CoreAdminHome.BrandingSettings"]';
const logoToUpload = path.join(PIWIK_INCLUDE_PATH, "/tests/resources/customlogo/logo.png");
const faviconToUpload = path.join(PIWIK_INCLUDE_PATH, "/tests/resources/customlogo/favicon.png");
const logoPublicPath = path.join(PIWIK_INCLUDE_PATH, "/misc/user/logo.png");
const faviconPublicPath = path.join(PIWIK_INCLUDE_PATH, "/misc/user/favicon.png");
// ba16a2cfb817c43df28fde559b8ee4774f422602 is sha1 of superUserLogin login
const logoTmpPath = path.join(PIWIK_INCLUDE_PATH, "/tmp/logos/ba16a2cfb817c43df28fde559b8ee4774f422602/logo.png");
const faviconTmpPath = path.join(PIWIK_INCLUDE_PATH, "/tmp/logos/ba16a2cfb817c43df28fde559b8ee4774f422602/favicon.png");
before(function () {
testEnvironment.optionsOverride = {
branding_use_custom_logo: '1'
};
testEnvironment.save();
});
it('should enable logo upload', async function() {
await page.goto('?module=CoreAdminHome&action=generalSettings');
await page.waitForNetworkIdle();
await page.evaluate(function(){
$('input[name="useCustomLogo"]').trigger('change');
});
await page.waitForTimeout(200);
expect(await page.screenshotSelector(contentSelector)).to.matchImage('enable_logo_upload');
});
it('should upload a custom logo', async function() {
const fileInput = await page.$('input[name=customLogo]');
await fileInput.uploadFile(logoToUpload);
await page.waitForTimeout(2000);
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(contentSelector)).to.matchImage('custom_logo_uploaded');
expect(fs.existsSync(logoTmpPath)).to.be.true; // custom file uploaded into tmp folder
expect(fs.existsSync(logoPublicPath)).to.be.false; // custom file not published as not saved
});
it('should publish custom logo when settings are saved', async function() {
await page.click('[vue-entry="CoreAdminHome.BrandingSettings"] .matomo-save-button');
await page.waitForTimeout(1000);
await page.waitForNetworkIdle();
expect(fs.existsSync(logoPublicPath)).to.be.true;
expect(fs.existsSync(logoTmpPath)).to.be.false;
expect(fs.existsSync(faviconPublicPath)).to.be.false;
expect(fs.existsSync(faviconTmpPath)).to.be.false;
});
it('should upload a custom favicon without a page reload', async function() {
const fileInput = await page.$('input[name=customFavicon]');
await fileInput.uploadFile(faviconToUpload);
await page.waitForTimeout(2000);
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(contentSelector)).to.matchImage('custom_favicon_uploaded');
expect(fs.existsSync(faviconTmpPath)).to.be.true; // custom file uploaded into tmp folder
expect(fs.existsSync(faviconPublicPath)).to.be.false;
});
it('should publish custom favicon and not alter custom logo when settings are saved again', async function() {
await page.click('[vue-entry="CoreAdminHome.BrandingSettings"] .matomo-save-button');
await page.waitForTimeout(1000);
await page.waitForNetworkIdle();
expect(fs.existsSync(logoPublicPath)).to.be.true;
expect(fs.existsSync(logoTmpPath)).to.be.false;
expect(fs.existsSync(faviconPublicPath)).to.be.true;
expect(fs.existsSync(faviconTmpPath)).to.be.false;
});
it('should display custom logo and favicon when settings page is reloaded', async function() {
await page.reload();
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(contentSelector)).to.matchImage('branding_settings_reloaded_first');
});
it('should not change anything when settings are saved with custom logos present', async function() {
await page.click('[vue-entry="CoreAdminHome.BrandingSettings"] .matomo-save-button');
await page.waitForTimeout(1000);
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(contentSelector)).to.matchImage('branding_settings_reloaded_second');
expect(fs.existsSync(logoPublicPath)).to.be.true;
expect(fs.existsSync(faviconPublicPath)).to.be.true;
expect(fs.existsSync(logoTmpPath)).to.be.false;
expect(fs.existsSync(faviconTmpPath)).to.be.false;
});
it('should disable custom logo feature and save settings', async function() {
const cb = await page.waitForSelector('input[name="useCustomLogo"]');
await cb.click();
await page.waitForTimeout(200);
await page.click('[vue-entry="CoreAdminHome.BrandingSettings"] .matomo-save-button');
await page.waitForTimeout(1000);
await page.waitForNetworkIdle();
expect(await page.screenshotSelector(contentSelector)).to.matchImage('disable_logo_upload');
expect(fs.existsSync(logoPublicPath)).to.be.false;
expect(fs.existsSync(logoTmpPath)).to.be.false;
expect(fs.existsSync(faviconPublicPath)).to.be.false;
expect(fs.existsSync(faviconTmpPath)).to.be.false;
});
});
|