|
| 1 | +(global as any).nova = Object.assign(nova, { |
| 2 | + commands: { |
| 3 | + invoke: jest.fn(), |
| 4 | + }, |
| 5 | + config: { |
| 6 | + onDidChange: jest.fn(), |
| 7 | + ["get"]: jest.fn(), |
| 8 | + }, |
| 9 | + workspace: { |
| 10 | + config: { onDidChange: jest.fn(), ["get"]: jest.fn() }, |
| 11 | + }, |
| 12 | +}); |
| 13 | + |
| 14 | +describe("skipDestructiveOrganizeImports", () => { |
| 15 | + beforeEach(() => { |
| 16 | + (nova.workspace.config.get as jest.Mock).mockReset(); |
| 17 | + (nova.config.get as jest.Mock).mockReset(); |
| 18 | + }); |
| 19 | + |
| 20 | + const { |
| 21 | + skipDestructiveOrganizeImports, |
| 22 | + } = require("./skipDestructiveOrganizeImports"); |
| 23 | + |
| 24 | + describe("reloads extension when it changes", () => { |
| 25 | + it("globally and for the workspace", () => { |
| 26 | + expect(nova.config.onDidChange).toBeCalledTimes(1); |
| 27 | + expect(nova.config.onDidChange).toBeCalledWith( |
| 28 | + "apexskier.typescript.config.skipDestructiveOrganizeImports", |
| 29 | + expect.any(Function) |
| 30 | + ); |
| 31 | + expect(nova.workspace.config.onDidChange).toBeCalledTimes(1); |
| 32 | + expect(nova.workspace.config.onDidChange).toBeCalledWith( |
| 33 | + "apexskier.typescript.config.skipDestructiveOrganizeImports", |
| 34 | + expect.any(Function) |
| 35 | + ); |
| 36 | + // same function |
| 37 | + const onWorkspaceChange = (nova.workspace.config.onDidChange as jest.Mock) |
| 38 | + .mock.calls[0][1]; |
| 39 | + const onGlobalChange = (nova.config.onDidChange as jest.Mock).mock |
| 40 | + .calls[0][1]; |
| 41 | + expect(onWorkspaceChange).toBe(onGlobalChange); |
| 42 | + }); |
| 43 | + |
| 44 | + it("by calling the reload command", () => { |
| 45 | + const reload = (nova.config.onDidChange as jest.Mock).mock.calls[0][1]; |
| 46 | + reload(); |
| 47 | + expect(nova.commands.invoke).toBeCalledTimes(1); |
| 48 | + expect(nova.commands.invoke).toBeCalledWith( |
| 49 | + "apexskier.typescript.reload" |
| 50 | + ); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe("is true by default", () => { |
| 55 | + expect(skipDestructiveOrganizeImports()).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + describe("can be disabled globally", () => { |
| 59 | + (nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null); |
| 60 | + (nova.config.get as jest.Mock).mockReturnValueOnce(false); |
| 61 | + expect(skipDestructiveOrganizeImports()).toBe(false); |
| 62 | + }); |
| 63 | + |
| 64 | + describe("can be enabled globally", () => { |
| 65 | + (nova.workspace.config.get as jest.Mock).mockReturnValueOnce(null); |
| 66 | + (nova.config.get as jest.Mock).mockReturnValueOnce(true); |
| 67 | + expect(skipDestructiveOrganizeImports()).toBe(true); |
| 68 | + }); |
| 69 | + |
| 70 | + describe("can be disabled in the workspace", () => { |
| 71 | + (nova.workspace.config.get as jest.Mock).mockReturnValueOnce("False"); |
| 72 | + (nova.config.get as jest.Mock).mockReturnValueOnce(true); |
| 73 | + expect(skipDestructiveOrganizeImports()).toBe(false); |
| 74 | + }); |
| 75 | + |
| 76 | + describe("can be enabled in the workspace", () => { |
| 77 | + (nova.workspace.config.get as jest.Mock).mockReturnValueOnce("True"); |
| 78 | + (nova.config.get as jest.Mock).mockReturnValueOnce(false); |
| 79 | + expect(skipDestructiveOrganizeImports()).toBe(true); |
| 80 | + }); |
| 81 | +}); |
0 commit comments