1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai = require("chai");
|
19 | const uri_1 = require("./uri");
|
20 | const uri_command_handler_1 = require("./uri-command-handler");
|
21 | const expect = chai.expect;
|
22 | const mockHandler = {
|
23 |
|
24 | execute(...args) { this.lastCall = args; },
|
25 | lastCall: []
|
26 | };
|
27 | const selectedURIs = [
|
28 | new uri_1.default('/foo'),
|
29 | new uri_1.default('/bar'),
|
30 | ];
|
31 | const mockSelectionService = {
|
32 | selection: selectedURIs.map(uri => ({ uri }))
|
33 | };
|
34 | describe('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 |
|
\ | No newline at end of file |