2021-08-16 18:44:11 +03:00
|
|
|
import { buildQrCodeUrl, QrCodeFormat, QrErrorCorrection } from '../../../src/utils/helpers/qrCodes';
|
2021-01-24 19:47:03 +03:00
|
|
|
|
|
|
|
describe('qrCodes', () => {
|
|
|
|
describe('buildQrCodeUrl', () => {
|
2021-09-20 23:00:34 +03:00
|
|
|
it.each([
|
2021-02-14 11:50:26 +03:00
|
|
|
[
|
|
|
|
'foo.com',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 530, format: 'svg' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: false, errorCorrectionIsSupported: false },
|
2021-02-14 11:50:26 +03:00
|
|
|
'foo.com/qr-code/530?format=svg',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo.com',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 530, format: 'png' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: false, errorCorrectionIsSupported: false },
|
2021-02-14 11:50:26 +03:00
|
|
|
'foo.com/qr-code/530?format=png',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'bar.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 870, format: 'svg' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: false, marginIsSupported: false, errorCorrectionIsSupported: false },
|
|
|
|
'bar.io/qr-code?size=870&format=svg',
|
2021-02-14 11:50:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'bar.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 200, format: 'png' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: false, marginIsSupported: false, errorCorrectionIsSupported: false },
|
2021-02-14 11:50:26 +03:00
|
|
|
'bar.io/qr-code?size=200&format=png',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'bar.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 200, format: 'svg' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: false, marginIsSupported: false, errorCorrectionIsSupported: false },
|
2021-02-14 11:50:26 +03:00
|
|
|
'bar.io/qr-code?size=200&format=svg',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo.net',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 480, format: 'png' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: false, errorCorrectionIsSupported: false },
|
|
|
|
'foo.net/qr-code/480?format=png',
|
2021-02-14 11:50:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'foo.net',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 480, format: 'svg' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: false, errorCorrectionIsSupported: false },
|
|
|
|
'foo.net/qr-code/480?format=svg',
|
2021-02-14 11:50:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'shlink.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 123, format: 'svg' as QrCodeFormat, margin: 10, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: false, errorCorrectionIsSupported: false },
|
|
|
|
'shlink.io/qr-code/123?format=svg',
|
2021-02-14 11:50:26 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'shlink.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 456, format: 'png' as QrCodeFormat, margin: 10, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: true, errorCorrectionIsSupported: false },
|
2021-02-14 11:50:26 +03:00
|
|
|
'shlink.io/qr-code/456?format=png&margin=10',
|
|
|
|
],
|
2021-02-14 12:16:30 +03:00
|
|
|
[
|
|
|
|
'shlink.io',
|
2021-08-16 18:44:11 +03:00
|
|
|
{ size: 456, format: 'png' as QrCodeFormat, margin: 0, errorCorrection: 'L' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: true, errorCorrectionIsSupported: false },
|
2021-02-14 12:16:30 +03:00
|
|
|
'shlink.io/qr-code/456?format=png',
|
|
|
|
],
|
2021-08-16 18:44:11 +03:00
|
|
|
[
|
|
|
|
'shlink.io',
|
|
|
|
{ size: 456, format: 'png' as QrCodeFormat, margin: 0, errorCorrection: 'H' as QrErrorCorrection },
|
2021-09-25 12:40:16 +03:00
|
|
|
{ useSizeInPath: true, marginIsSupported: true, errorCorrectionIsSupported: true },
|
2021-08-16 18:44:11 +03:00
|
|
|
'shlink.io/qr-code/456?format=png&errorCorrection=H',
|
|
|
|
],
|
2021-02-14 11:50:26 +03:00
|
|
|
])('builds expected URL based in params', (shortUrl, options, capabilities, expectedUrl) => {
|
|
|
|
expect(buildQrCodeUrl(shortUrl, options, capabilities)).toEqual(expectedUrl);
|
2021-01-24 19:47:03 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|