/* eslint-env jest */ import { changeExcerpt, fieldLabel, sourceLabel, valueLabel, } from '../change-labels'; describe('change labels', () => { it('names the writer, the field and the value as a merchant reads them', () => { expect(sourceLabel('agent')).toBe('SEO medic'); expect(sourceLabel('something_new')).toBe('Something new'); expect(fieldLabel('post', '_recomaze_seo_description')).toBe( 'Meta description' ); expect(fieldLabel('media', 'alt')).toBe('Alt text'); expect(fieldLabel('user', '_recomaze_seo_x')).toBe('X username'); expect(fieldLabel('user', '_recomaze_seo_profiles')).toBe('Other profiles'); expect(fieldLabel('option', 'general.robots_ai_allow')).toBe( 'AI crawlers allowed' ); expect(fieldLabel('option', 'titles.some_new_key')).toBe('Some new key'); expect(fieldLabel('module', 'monitor_404')).toBe('Module: Monitor 404'); expect(valueLabel(true)).toBe('On'); expect(valueLabel(false)).toBe('Off'); expect(valueLabel(['gptbot', 'ccbot'])).toBe('gptbot, ccbot'); expect(valueLabel('')).toBe('—'); }); }); describe('the excerpt of a long text change', () => { const post = (href: string, tail = ''): string => `

Choosing the right hoodie size comes down to three measurements. Read the first guide before you buy, then compare the chart with your own numbers.${tail}

`; it('shows the words that changed with a little text around them', () => { const parts = changeExcerpt( post('https://old.example/a'), post('https://new.example/a') ); expect(parts).toEqual([ { type: 'same', text: '…hoodie size comes down to three measurements. Read the first' }, { type: 'add', text: 'href="https://new.example/a">first' }, { type: 'same', text: ' guide before you buy, then compare the chart with your…', }, ]); }); it('shows what was taken out or added alone', () => { const parts = changeExcerpt( post('https://a.example'), post('https://a.example', ' Free returns.') ); expect(parts?.filter(part => part.type !== 'same')).toEqual([ { type: 'del', text: 'numbers.

' }, { type: 'add', text: 'numbers. Free returns.

' }, ]); }); it('leaves short values and values that are not text to the plain label', () => { expect(changeExcerpt('Old title', 'New title')).toBeNull(); expect(changeExcerpt(['a'], ['b'])).toBeNull(); expect(changeExcerpt(post('x'), post('x'))).toBeNull(); }); });