1 | // *****************************************************************************
|
2 | // Copyright (C) 2017 TypeFox and others.
|
3 | //
|
4 | // This program and the accompanying materials are made available under the
|
5 | // terms of the Eclipse Public License v. 2.0 which is available at
|
6 | // http://www.eclipse.org/legal/epl-2.0.
|
7 | //
|
8 | // This Source Code may also be made available under the following Secondary
|
9 | // Licenses when the conditions for such availability set forth in the Eclipse
|
10 | // Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
11 | // with the GNU Classpath Exception which is available at
|
12 | // https://www.gnu.org/software/classpath/license.html.
|
13 | //
|
14 | // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
15 | // *****************************************************************************
|
16 |
|
17 | import { DefaultOpenerService, OpenHandler } from './opener-service';
|
18 | import * as assert from 'assert';
|
19 | import { MaybePromise } from '../common/types';
|
20 | import * as chai from 'chai';
|
21 | const expect = chai.expect;
|
22 |
|
23 | const id = 'my-opener';
|
24 | const openHandler: OpenHandler = {
|
25 | id,
|
26 | label: 'My Opener',
|
27 | canHandle(): MaybePromise<number> {
|
28 | return Promise.resolve(1);
|
29 | },
|
30 | open(): MaybePromise<object | undefined> {
|
31 | return Promise.resolve(undefined);
|
32 | }
|
33 | };
|
34 | const openerService = new DefaultOpenerService({
|
35 | getContributions: () => [openHandler]
|
36 | });
|
37 |
|
38 | describe('opener-service', () => {
|
39 | it('getOpeners', () =>
|
40 | openerService.getOpeners().then(openers => {
|
41 | assert.deepStrictEqual([openHandler], openers);
|
42 | }));
|
43 | it('addHandler', () => {
|
44 | openerService.addHandler(openHandler);
|
45 | openerService.getOpeners().then(openers => {
|
46 | expect(openers.length).is.equal(2);
|
47 | });
|
48 | });
|
49 | });
|