Skip to content

Commit de82ebd

Browse files
committed
refactor: update tests to reflect new button display interface
1 parent dab7163 commit de82ebd

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/__tests__/nbgitpuller_jb_interface.spec.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
it
1111
} from '@jest/globals';
1212

13-
import { checkForRepoUpdates, setUpdateButtonDisplay } from '../utils';
13+
import { checkForRepoUpdates, setUpdateButtonDisplay, WidgetState } from '../utils';
1414

1515
describe('nbgitpuller-jl-interface utils checkForRepoUpdates', () => {
1616
beforeEach(() => {});
@@ -134,36 +134,41 @@ describe('nbgitpuller-jl-interface utils setUpdateButtonDisplay', () => {
134134
document.body.innerHTML = '';
135135
});
136136

137-
it('widget up to date populated', async () => {
137+
it('widget up to date success', async () => {
138138
const widget = await document.createElement('div');
139139
widget.id = 'nbgitpuller-jl-interface-update-btn';
140140
document.body.appendChild(widget);
141141

142-
const returnValue = await setUpdateButtonDisplay(true, '', [
143-
{ repoUrl: 'https://fakerepo.com', branch: 'main', destPath: 'mypath' }
144-
]);
142+
const returnValue = await setUpdateButtonDisplay(WidgetState.UpToDate, '');
145143

146144
expect(returnValue).toStrictEqual({ error: '', returncode: 0 });
147145
expect(widget.innerHTML).toContain(`<span class="success">◉</span>`);
148146
});
149147

150-
it('widget update needed populated', async () => {
148+
it('widget update required', async () => {
151149
const widget = await document.createElement('div');
152150
widget.id = 'nbgitpuller-jl-interface-update-btn';
153151
document.body.appendChild(widget);
154152

155-
const returnValue = await setUpdateButtonDisplay(false, '', [
156-
{ repoUrl: 'https://fakerepo.com', branch: 'main', destPath: 'mypath' }
157-
]);
153+
const returnValue = await setUpdateButtonDisplay(WidgetState.UpdateRequired, '');
154+
155+
expect(returnValue).toStrictEqual({ error: '', returncode: 0 });
156+
expect(widget.innerHTML).toContain(`<span class="pending blink">◉</span>`);
157+
});
158+
159+
it('widget error', async () => {
160+
const widget = await document.createElement('div');
161+
widget.id = 'nbgitpuller-jl-interface-update-btn';
162+
document.body.appendChild(widget);
163+
164+
const returnValue = await setUpdateButtonDisplay(WidgetState.Error, '');
158165

159166
expect(returnValue).toStrictEqual({ error: '', returncode: 0 });
160167
expect(widget.innerHTML).toContain(`<span class="failure blink">◉</span>`);
161168
});
162169

163170
it('widget not found', async () => {
164-
const returnValue = await setUpdateButtonDisplay(false, '', [
165-
{ repoUrl: 'https://fakerepo.com', branch: 'main', destPath: 'mypath' }
166-
]);
171+
const returnValue = await setUpdateButtonDisplay(WidgetState.Error, '');
167172

168173
expect(returnValue).toStrictEqual({
169174
error: 'Unable to find nbgitpuller widget',

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export async function checkForUpdatesAndSetDisplay(
239239
}
240240
}
241241

242-
enum WidgetState {
242+
export enum WidgetState {
243243
UpToDate,
244244
UpdateRequired,
245245
Updating,

0 commit comments

Comments
 (0)