Skip to content

Commit

Permalink
fixup! dapp: export user settings to own store module
Browse files Browse the repository at this point in the history
  • Loading branch information
weilbith committed May 10, 2021
1 parent 0c02876 commit 7b72b31
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
4 changes: 2 additions & 2 deletions raiden-dapp/src/store/user-settings/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { EthereumConnectionOptions } from '@/services/ethereum-connection';
import type { UserSettingsState } from './types';

export const mutations: MutationTree<UserSettingsState> = {
enableRaidenAccountUsage(state) {
enableRaidenAccount(state) {
state.useRaidenAccount = true;
},
disableRaidenAccountUsage(state) {
disableRaidenAccount(state) {
state.useRaidenAccount = false;
},
saveEthereumConnectionOptions(
Expand Down
8 changes: 4 additions & 4 deletions raiden-dapp/src/views/account/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ const { mapState, mapMutations } = createNamespacedHelpers('userSettings');
@Component({
computed: {
...mapState(['useRaidenAccount']),
...mapMutations(['enableRaidenAccountUsage', 'disableRaidenAccountUsage']),
...mapMutations(['enableRaidenAccount', 'disableRaidenAccount']),
},
})
export default class RaidenSettings extends Vue {
useRaidenAccount!: boolean;
enableRaidenAccountUsage!: () => void;
disableRaidenAccountUsage!: () => void;
enableRaidenAccount!: () => void;
disableRaidenAccount!: () => void;
toggleRaidenAccountUsage(value: boolean): void {
value ? this.enableRaidenAccountUsage() : this.disableRaidenAccountUsage();
value ? this.enableRaidenAccount() : this.disableRaidenAccount();
}
}
</script>
Expand Down
4 changes: 2 additions & 2 deletions raiden-dapp/tests/unit/store/user-settings/mutations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('user setttings store mutations', () => {
const state = defaultState();
state.useRaidenAccount = false;

mutations.enableRaidenAccountUsage(state);
mutations.enableRaidenAccount(state);

expect(state.useRaidenAccount).toBe(true);
});
Expand All @@ -15,7 +15,7 @@ describe('user setttings store mutations', () => {
const state = defaultState();
expect(state.useRaidenAccount).toBe(true);

mutations.disableRaidenAccountUsage(state);
mutations.disableRaidenAccount(state);

expect(state.useRaidenAccount).toBe(false);
});
Expand Down
12 changes: 6 additions & 6 deletions raiden-dapp/tests/unit/views/account/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jest.mock('vue-router');
Vue.use(Vuetify);
Vue.use(Vuex);

const enableRaidenAccountUsage = jest.fn();
const disableRaidenAccountUsage = jest.fn();
const enableRaidenAccount = jest.fn();
const disableRaidenAccount = jest.fn();

function createWrapper(options?: { useRaidenAccount?: boolean }): Wrapper<Settings> {
const vuetify = new Vuetify();
Expand All @@ -21,8 +21,8 @@ function createWrapper(options?: { useRaidenAccount?: boolean }): Wrapper<Settin
};

const mutations = {
enableRaidenAccountUsage,
disableRaidenAccountUsage,
enableRaidenAccount,
disableRaidenAccount,
};

const userSettingsModule = {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Settings.vue', () => {
toggleInput.trigger('click');
await wrapper.vm.$nextTick();

expect(enableRaidenAccountUsage).toHaveBeenCalledTimes(1);
expect(enableRaidenAccount).toHaveBeenCalledTimes(1);
expect((toggleInput.element as HTMLInputElement).checked).toBe(true);
});

Expand All @@ -72,7 +72,7 @@ describe('Settings.vue', () => {
toggleInput.trigger('click');
await wrapper.vm.$nextTick();

expect(disableRaidenAccountUsage).toHaveBeenCalledTimes(1);
expect(disableRaidenAccount).toHaveBeenCalledTimes(1);
expect((toggleInput.element as HTMLInputElement).checked).toBe(false);
});
});
8 changes: 6 additions & 2 deletions raiden-dapp/tests/unit/views/home.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ describe('Home.vue', () => {
async function connect(settings?: { useRaidenAccount?: boolean }): Promise<void> {
const useRaidenAccount = settings?.useRaidenAccount ?? true;
const mutation = useRaidenAccount
? 'userSettings/enableRaidenAccountUsage'
: 'userSettings/disableRaidenAccountUsage';
? 'userSettings/enableRaidenAccount'
: 'userSettings/disableRaidenAccount';
store.commit(mutation);

await (wrapper.vm as any).connect();
Expand All @@ -78,6 +78,7 @@ describe('Home.vue', () => {
test('successful connect navigates to redirect target if given in query', async () => {
const redirectTo = 'connect/0x5Fc523e13fBAc2140F056AD7A96De2cC0C4Cc63A';
wrapper.vm.$route.query = { redirectTo };
await wrapper.vm.$nextTick();

await connect();

Expand All @@ -86,7 +87,10 @@ describe('Home.vue', () => {

test('connect can be called without displaying error after failing initially', async () => {
(wrapper.vm as any).connectionError = ErrorCode.UNSUPPORTED_NETWORK;
await wrapper.vm.$nextTick();

await connect();

expect((wrapper.vm as any).connectionError).toBe(null);
});

Expand Down

0 comments on commit 7b72b31

Please sign in to comment.