UNPKG

4.55 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2020 Ericsson and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const chai = require("chai");
19const uri_1 = require("./uri");
20const uri_command_handler_1 = require("./uri-command-handler");
21const expect = chai.expect;
22const mockHandler = {
23 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24 execute(...args) { this.lastCall = args; },
25 lastCall: []
26};
27const selectedURIs = [
28 new uri_1.default('/foo'),
29 new uri_1.default('/bar'),
30];
31const mockSelectionService = {
32 selection: selectedURIs.map(uri => ({ uri }))
33};
34describe('URI-Aware Command Handlers', () => {
35 afterEach(() => {
36 mockHandler.lastCall = [];
37 });
38 describe('UriAwareCommandHandler', () => {
39 it('getUri returns the first argument if it is a URI (single)', () => {
40 const args = [new uri_1.default('/passed/in'), 'some', 'other', 'args'];
41 const output = uri_command_handler_1.UriAwareCommandHandler.MonoSelect(mockSelectionService, mockHandler)['getUri'](...args);
42 expect(output).equals(args[0]);
43 });
44 it('getUri returns the first argument if it is a URI (multi)', () => {
45 const args = [[new uri_1.default('/passed/in')], 'some', 'other', 'args'];
46 const output = uri_command_handler_1.UriAwareCommandHandler.MultiSelect(mockSelectionService, mockHandler)['getUri'](...args);
47 expect(output).equals(args[0]);
48 });
49 it('getUri returns an argument from the service if no URI is provided (single)', () => {
50 const args = ['some', 'other', 'args'];
51 const output = uri_command_handler_1.UriAwareCommandHandler.MonoSelect(mockSelectionService, mockHandler)['getUri'](...args);
52 expect(output).equals(selectedURIs[0]);
53 });
54 it('getUri returns an argument from the service if no URI is provided (multi)', () => {
55 const args = ['some', 'other', 'args'];
56 const output = uri_command_handler_1.UriAwareCommandHandler.MultiSelect(mockSelectionService, mockHandler)['getUri'](...args);
57 expect(output).deep.equals(selectedURIs);
58 });
59 it('calls the handler with the same args if the first argument if it is a URI (single)', () => {
60 const args = [new uri_1.default('/passed/in'), 'some', 'other', 'args'];
61 uri_command_handler_1.UriAwareCommandHandler.MonoSelect(mockSelectionService, mockHandler)['execute'](...args);
62 expect(mockHandler.lastCall).deep.equals(args);
63 });
64 it('calls the handler with the same args if the first argument if it is a URI (multi)', () => {
65 const args = [[new uri_1.default('/passed/in')], 'some', 'other', 'args'];
66 uri_command_handler_1.UriAwareCommandHandler.MultiSelect(mockSelectionService, mockHandler)['execute'](...args);
67 expect(mockHandler.lastCall).deep.equals(args);
68 });
69 it('calls the handler with an argument from the service if no URI is provided (single)', () => {
70 const args = ['some', 'other', 'args'];
71 uri_command_handler_1.UriAwareCommandHandler.MonoSelect(mockSelectionService, mockHandler)['execute'](...args);
72 expect(mockHandler.lastCall).deep.equals([selectedURIs[0], ...args]);
73 });
74 it('calls the handler with an argument from the service if no URI is provided (multi)', () => {
75 const args = ['some', 'other', 'args'];
76 uri_command_handler_1.UriAwareCommandHandler.MultiSelect(mockSelectionService, mockHandler)['execute'](...args);
77 expect(mockHandler.lastCall).deep.equals([selectedURIs, ...args]);
78 });
79 });
80});
81//# sourceMappingURL=uri-command-handler.spec.js.map
\No newline at end of file