Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add missing tests #1609

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16,131 changes: 9,170 additions & 6,961 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/
8 changes: 8 additions & 0 deletions packages/core/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ export type {
EditCompletedEvent,
EditCompletedDetail,
} from './foundation/edit-completed-event.js';

/** @returns the cartesian product of `arrays` */
export function crossProduct<T>(...arrays: T[][]): T[][] {
return arrays.reduce<T[][]>(
(a, b) => <T[][]>a.flatMap(d => b.map(e => [d, e].flat())),
[[]]
);
}
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';

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,
});
});
});
});
Loading
Loading