Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create profile tests #83

Open
wants to merge 6 commits into
base: proto
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
setupFilesAfterEnv: ['<rootDir>/tests/unit/setup.js'],
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel'
}
377 changes: 195 additions & 182 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/Profile/SelectColorScheme.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import Vue, { PropType } from 'vue'
import HeaderProfile from '@/components/Profile/Header.vue'
import SelectColorSchemeCard from '@/components/Profile/SelectColorSchemeCard.vue'
import { ColorScheme } from '@/types/generators'
import { ColorScheme } from '@/types/services/userColorSchemeService'

export default Vue.extend({
name: 'SelectColorScheme',
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/SwapStepper.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="swap-stepper">
<template v-for="step in stepsCount">
<div v-show="step === activeStep" :key="step" class="swap-stepper__content">
<div v-show="step === activeStep" :key="step" class="swap-stepper__content" data-test-id="swap-stepper-content">
<slot :name="step" :change-active-step="changeActiveStep"></slot>
</div>
</template>
Expand Down
16 changes: 11 additions & 5 deletions src/views/Profile/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</create-profile-select-color-scheme>
</template>
<template #2="{ changeActiveStep }">
<div class="create-profile__mnemonic-phrase-table">
<div class="create-profile__mnemonic-phrase-table" data-testid="step-mnemonic-phrase">
<create-profile-header class="create-profile__header">
Your secret phrase
<template #help-text>
Expand All @@ -49,7 +49,7 @@
</div>
</template>
<template #3="{ changeActiveStep }">
<div class="create-profile__mnemonic-phrase-table">
<div class="create-profile__mnemonic-phrase-table" data-testid="step-mnemonic-phrase-edit">
<create-profile-header class="create-profile__header">
Fill in the missing words
<template #help-text>
Expand Down Expand Up @@ -123,7 +123,7 @@ import {
FORM_PASSWORD
} from '@/constants/profile'
import { iframeMessageTypes, profileMessageTypes } from '@/constants/messageTypes'
import { ColorScheme } from '@/types/generators'
import { ColorScheme } from '@/types/services/userColorSchemeService'
import { EncryptionParameters, MnemonicPhrase } from '@/types/encryptionParameters'
import { ProfileParameters } from '@/types/profileParameters'
import { ChangeActiveStep } from '@/types/components/UI/swapStepper'
Expand Down Expand Up @@ -179,7 +179,7 @@ export default Vue.extend({

data(): Data {
return {
profilesParameters: profileService.getProfilesParameters(),
profilesParameters: [],
selectedProfileParameters: profileService.getSelectedProfileParameters(),
tableMatrix: [],
isRefreshing: false
Expand All @@ -206,10 +206,13 @@ export default Vue.extend({
async created(): Promise<void> {
if (!this.profilesParameters.length) {
this.profilesParameters = await this.getProfilesParameters(PROFILES_COUNT)

profileService.setProfilesParameters(this.profilesParameters)
} else {
this.profilesParameters = profileService.getProfilesParameters()
}

document.addEventListener('keydown', this.closeByPressingESC)
window.addEventListener('keydown', this.closeByPressingESC)

windowParentPostMessage({
key: CREATE_PROFILE_WINDOW,
Expand Down Expand Up @@ -247,12 +250,14 @@ export default Vue.extend({
}

const profilesParameters = await Promise.all(profilesParametersResolvers)

return profilesParameters
},
async refreshProfilesParameters(): Promise<void> {
if (!this.isRefreshing) {
this.isRefreshing = true
this.profilesParameters = await this.getProfilesParameters(PROFILES_COUNT)

profileService.setProfilesParameters(this.profilesParameters)
this.isRefreshing = false
}
Expand Down Expand Up @@ -312,6 +317,7 @@ export default Vue.extend({
},
goToStepShowMnemonicPhrase(changeActiveStep: ChangeActiveStep): void {
this.tableMatrix = this.getDefaultTableMatrix()

changeActiveStep(STEPS[MNEMONIC_PHRASE_SHOW])
},
goToStepWriteMnemonicPhrase(changeActiveStep: ChangeActiveStep): void {
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/__helpers__/flushPromises.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function flushPromises(): Promise<void> {
return new Promise(resolve => setTimeout(resolve, 0))
}
12 changes: 12 additions & 0 deletions tests/unit/__helpers__/stubComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function stubComponent(Component, options = {}) {
return {
props: Component.options.props,
model: Component.options.model,
// Do not render any slots/scoped slots except default
// This differs from VTU behavior which renders all slots
template: '<div><slot></slot></div>',
// allows wrapper.find(Component) to work for stub
$_vueTestUtils_original: Component,
...options
}
}
6 changes: 6 additions & 0 deletions tests/unit/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Vue from 'vue'
import UI from '@/components/UI'
import { enableAutoDestroy } from '@vue/test-utils'

Vue.use(UI)
enableAutoDestroy(global.afterEach)
Loading