2020-01-28 04:09:06 -05:00
|
|
|
import { setTitle, updateRefPortionOfTitle } from '~/repository/utils/title';
|
2019-05-24 10:48:29 -04:00
|
|
|
|
|
|
|
describe('setTitle', () => {
|
|
|
|
it.each`
|
|
|
|
path | title
|
|
|
|
${'/'} | ${'Files'}
|
|
|
|
${'app'} | ${'app'}
|
|
|
|
${'app/assets'} | ${'app/assets'}
|
|
|
|
${'app/assets/javascripts'} | ${'app/assets/javascripts'}
|
|
|
|
`('sets document title as $title for $path', ({ path, title }) => {
|
2021-04-21 08:09:16 -04:00
|
|
|
setTitle(path, 'main', 'GitLab Org / GitLab');
|
2019-05-24 10:48:29 -04:00
|
|
|
|
2021-04-21 08:09:16 -04:00
|
|
|
expect(document.title).toEqual(`${title} · main · GitLab Org / GitLab · GitLab`);
|
2019-05-24 10:48:29 -04:00
|
|
|
});
|
|
|
|
});
|
2020-01-28 04:09:06 -05:00
|
|
|
|
|
|
|
describe('updateRefPortionOfTitle', () => {
|
|
|
|
const sha = 'abc';
|
|
|
|
const testCases = [
|
|
|
|
[
|
|
|
|
'updates the title with the SHA',
|
|
|
|
{ title: 'part 1 · part 2 · part 3' },
|
|
|
|
'part 1 · abc · part 3',
|
|
|
|
],
|
|
|
|
["makes no change if there's no title", { foo: null }, undefined],
|
|
|
|
[
|
|
|
|
"makes no change if the title doesn't split predictably",
|
|
|
|
{ title: 'part 1 - part 2 - part 3' },
|
|
|
|
'part 1 - part 2 - part 3',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
it.each(testCases)('%s', (desc, doc, title) => {
|
|
|
|
updateRefPortionOfTitle(sha, doc);
|
|
|
|
|
|
|
|
expect(doc.title).toEqual(title);
|
|
|
|
});
|
|
|
|
});
|