Skip to content

Commit

Permalink
test: add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trusz committed Dec 4, 2024
1 parent 267935f commit ad97a6b
Show file tree
Hide file tree
Showing 14 changed files with 11,895 additions and 9,451 deletions.
20,977 changes: 11,593 additions & 9,384 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
dist/
node_modules/
doc/
coverage/
10 changes: 4 additions & 6 deletions packages/core/foundation/deprecated/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export type InfoEntry = Timestamped & InfoDetail;

export type LogEntry = InfoEntry | CommitEntry;


export function newLogEvent(
detail: LogDetail,
eventInitDict?: CustomEventInit<LogDetail>
Expand All @@ -70,9 +69,8 @@ export function newIssueEvent(
}

declare global {
interface ElementEventMap {
['log']: LogEvent;
['issue']: IssueEvent;
}
interface ElementEventMap {
['log']: LogEvent;
['issue']: IssueEvent;
}
}
8 changes: 4 additions & 4 deletions packages/core/foundation/deprecated/open-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function newOpenDocEvent(
}

declare global {
interface ElementEventMap {
['open-doc']: OpenDocEvent;
}
}
interface ElementEventMap {
['open-doc']: OpenDocEvent;
}
}
1 change: 0 additions & 1 deletion packages/core/foundation/deprecated/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export function newSettingsUIEvent(
});
}


declare global {
interface ElementEventMap {
['oscd-settings']: SettingsUIEvent;
Expand Down
8 changes: 3 additions & 5 deletions packages/core/foundation/deprecated/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ export function newValidateEvent(
});
}


