|
1 | | -import { Uri, window, workspace, WorkspaceFolder } from "vscode"; |
2 | | -import * as tmp from "tmp"; |
3 | | -import { join } from "path"; |
4 | | -import { writeFile, mkdir } from "fs-extra"; |
5 | | - |
6 | | -import { prepareCodeTour } from "../../../src/helpers"; |
7 | 1 | import { reportStreamProgress } from "../../../src/common/vscode/progress"; |
8 | | -import { Setting } from "../../../src/config"; |
9 | | -import { createMockCommandManager } from "../../__mocks__/commandsMock"; |
10 | 2 |
|
11 | 3 | describe("helpers", () => { |
12 | 4 | it("should report stream progress", () => { |
@@ -66,105 +58,3 @@ describe("helpers", () => { |
66 | 58 | }); |
67 | 59 | }); |
68 | 60 | }); |
69 | | - |
70 | | -describe("prepareCodeTour", () => { |
71 | | - let dir: tmp.DirResult; |
72 | | - let showInformationMessageSpy: jest.SpiedFunction< |
73 | | - typeof window.showInformationMessage |
74 | | - >; |
75 | | - |
76 | | - beforeEach(() => { |
77 | | - dir = tmp.dirSync(); |
78 | | - |
79 | | - const mockWorkspaceFolders = [ |
80 | | - { |
81 | | - uri: Uri.file(dir.name), |
82 | | - name: "test", |
83 | | - index: 0, |
84 | | - }, |
85 | | - ] as WorkspaceFolder[]; |
86 | | - |
87 | | - jest |
88 | | - .spyOn(workspace, "workspaceFolders", "get") |
89 | | - .mockReturnValue(mockWorkspaceFolders); |
90 | | - |
91 | | - showInformationMessageSpy = jest |
92 | | - .spyOn(window, "showInformationMessage") |
93 | | - .mockResolvedValue({ title: "Yes" }); |
94 | | - }); |
95 | | - |
96 | | - afterEach(() => { |
97 | | - dir.removeCallback(); |
98 | | - }); |
99 | | - |
100 | | - describe("if we're in the tour repo", () => { |
101 | | - describe("if the workspace is not already open", () => { |
102 | | - it("should open the tutorial workspace", async () => { |
103 | | - // set up directory to have a 'tutorial.code-workspace' file |
104 | | - const tutorialWorkspacePath = join(dir.name, "tutorial.code-workspace"); |
105 | | - await writeFile(tutorialWorkspacePath, "{}"); |
106 | | - |
107 | | - // set up a .tours directory to indicate we're in the tour codespace |
108 | | - const tourDirPath = join(dir.name, ".tours"); |
109 | | - await mkdir(tourDirPath); |
110 | | - |
111 | | - // spy that we open the workspace file by calling the 'vscode.openFolder' command |
112 | | - const executeCommand = jest.fn(); |
113 | | - await prepareCodeTour(createMockCommandManager({ executeCommand })); |
114 | | - |
115 | | - expect(showInformationMessageSpy).toHaveBeenCalled(); |
116 | | - expect(executeCommand).toHaveBeenCalledWith( |
117 | | - "vscode.openFolder", |
118 | | - expect.objectContaining({ |
119 | | - path: expect.stringMatching(/tutorial.code-workspace$/), |
120 | | - }), |
121 | | - ); |
122 | | - }); |
123 | | - }); |
124 | | - |
125 | | - describe("if the workspace is already open", () => { |
126 | | - it("should not open the tutorial workspace", async () => { |
127 | | - // Set isCodespacesTemplate to true to indicate the workspace has already been opened |
128 | | - jest.spyOn(Setting.prototype, "getValue").mockReturnValue(true); |
129 | | - |
130 | | - // set up directory to have a 'tutorial.code-workspace' file |
131 | | - const tutorialWorkspacePath = join(dir.name, "tutorial.code-workspace"); |
132 | | - await writeFile(tutorialWorkspacePath, "{}"); |
133 | | - |
134 | | - // set up a .tours directory to indicate we're in the tour codespace |
135 | | - const tourDirPath = join(dir.name, ".tours"); |
136 | | - await mkdir(tourDirPath); |
137 | | - |
138 | | - // spy that we open the workspace file by calling the 'vscode.openFolder' command |
139 | | - const executeCommand = jest.fn(); |
140 | | - await prepareCodeTour(createMockCommandManager({ executeCommand })); |
141 | | - |
142 | | - expect(executeCommand).not.toHaveBeenCalled(); |
143 | | - }); |
144 | | - }); |
145 | | - }); |
146 | | - |
147 | | - describe("if we're in a different tour repo", () => { |
148 | | - it("should not open the tutorial workspace", async () => { |
149 | | - // set up a .tours directory |
150 | | - const tourDirPath = join(dir.name, ".tours"); |
151 | | - await mkdir(tourDirPath); |
152 | | - |
153 | | - // spy that we open the workspace file by calling the 'vscode.openFolder' command |
154 | | - const executeCommand = jest.fn(); |
155 | | - await prepareCodeTour(createMockCommandManager({ executeCommand })); |
156 | | - |
157 | | - expect(executeCommand).not.toHaveBeenCalled(); |
158 | | - }); |
159 | | - }); |
160 | | - |
161 | | - describe("if we're in a different repo with no tour", () => { |
162 | | - it("should not open the tutorial workspace", async () => { |
163 | | - // spy that we open the workspace file by calling the 'vscode.openFolder' command |
164 | | - const executeCommand = jest.fn(); |
165 | | - await prepareCodeTour(createMockCommandManager({ executeCommand })); |
166 | | - |
167 | | - expect(executeCommand).not.toHaveBeenCalled(); |
168 | | - }); |
169 | | - }); |
170 | | -}); |
0 commit comments