Files
grafana/public/app/features/plugins/loader/pluginLoader.mock.ts
Hugo Häggmark 18ae5d7f0c i18n: wires up translations for plugins (#102853)
* i18n: consolidate i18n types & runtime services

* Chore: updates after PR feedback

* Chore: updates after feedback

* Chore: updates after feedback

* Chore: adds feature toggle

* Chore: adds locale to backend

* Chore: adds locales to i18n instance

* Chore: fix missing path in CODEOWNERS

* Chore: fix go lint issues

* Chore: fix missing path in CODEOWNERS

* Chore: updates after PR feedback

* Trigger build

* Chore: updates after PR feedback

* Chore: use resolved language for lookup

* Chore: updates after PR feedback

* Update pkg/plugins/plugins.go

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>

* Chore: updates after PR feedback

* Chore: updates after PR feedback

---------

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
2025-03-31 06:38:38 +02:00

89 lines
2.3 KiB
TypeScript

import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
export const mockSystemModule = `System.register(['./dependencyA'], function (_export, _context) {
"use strict";
var DependencyACtrl;
return {
setters: [function (_dependencyA) {
DependencyACtrl = _dependencyA.DependencyACtrl;
}],
execute: function () {
_export('PanelCtrl', DependencyACtrl);
}
};
});`;
export const mockAmdModule = `define([], function() {
return function() {
console.log('AMD module loaded');
var pluginPath = "/public/plugins/";
}
});`;
const mockTranslation = (value: string) =>
`System.register([],function(e){return{execute:function(){e("default",{"testKey":"${value}"})}}})`;
const mockTranslationWithNoDefaultExport = `System.register([],function(e){return{execute:function(){e({"testKey":"unknown"})}}})`;
const server = setupServer(
http.get(
'/public/plugins/mockAmdModule/module.js',
() =>
new HttpResponse(mockAmdModule, {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get(
'/public/plugins/mockSystemModule/module.js',
() =>
new HttpResponse(mockSystemModule, {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get(
'http://my-cdn.com/plugins/my-plugin/v1.0.0/public/plugins/my-plugin/module.js',
() =>
new HttpResponse(mockAmdModule, {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get(
'/public/plugins/test-panel/locales/en-US/test-panel.json',
() =>
new HttpResponse(mockTranslation('testValue'), {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get(
'/public/plugins/test-panel/locales/pt-BR/test-panel.json',
() =>
new HttpResponse(mockTranslation('valorDeTeste'), {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get(
'/public/plugins/test-panel/locales/en-US/no-default-export.json',
() =>
new HttpResponse(mockTranslationWithNoDefaultExport, {
headers: {
'Content-Type': 'text/javascript',
},
})
),
http.get('/public/plugins/test-panel/locales/en-US/unknown.json', () => HttpResponse.error())
);
export { server };