declare global {
interface ElementEventMap {
['validate']: ValidateEvent;
}
interface ElementEventMap {
['validate']: ValidateEvent;
}
}
2 changes: 1 addition & 1 deletion packages/core/foundation/deprecated/waiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface PendingStateDetail {
export type PendingStateEvent = CustomEvent<PendingStateDetail>;

/**
* @deprecated
* @deprecated not used anymore
*/
export function newPendingStateEvent(
promise: Promise<void>,
Expand Down
187 changes: 187 additions & 0 deletions packages/core/foundation/edit-event.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import {
Edit,
EditEvent,
EditEventDetail,
isComplex,
isInsert,
isNamespaced,
isRemove,
isUpdate,
NamespacedAttributeValue,
newEditEvent,
} from './edit-event.js';

const doc: XMLDocument = new DOMParser().parseFromString(
`<Document></Document>`,
'application/xml'
);

describe('edit-event.ts', () => {
const el: Element = doc.createElement('Parent');

describe('isComplex', () => {
it('should return true when `Edit` is complex', () => {
const complexEdit: Edit = [
{
element: el,
attributes: {
firstname: 'John',
},
},
{
element: el,
attributes: {
lastname: 'Doe',
},
},
];

expect(isComplex(complexEdit)).toBeTruthy();
});

it('Should return false when `Edit` is simple', () => {
const simpleEdit: Edit = {
element: el,
attributes: {
name: 'John Doe',
},
};

expect(isComplex(simpleEdit)).toBeFalsy();
});
});

describe('isInsert', () => {
it('Should return true when `Edit` is Insert', () => {
const edit: Edit = {
parent: doc,
node: el,
};

expect(isInsert(edit)).toBeTruthy();
});

it('Should return false when `Edit` is Update', () => {
const edit: Edit = {
element: el,
attributes: {
name: 'John Doe',
},
};

expect(isInsert(edit)).toBeFalsy();
});
});

describe('isNamespaced', () => {
it('Should return true when `value` is Namespaced', () => {
const value: NamespacedAttributeValue = {
value: 'Name',
namespaceURI: 'TEST',
};

expect(isNamespaced(value)).toBeTruthy();
});

it('Should return false when `value` is String', () => {
expect(isNamespaced('TEST')).toBeFalsy();
});

it('Should return false when `value` is null', () => {
expect(isNamespaced(null)).toBeFalsy();
});
});

describe('isUpdate', () => {
it('Should return true when Edit is Update', () => {
const edit: Edit = {
element: el,
attributes: {},
};

expect(isUpdate(edit)).toBeTruthy();
});

it('Should return false when Edit is Insert', () => {
const edit: Edit = {
parent: doc,
node: el,
};

expect(isUpdate(edit)).toBeFalsy();
});
});

describe('isRemove', () => {
it('Should return true when Edit is Remove', () => {
const edit: Edit = {
node: el,
};

expect(isRemove(edit)).toBeTruthy();
});

it('Should return false when Edit is Update', () => {
const edit: Edit = {
element: el,
attributes: {},
};

expect(isRemove(edit)).toBeFalsy();
});
});

describe('newEditEvent', () => {
it('Should have name `oscd-edit`', () => {
const edit: Edit = {
element: el,
attributes: {},
};

const res: EditEvent = newEditEvent(edit);

expect(res.type).toEqual('oscd-edit');
});

it('Should be composed', () => {
const edit: Edit = {
element: el,
attributes: {},
};

const res: EditEvent = newEditEvent(edit);

expect(res.composed).toBeTruthy();
});

it('Should be bubble-able', () => {
const edit: Edit = {
element: el,
attributes: {},
};

const res: EditEvent = newEditEvent(edit);

expect(res.bubbles).toBeTruthy();
});

it('Should have Edit as Detail', () => {
const edit: Edit = {
element: el,
attributes: {},
};

const res: EditEvent = newEditEvent(edit);

const expectedEventDetail: EditEventDetail<Edit> = {
edit: {
element: el,
attributes: {},
},
initiator: 'user',
};

expect(res.detail).toEqual(expectedEventDetail);
});
});
});
39 changes: 39 additions & 0 deletions packages/core/foundation/open-event.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { newOpenEvent, OpenEvent } from './open-event';

const doc: XMLDocument = new DOMParser().parseFromString(
`<Document></Document>`,
'application/xml'
);

describe('open-event.ts', () => {
const docName = 'test.xml';

describe('newOpenEvent', () => {
it('Should have name `oscd-open`', () => {
const res: OpenEvent = newOpenEvent(doc, docName);

expect(res.type).toEqual('oscd-open');
});

it('Should be composed', () => {
const res: OpenEvent = newOpenEvent(doc, docName);

expect(res.composed).toBeTruthy();
});

it('Should be bubble-able', () => {
const res: OpenEvent = newOpenEvent(doc, docName);

expect(res.bubbles).toBeTruthy();
});

it('Should have Edit as Detail', () => {
const res: OpenEvent = newOpenEvent(doc, docName);

expect(res.detail).toEqual({
docName: docName,
doc: doc,
});
});
});
});
19 changes: 19 additions & 0 deletions packages/core/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import("ts-jest").JestConfigWithTsJest} */
module.exports = {
roots: ["<rootDir>"],
preset: "ts-jest",
testEnvironment: "jsdom",
collectCoverage: true,
coverageDirectory: "coverage",
testPathIgnorePatterns: ["/node_modules/"],

verbose: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
};
9 changes: 2 additions & 7 deletions packages/core/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ export const sourceLocale = `en`;
* The other locale codes that this application is localized into. Sorted
* lexicographically.
*/
export const targetLocales = [
`de`,
] as const;
export const targetLocales = [`de`] as const;

/**
* All valid project locale codes. Sorted lexicographically.
*/
export const allLocales = [
`de`,
`en`,
] as const;
export const allLocales = [`de`, `en`] as const;
17 changes: 5 additions & 12 deletions packages/core/locales/de.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
// Do not modify this file by hand!
// Re-generate this file by running lit-localize

// Do not modify this file by hand!
// Re-generate this file by running lit-localize
/* eslint-disable no-irregular-whitespace */
/* eslint-disable @typescript-eslint/no-explicit-any */




/* eslint-disable no-irregular-whitespace */
/* eslint-disable @typescript-eslint/no-explicit-any */

export const templates = {

};

export const templates = {};
Loading

0 comments on commit ad97a6b

Please sign in to comment.