Skip to content

Commit 62593f2

Browse files
authored
AXON-1972: add tests and fix typo (#1704)
1 parent 2486af9 commit 62593f2

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

src/lib/webview/controller/config/configV3WebviewController.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ describe('ConfigV3WebviewController', () => {
164164
...section,
165165
});
166166
});
167+
168+
test('should call invalidate when section is undefined', async () => {
169+
const mockJiraSites = [{ id: 'site1' }];
170+
const mockBBSites = [{ id: 'site2' }];
171+
const mockTarget = 'workspace';
172+
const mockConfig = { setting1: true };
173+
const mockFeedbackUser = { id: 'user1' };
174+
175+
mockApi.getSitesWithAuth.mockResolvedValue([mockJiraSites, mockBBSites] as any);
176+
mockApi.getConfigTarget.mockReturnValue(mockTarget as any);
177+
mockApi.flattenedConfigForTarget.mockReturnValue(mockConfig as any);
178+
mockApi.getFeedbackUser.mockResolvedValue(mockFeedbackUser as any);
179+
mockApi.getIsRemote.mockReturnValue(false);
180+
mockApi.shouldShowTunnelOption.mockReturnValue(true);
181+
182+
controller.update(undefined);
183+
184+
await new Promise(process.nextTick);
185+
186+
expect(mockApi.getSitesWithAuth).toHaveBeenCalledTimes(1);
187+
expect(mockMessagePoster).toHaveBeenCalledWith(
188+
expect.objectContaining({
189+
type: ConfigMessageType.Init,
190+
}),
191+
);
192+
});
193+
194+
test('should not post SectionChange when section is undefined', () => {
195+
controller.update(undefined);
196+
197+
expect(mockMessagePoster).not.toHaveBeenCalledWith(
198+
expect.objectContaining({
199+
type: ConfigMessageType.SectionChange,
200+
}),
201+
);
202+
});
167203
});
168204

169205
describe('invalidate', () => {

src/lib/webview/controller/config/configV3WebviewController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ export class ConfigV3WebviewController implements WebviewController<SectionV3Cha
143143
try {
144144
await this.invalidate();
145145
} catch (e) {
146-
this._logger.error(e, 'Error refeshing config');
146+
this._logger.error(e, 'Error refreshing config');
147147
this.postMessage({
148148
type: CommonMessageType.Error,
149-
reason: formatError(e, 'Error refeshing config'),
149+
reason: formatError(e, 'Error refreshing config'),
150150
});
151151
}
152152
break;

src/lib/webview/controller/config/configWebviewController.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,42 @@ describe('ConfigWebviewController', () => {
164164
...section,
165165
});
166166
});
167+
168+
test('should call invalidate when section is undefined', async () => {
169+
const mockJiraSites = [{ id: 'site1' }];
170+
const mockBBSites = [{ id: 'site2' }];
171+
const mockTarget = 'workspace';
172+
const mockConfig = { setting1: true };
173+
const mockFeedbackUser = { id: 'user1' };
174+
175+
mockApi.getSitesWithAuth.mockResolvedValue([mockJiraSites, mockBBSites] as any);
176+
mockApi.getConfigTarget.mockReturnValue(mockTarget as any);
177+
mockApi.flattenedConfigForTarget.mockReturnValue(mockConfig as any);
178+
mockApi.getFeedbackUser.mockResolvedValue(mockFeedbackUser as any);
179+
mockApi.getIsRemote.mockReturnValue(false);
180+
mockApi.shouldShowTunnelOption.mockReturnValue(true);
181+
182+
controller.update(undefined);
183+
184+
await new Promise(process.nextTick);
185+
186+
expect(mockApi.getSitesWithAuth).toHaveBeenCalledTimes(1);
187+
expect(mockMessagePoster).toHaveBeenCalledWith(
188+
expect.objectContaining({
189+
type: ConfigMessageType.Init,
190+
}),
191+
);
192+
});
193+
194+
test('should not post SectionChange when section is undefined', () => {
195+
controller.update(undefined);
196+
197+
expect(mockMessagePoster).not.toHaveBeenCalledWith(
198+
expect.objectContaining({
199+
type: ConfigMessageType.SectionChange,
200+
}),
201+
);
202+
});
167203
});
168204

169205
describe('invalidate', () => {
@@ -237,7 +273,7 @@ describe('ConfigWebviewController', () => {
237273

238274
await controller.onMessageReceived({ type: CommonActionType.Refresh });
239275

240-
expect(mockLogger.error).toHaveBeenCalledWith(error, 'Error refeshing config');
276+
expect(mockLogger.error).toHaveBeenCalledWith(error, 'Error refreshing config');
241277
expect(mockMessagePoster).toHaveBeenCalledWith({
242278
type: CommonMessageType.Error,
243279
reason: expect.anything(),

src/lib/webview/controller/config/configWebviewController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ export class ConfigWebviewController implements WebviewController<SectionChangeM
142142
try {
143143
await this.invalidate();
144144
} catch (e) {
145-
this._logger.error(e, 'Error refeshing config');
145+
this._logger.error(e, 'Error refreshing config');
146146
this.postMessage({
147147
type: CommonMessageType.Error,
148-
reason: formatError(e, 'Error refeshing config'),
148+
reason: formatError(e, 'Error refreshing config'),
149149
});
150150
}
151151
break;

0 commit comments

Comments
 (0)