Skip to content

Instantly share code, notes, and snippets.

View thomashagstrom's full-sized avatar

Thomas Hagström thomashagstrom

  • Chas Consulting AB
  • Stockholm, Sweden
View GitHub Profile
@thomashagstrom
thomashagstrom / cloudSettings
Last active January 15, 2018 13:48
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-01-15T13:48:50.107Z","extensionVersion":"v2.8.7"}
@thomashagstrom
thomashagstrom / DropboxService.cs
Last active January 11, 2019 13:09
DropboxService.Authorize
/// <summary>
/// <para>Runs the Dropbox OAuth authorization process if not yet authenticated.</para>
/// <para>Upon completion <seealso cref="OnAuthenticated"/> is called</para>
/// </summary>
/// <returns>An asynchronous task.</returns>
public async Task Authorize()
{
if (string.IsNullOrWhiteSpace(this.AccessToken) == false)
{
// Already authorized
@thomashagstrom
thomashagstrom / DropboxService.cs
Created January 11, 2019 13:11
WebViewOnNavigating method
private async void WebViewOnNavigating(object sender, WebNavigatingEventArgs e)
{
if (!e.Url.StartsWith(RedirectUri, StringComparison.OrdinalIgnoreCase))
{
// we need to ignore all navigation that isn't to the redirect uri.
return;
}
try
{
@thomashagstrom
thomashagstrom / DropboxService.cs
Created January 11, 2019 13:13
DropboxClient
using (var client = new DropboxClient(this.AccessToken))
{
// List files
var list = await client.Files.ListFolderAsync(string.Empty);
IList<Metadata> entries = list?.Entries;
// Get file as bytes
var response = await client.Files.DownloadAsync(file);
var bytes = response?.GetContentAsByteArrayAsync();
@thomashagstrom
thomashagstrom / jest.config.js
Created January 11, 2019 22:42
Jest code coverage
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
"**/*.{ts,tsx}",
"!**/node_modules/**",
"!**/vendor/**",
"!**/__mocks__/**",
"!**/__snapshots__/**",
"!**/android/**",
"!**/ios/**",
@thomashagstrom
thomashagstrom / ReadMe.md
Created January 11, 2019 22:50
Codecov Markdown badge

[codecov]

@thomashagstrom
thomashagstrom / Codecov.sh
Created January 11, 2019 22:58
Upload to codecov
echo Upload code coverage
echo Token: "$(CODECOV_TOKEN)"
codecov -t "$(CODECOV_TOKEN)"
@thomashagstrom
thomashagstrom / JestSetState.tsx
Created January 13, 2019 12:10
Jest set React component state
const wrapper = TestRenderer.create(<CognitoLogin />);
const state: ICognitoLoginState = {
formState: 'Register',
code: 'testcode',
userInput: { email: 'bogus@test.com', password: 'testPw' },
result: undefined,
};
wrapper.root.instance.setState(state);
@thomashagstrom
thomashagstrom / FindByTestID.test.tsx
Last active January 13, 2019 12:22
Jest find React child by testID
it('On forgot password should not throw', () => {
const wrapper = TestRenderer.create(<CognitoLogin />);
const child = wrapper.root.findByProps({
testID: 'ForgotForm',
});
expect(child).toBeDefined();
});
@thomashagstrom
thomashagstrom / JestReadReactState.test.tsx
Created January 13, 2019 12:30
Read React state in Jest test
import React from 'react';
import TestRenderer from 'react-test-renderer';
import CognitoLogin from './CognitoLogin';
import _ from 'lodash';
it('When no `code` or `email` `onSavePress` should set `message` to `Need code and user e-mail`', async (done) => {
// Arrange
const wrapper = TestRenderer.create(<CognitoLogin />);
const child = wrapper.root.findByProps({
testID: 'ForgotForm',