-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a21048
commit 1f81207
Showing
8 changed files
with
316 additions
and
10 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
apps/wallet/src/components/change-canister/AdvancedUpdateMode.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { VueWrapper } from '@vue/test-utils'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { ChangeCanisterFormValue } from '~/components/change-canister/change-canister.types'; | ||
import { mount } from '~/test.utils'; | ||
import { ChangeCanisterTargetType } from '~/types/station.types'; | ||
import AdvancedUpdateMode from './AdvancedUpdateMode.vue'; | ||
|
||
describe('AdvancedUpdateMode', () => { | ||
it('renders with empty form', () => { | ||
const wrapper = mount(AdvancedUpdateMode, { | ||
props: { | ||
modelValue: { | ||
wasmInitArg: undefined, | ||
target: undefined, | ||
wasmModule: undefined, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
expect(wrapper.find('[name="target"]').exists()).toBe(true); | ||
expect(wrapper.find('[name="arg"]').exists()).toBe(true); | ||
expect(wrapper.find('[name="wasm"]').exists()).toBe(true); | ||
}); | ||
|
||
it('when target type changes the modelValue picks up the change', async () => { | ||
const wrapper = mount(AdvancedUpdateMode, { | ||
props: { | ||
modelValue: { | ||
wasmInitArg: undefined, | ||
target: undefined, | ||
wasmModule: undefined, | ||
}, | ||
}, | ||
}) as unknown as VueWrapper< | ||
InstanceType<typeof AdvancedUpdateMode> & { upgradeTarget: ChangeCanisterTargetType } | ||
>; | ||
|
||
// picks up the change to upgrade station | ||
wrapper.vm.upgradeTarget = ChangeCanisterTargetType.UpgradeStation; | ||
await wrapper.vm.$nextTick(); | ||
const modelValue = wrapper.emitted('update:modelValue')?.[0]?.[0] as ChangeCanisterFormValue; | ||
expect(modelValue.target).toEqual({ UpgradeStation: null }); | ||
|
||
// picks up the change to upgrade upgrader | ||
wrapper.vm.upgradeTarget = ChangeCanisterTargetType.UpgradeUpgrader; | ||
await wrapper.vm.$nextTick(); | ||
const modelValue2 = wrapper.emitted('update:modelValue')?.[1]?.[0] as ChangeCanisterFormValue; | ||
expect(modelValue2.target).toEqual({ UpgradeUpgrader: null }); | ||
}); | ||
}); |
47 changes: 47 additions & 0 deletions
47
apps/wallet/src/components/change-canister/ChangeCanisterConfirmationScreen.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { mount } from '~/test.utils'; | ||
import ChangeCanisterConfirmationScreen from './ChangeCanisterConfirmationScreen.vue'; | ||
|
||
describe('ChangeCanisterConfirmationScreen', () => { | ||
it('confirmation screen has checksum and comment fields', () => { | ||
const wrapper = mount(ChangeCanisterConfirmationScreen, { | ||
props: { | ||
wasmModuleChecksum: 'checksum', | ||
comment: 'My test comment', | ||
}, | ||
}); | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
expect(wrapper.find('[name="wasm_checksum"]').exists()).toBe(true); | ||
expect(wrapper.find('[name="comment"]').exists()).toBe(true); | ||
}); | ||
|
||
it('confirmation screen shows the checksum in the field in readonly mode', () => { | ||
const wrapper = mount(ChangeCanisterConfirmationScreen, { | ||
props: { | ||
wasmModuleChecksum: 'checksum', | ||
}, | ||
}); | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
|
||
const field = wrapper.find('[name="wasm_checksum"]').element as HTMLInputElement; | ||
expect(field.value).toEqual('checksum'); | ||
expect(field.readOnly).toBe(true); | ||
}); | ||
|
||
it('confirmation screen shows the comment in the field in edit mode', () => { | ||
const wrapper = mount(ChangeCanisterConfirmationScreen, { | ||
props: { | ||
wasmModuleChecksum: 'checksum', | ||
comment: 'My test comment', | ||
}, | ||
}); | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
|
||
const field = wrapper.find('[name="comment"]').element as HTMLInputElement; | ||
expect(field.value).toEqual('My test comment'); | ||
expect(field.readOnly).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
apps/wallet/src/components/change-canister/RegistryUpdateMode.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { mockPinia, mount } from '~/test.utils'; | ||
import RegistryUpdateMode from './RegistryUpdateMode.vue'; | ||
import { useStationStore } from '~/stores/station.store'; | ||
|
||
describe('RegistryUpdateMode', () => { | ||
it('on mount triggers the check for new updates', () => { | ||
const pinia = mockPinia({ activate: true }); | ||
const station = useStationStore(); | ||
vi.spyOn(station, 'checkVersionUpdates').mockImplementation(() => Promise.resolve()); | ||
|
||
const wrapper = mount( | ||
RegistryUpdateMode, | ||
{ props: { modelValue: {} } }, | ||
{ plugins: { pinia } }, | ||
); | ||
|
||
expect(wrapper.exists()).toBe(true); | ||
expect(station.checkVersionUpdates).toHaveBeenCalled(); | ||
}); | ||
|
||
it('shows already in latest version screen', () => { | ||
const pinia = mockPinia({ | ||
activate: true, | ||
initialState: { | ||
station: { | ||
versionManagement: { | ||
loading: false, | ||
nextStationVersion: undefined, | ||
nextUpgraderVersion: undefined, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const station = useStationStore(); | ||
vi.spyOn(station, 'checkVersionUpdates').mockImplementation(() => Promise.resolve()); | ||
|
||
const wrapper = mount( | ||
RegistryUpdateMode, | ||
{ props: { modelValue: {} } }, | ||
{ plugins: { pinia } }, | ||
); | ||
|
||
expect(wrapper.find('[data-test-id="latest-screen"]').exists()).toBe(true); | ||
}); | ||
|
||
it('shows update available screen', () => { | ||
const pinia = mockPinia({ | ||
activate: true, | ||
initialState: { | ||
station: { | ||
versionManagement: { | ||
loading: false, | ||
nextStationVersion: '1.2.3', | ||
nextUpgraderVersion: '1.2.3', | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const station = useStationStore(); | ||
vi.spyOn(station, 'checkVersionUpdates').mockImplementation(() => Promise.resolve()); | ||
|
||
const wrapper = mount( | ||
RegistryUpdateMode, | ||
{ props: { modelValue: {} } }, | ||
{ plugins: { pinia } }, | ||
); | ||
|
||
expect(wrapper.find('[data-test-id="update-available-screen"]').exists()).toBe(true); | ||
}); | ||
|
||
it('shows loading screen while version updates is in progress', () => { | ||
const pinia = mockPinia({ | ||
activate: true, | ||
initialState: { | ||
station: { | ||
versionManagement: { | ||
loading: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const station = useStationStore(); | ||
vi.spyOn(station, 'checkVersionUpdates').mockImplementation(() => Promise.resolve()); | ||
|
||
const wrapper = mount( | ||
RegistryUpdateMode, | ||
{ props: { modelValue: {} } }, | ||
{ plugins: { pinia } }, | ||
); | ||
|
||
expect(station.checkVersionUpdates).not.toHaveBeenCalled(); | ||
expect(wrapper.find('[data-test-id="loading-screen"]').exists()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
apps/wallet/src/composables/change-canister.composable.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
useDefaultUpgradeModel, | ||
useUpgradeTargets, | ||
} from '~/composables/change-canister.composable'; | ||
import { setupComponent } from '~/test.utils'; | ||
import { ChangeCanisterTargetType } from '~/types/station.types'; | ||
|
||
describe('change-canister.composable', () => { | ||
it('should return upgrade targets with correct targets', () => { | ||
const vm = setupComponent(() => ({ targets: useUpgradeTargets() })); | ||
|
||
expect(vm.targets.station.value).toEqual(ChangeCanisterTargetType.UpgradeStation); | ||
expect(vm.targets.upgrader.value).toEqual(ChangeCanisterTargetType.UpgradeUpgrader); | ||
}); | ||
|
||
it('should return default form value with empty values', () => { | ||
const { modelValue } = useDefaultUpgradeModel(); | ||
|
||
expect(modelValue).toEqual({ | ||
target: undefined, | ||
wasmModule: undefined, | ||
wasmInitArg: undefined, | ||
comment: undefined, | ||
}); | ||
}); | ||
|
||
it('by default upgrade form should be invalid', () => { | ||
const { valid } = useDefaultUpgradeModel(); | ||
|
||
expect(valid).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { HttpAgent } from '@dfinity/agent'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { RegistryEntry } from '~/generated/control-panel/control_panel.did'; | ||
import { ControlPanelService } from '~/services/control-panel.service'; | ||
|
||
const mockWasmModuleEntry = (name: string, version: string): RegistryEntry => ({ | ||
id: '', | ||
name, | ||
categories: [], | ||
tags: [], | ||
description: 'This is a test description', | ||
created_at: '2024-01-01T00:00:00Z', | ||
updated_at: [], | ||
metadata: [], | ||
value: { | ||
WasmModule: { | ||
dependencies: [], | ||
version, | ||
wasm_artifact_id: '', | ||
}, | ||
}, | ||
}); | ||
|
||
describe('ControlPanelService', () => { | ||
it('should find module of a given version', async () => { | ||
const controlPanel = new ControlPanelService(new HttpAgent()); | ||
const firstCallEntry = mockWasmModuleEntry('test', '1.0.0'); | ||
const secondCallEntry = mockWasmModuleEntry('test', '1.0.1'); | ||
|
||
vi.spyOn(controlPanel, 'findRegistryEntries') | ||
.mockReturnValue(Promise.resolve({ entries: [], next_offset: [], total: BigInt(0) })) | ||
.mockReturnValueOnce( | ||
Promise.resolve({ entries: [firstCallEntry], next_offset: [BigInt(1)], total: BigInt(2) }), | ||
) | ||
.mockReturnValueOnce( | ||
Promise.resolve({ entries: [secondCallEntry], next_offset: [], total: BigInt(2) }), | ||
); | ||
|
||
vi.spyOn(controlPanel, 'getRegistryEntry').mockReturnValue( | ||
Promise.resolve({ entry: secondCallEntry }), | ||
); | ||
|
||
const entry = await controlPanel.findModuleVersionRegistryEntry('test', '1.0.1'); | ||
|
||
expect(controlPanel.findRegistryEntries).toHaveBeenCalledTimes(2); | ||
expect(controlPanel.getRegistryEntry).toHaveBeenCalledTimes(1); | ||
expect(entry).toEqual(mockWasmModuleEntry('test', '1.0.1')); | ||
}); | ||
|
||
it('should return null if module version is not found', async () => { | ||
const controlPanel = new ControlPanelService(new HttpAgent()); | ||
|
||
vi.spyOn(controlPanel, 'findRegistryEntries').mockReturnValue( | ||
Promise.resolve({ entries: [], next_offset: [], total: BigInt(0) }), | ||
); | ||
|
||
const entry = await controlPanel.findModuleVersionRegistryEntry('test', '1.0.1'); | ||
|
||
expect(entry).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters