mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 07:42:39 +00:00
Merge pull request #3931 from G-Ambatte/tagsToArrayOnLoad-#3927
Convert any `tags` strings to arrays
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
/* eslint-disable max-lines */
|
/* eslint-disable max-lines */
|
||||||
|
|
||||||
|
import { splitTextStyleAndMetadata } from '../shared/helpers.js';
|
||||||
|
|
||||||
describe('Tests for api', ()=>{
|
describe('Tests for api', ()=>{
|
||||||
let api;
|
let api;
|
||||||
let google;
|
let google;
|
||||||
@@ -968,4 +970,57 @@ brew`);
|
|||||||
expect(res.send).toHaveBeenCalledWith('');
|
expect(res.send).toHaveBeenCalledWith('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('Split Text, Style, and Metadata', ()=>{
|
||||||
|
|
||||||
|
it('basic splitting', async ()=>{
|
||||||
|
const testBrew = {
|
||||||
|
text : '```metadata\n' +
|
||||||
|
'title: title\n' +
|
||||||
|
'description: description\n' +
|
||||||
|
'tags: [ \'tag a\' , \'tag b\' ]\n' +
|
||||||
|
'systems: [ test system ]\n' +
|
||||||
|
'renderer: legacy\n' +
|
||||||
|
'theme: 5ePHB\n' +
|
||||||
|
'lang: en\n' +
|
||||||
|
'\n' +
|
||||||
|
'```\n' +
|
||||||
|
'\n' +
|
||||||
|
'```css\n' +
|
||||||
|
'style\n' +
|
||||||
|
'style\n' +
|
||||||
|
'style\n' +
|
||||||
|
'```\n' +
|
||||||
|
'\n' +
|
||||||
|
'text\n'
|
||||||
|
};
|
||||||
|
|
||||||
|
splitTextStyleAndMetadata(testBrew);
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
expect(testBrew.title).toEqual('title');
|
||||||
|
expect(testBrew.description).toEqual('description');
|
||||||
|
expect(testBrew.tags).toEqual(['tag a', 'tag b']);
|
||||||
|
expect(testBrew.systems).toEqual(['test system']);
|
||||||
|
expect(testBrew.renderer).toEqual('legacy');
|
||||||
|
expect(testBrew.theme).toEqual('5ePHB');
|
||||||
|
expect(testBrew.lang).toEqual('en');
|
||||||
|
// Style
|
||||||
|
expect(testBrew.style).toEqual('style\nstyle\nstyle');
|
||||||
|
// Text
|
||||||
|
expect(testBrew.text).toEqual('text\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('convert tags string to array', async ()=>{
|
||||||
|
const testBrew = {
|
||||||
|
text : '```metadata\n' +
|
||||||
|
'tags: tag a\n' +
|
||||||
|
'```\n\n'
|
||||||
|
};
|
||||||
|
|
||||||
|
splitTextStyleAndMetadata(testBrew);
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
expect(testBrew.tags).toEqual(['tag a']);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const splitTextStyleAndMetadata = (brew)=>{
|
|||||||
brew.snippets = brew.text.slice(11, index - 1);
|
brew.snippets = brew.text.slice(11, index - 1);
|
||||||
brew.text = brew.text.slice(index + 5);
|
brew.text = brew.text.slice(index + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle old brews that still have empty strings in the tags metadata
|
||||||
|
if(typeof brew.tags === 'string') brew.tags = brew.tags ? [brew.tags] : [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const printCurrentBrew = ()=>{
|
const printCurrentBrew = ()=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user