import { markInputRegex, extractMarkAttributesFromMatch, } from '~/content_editor/services/mark_utils'; describe('content_editor/services/mark_utils', () => { describe.each` tag | input | matches ${'tag'} | ${'hello'} | ${true} ${'tag'} | ${'hello'} | ${true} ${'kbd'} | ${'Hold Ctrl'} | ${true} ${'time'} | ${'Lets meet at '} | ${true} ${'tag'} | ${'attrs not quoted'} | ${false} ${'tag'} | ${"single quote attrs not supported"} | ${false} ${'tag'} | ${'attr has no value'} | ${false} ${'tag'} | ${'tag opened but not closed'} | ${false} ${'tag'} | ${'tag closed before opened'} | ${false} `('inputRegex("$tag")', ({ tag, input, matches }) => { it(`${matches ? 'matches' : 'does not match'}: "${input}"`, () => { const match = markInputRegex(tag).test(input); expect(match).toBe(matches); }); }); describe.each` tag | input | attrs ${'kbd'} | ${'Hold Ctrl'} | ${{}} ${'tag'} | ${'hello'} | ${{ title: 'tooltip' }} ${'time'} | ${'Lets meet at '} | ${{ title: 'today', datetime: '20:00' }} ${'abbr'} | ${'Sure, you can try it out but YMMV'} | ${{ title: 'Your mileage may vary' }} `('extractAttributesFromMatch(inputRegex("$tag").exec(\'$input\'))', ({ tag, input, attrs }) => { it(`returns: "${JSON.stringify(attrs)}"`, () => { const matches = markInputRegex(tag).exec(input); expect(extractMarkAttributesFromMatch(matches)).toEqual(attrs); }); }); });