Skip to content

Commit

Permalink
Chore: Added additional properties (#1369)
Browse files Browse the repository at this point in the history
* Chore: Added docs and locale properties to OpenSCD shell class

* Removed dist classes

* test: Fixed test

* Removed dist folder

---------

Co-authored-by: Juan Munoz <juan.munoz@alliander.com>
  • Loading branch information
pascalwilbrink and juancho0202 authored Nov 27, 2023
1 parent 2e8acc3 commit 754c301
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/open-scd/src/Plugging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function staticTagHtml(

type PluginKind = 'editor' | 'menu' | 'validator';
const menuPosition = ['top', 'middle', 'bottom'] as const;
type MenuPosition = typeof menuPosition[number];
type MenuPosition = (typeof menuPosition)[number];

export type Plugin = {
name: string;
Expand Down Expand Up @@ -239,6 +239,20 @@ export function Plugging<
@query('#pluginAdd')
pluginDownloadUI!: Dialog;

protected get locale(): string {
return navigator.language || 'en-US';
}

get docs(): Record<string, XMLDocument> {
const docs: Record<string, XMLDocument> = {};

if (this.doc) {
docs[this.docName] = this.doc;
}

return docs;
}

private setPlugins(indices: Set<number>) {
const newPlugins = this.plugins.map((plugin, index) => {
return { ...plugin, installed: indices.has(index) };
Expand Down Expand Up @@ -293,6 +307,8 @@ export function Plugging<
.docId=${this.docId}
.pluginId=${plugin.src}
.nsdoc=${this.nsdoc}
.docs=${this.docs}
.locale=${this.locale}
class="${classMap({
plugin: true,
menu: plugin.kind === 'menu',
Expand Down
12 changes: 11 additions & 1 deletion packages/open-scd/test/unit/Plugging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { TextField } from '@material/mwc-textfield';
describe('PluggingElement', () => {
let element: MockPlugger;
let doc: XMLDocument;
const docName: string = 'testDoc';

afterEach(async () => {
await new Promise(resolve => setTimeout(resolve, 50)); // await animation
Expand All @@ -19,7 +20,7 @@ describe('PluggingElement', () => {
.then(str => new DOMParser().parseFromString(str, 'application/xml'));
element = <MockPlugger>(
await fixture(
html`<mock-plugger .doc=${doc} docName="testDoc"></mock-plugger>`
html`<mock-plugger .doc=${doc} .docName=${docName}></mock-plugger>`
)
);
await element.updateComplete;
Expand All @@ -28,6 +29,15 @@ describe('PluggingElement', () => {
it('stores default plugins on load', () =>
expect(element).property('editors').to.have.lengthOf(6));

it('has Locale property', async () => {
expect(element).to.have.property('locale');
});

it('has docs property', () => {
expect(element).to.have.property(`docs`).that.is.a('Object');
expect(element.docs[docName]).to.equal(doc);
});

describe('plugin manager dialog', () => {
let firstEditorPlugin: HTMLElement;
let resetAction: HTMLElement;
Expand Down

0 comments on commit 754c301

Please sign in to comment.