mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
favicon: Redo favicon customization
This commit is contained in:
parent
92e0bff80c
commit
ea8846154f
10 changed files with 64 additions and 13 deletions
BIN
src/tests/backend/specs/favicon-test-custom.png
Normal file
BIN
src/tests/backend/specs/favicon-test-custom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 635 B |
|
@ -12,11 +12,13 @@ describe(__filename, function () {
|
|||
let agent;
|
||||
let backupSettings;
|
||||
let skinDir;
|
||||
let wantCustomIcon;
|
||||
let wantDefaultIcon;
|
||||
let wantSkinIcon;
|
||||
|
||||
before(async function () {
|
||||
agent = await common.init();
|
||||
wantCustomIcon = await fsp.readFile(path.join(__dirname, 'favicon-test-custom.png'));
|
||||
wantDefaultIcon = await fsp.readFile(path.join(settings.root, 'src', 'static', 'favicon.ico'));
|
||||
wantSkinIcon = await fsp.readFile(path.join(__dirname, 'favicon-test-skin.png'));
|
||||
});
|
||||
|
@ -28,6 +30,7 @@ describe(__filename, function () {
|
|||
});
|
||||
|
||||
afterEach(async function () {
|
||||
delete settings.favicon;
|
||||
delete settings.skinName;
|
||||
Object.assign(settings, backupSettings);
|
||||
try {
|
||||
|
@ -38,8 +41,40 @@ describe(__filename, function () {
|
|||
} catch (err) { /* intentionally ignored */ }
|
||||
});
|
||||
|
||||
it('uses custom favicon if set (relative pathname)', async function () {
|
||||
settings.favicon =
|
||||
path.relative(settings.root, path.join(__dirname, 'favicon-test-custom.png'));
|
||||
assert(!path.isAbsolute(settings.favicon));
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
.expect(200);
|
||||
assert(gotIcon.equals(wantCustomIcon));
|
||||
});
|
||||
|
||||
it('uses custom favicon if set (absolute pathname)', async function () {
|
||||
settings.favicon = path.join(__dirname, 'favicon-test-custom.png');
|
||||
assert(path.isAbsolute(settings.favicon));
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
.expect(200);
|
||||
assert(gotIcon.equals(wantCustomIcon));
|
||||
});
|
||||
|
||||
it('falls back if custom favicon is missing', async function () {
|
||||
// The previous default for settings.favicon was 'favicon.ico', so many users will continue to
|
||||
// have that in their settings.json for a long time. There is unlikely to be a favicon at
|
||||
// path.resolve(settings.root, 'favicon.ico'), so this test ensures that 'favicon.ico' won't be
|
||||
// a problem for those users.
|
||||
settings.favicon = 'favicon.ico';
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
.expect(200);
|
||||
assert(gotIcon.equals(wantDefaultIcon));
|
||||
});
|
||||
|
||||
it('uses skin favicon if present', async function () {
|
||||
await fsp.writeFile(path.join(skinDir, 'favicon.ico'), wantSkinIcon);
|
||||
settings.favicon = null;
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
.expect(200);
|
||||
|
@ -47,6 +82,7 @@ describe(__filename, function () {
|
|||
});
|
||||
|
||||
it('falls back to default favicon', async function () {
|
||||
settings.favicon = null;
|
||||
const {body: gotIcon} = await agent.get('/favicon.ico')
|
||||
.accept('png').buffer(true).parse(superagent.parse.image)
|
||||
.expect(200);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue