Skip to content

Commit

Permalink
fix: publishing gists with empty files to Github (electron#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckerr authored Jul 14, 2021
1 parent 64808ac commit 133597b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
18 changes: 4 additions & 14 deletions src/renderer/components/commands-action-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,9 @@ export class GistActionButton extends React.Component<
};

private gistFilesList = (values: EditorValues) => {
const filesList: EditorValues = {};

// Add files for default editors.
for (const editor of DEFAULT_EDITORS) {
filesList[editor] = {
content: values[editor] || getEmptyContent(editor),
};
}

for (const id of Object.keys(values)) {
filesList[id] = { content: values[id] };
}

return filesList;
const ids = [...DEFAULT_EDITORS, ...Object.keys(values)];
return Object.fromEntries(
ids.map((id) => [id, { content: values[id] || getEmptyContent(id) }]),
);
};
}
8 changes: 6 additions & 2 deletions tests/renderer/components/commands-publish-button-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DefaultEditorId,
GistActionState,
GistActionType,
MAIN_JS,
} from '../../../src/interfaces';
import { IpcEvents } from '../../../src/ipc-events';
import { ipcRendererManager } from '../../../src/renderer/ipc';
Expand Down Expand Up @@ -135,8 +136,11 @@ describe('Action button component', () => {
expect(mocktokit.gists.create).not.toHaveBeenCalled();
});

it('handles missing content', async () => {
app.getEditorValues.mockReturnValueOnce({});
it.each([
['handles missing files', {}],
['handles empty files', { [MAIN_JS]: '' }],
])('%s', async (_, appEditorValues) => {
app.getEditorValues.mockReturnValueOnce(appEditorValues);
const { instance } = createActionButton();
state.showInputDialog = jest.fn().mockResolvedValueOnce(description);

Expand Down

0 comments on commit 133597b

Please sign in to comment.