95 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-21 15:32:30 +02:00
'use strict';
2021-08-02 18:09:29 +02:00
const metricsLoader = require('../metrics');
const { isLocalizedContentType } = require('../content-types')();
2021-04-21 15:32:30 +02:00
describe('Metrics', () => {
test('sendDidInitializeEvent', async () => {
global.strapi = {
contentTypes: {
withI18n: {
pluginOptions: {
i18n: {
localized: true,
},
},
},
withoutI18n: {
pluginOptions: {
i18n: {
localized: false,
},
},
},
withNoOption: {
pluginOptions: {},
},
},
plugins: {
i18n: {
services: {
2022-08-08 15:50:34 +02:00
'content-types': {
2021-04-21 15:32:30 +02:00
isLocalizedContentType,
},
},
},
},
telemetry: {
send: jest.fn(),
},
};
2021-08-02 18:09:29 +02:00
const { sendDidInitializeEvent } = metricsLoader({ strapi });
2021-04-21 15:32:30 +02:00
await sendDidInitializeEvent();
expect(strapi.telemetry.send).toHaveBeenCalledWith('', 'didInitializeI18n', {
2021-04-21 15:32:30 +02:00
numberOfContentTypes: 1,
});
});
test('sendDidUpdateI18nLocalesEvent', async () => {
global.strapi = {
contentTypes: {
withI18n: {
pluginOptions: {
i18n: {
localized: true,
},
},
},
withoutI18n: {
pluginOptions: {
i18n: {
localized: false,
},
},
},
withNoOption: {
pluginOptions: {},
},
},
plugins: {
i18n: {
services: {
locales: {
count: jest.fn(() => 3),
},
},
},
},
telemetry: {
send: jest.fn(),
},
};
2021-08-02 18:09:29 +02:00
const { sendDidUpdateI18nLocalesEvent } = metricsLoader({ strapi });
2021-04-21 15:32:30 +02:00
await sendDidUpdateI18nLocalesEvent();
expect(strapi.telemetry.send).toHaveBeenCalledWith('', 'didUpdateI18nLocales', {
2021-04-21 15:32:30 +02:00
numberOfLocales: 3,
});
});
});