Skip to content

Commit

Permalink
PriceChart unit tests fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karynemayer committed Apr 23, 2024
1 parent fc55784 commit b589851
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 106 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"ual-anchor": "1.3.0",
"universal-authenticator-library": "^0.3.0",
"vue": "^3.3.0",
"vue-class-component": "^7.2.6",
"vue-json-viewer": "^3.0.4",
"vue-router": "^4.0.0",
"vue3-openlayers": "^0.1.63"
Expand Down
43 changes: 37 additions & 6 deletions test/jest/__tests__/components/PriceChart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
beforeEach,
} from '@jest/globals';
import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-jest';
import { shallowMount } from '@vue/test-utils';
import { mount } from '@vue/test-utils';
import PriceChart from 'src/components/PriceChart.vue';
import { PriceStats, PriceHistory } from 'src/types';
import axios from 'axios';
Expand Down Expand Up @@ -55,33 +55,64 @@ describe('PriceChart', () => {
it('returns value rounded to 2 decimals as a % string', () => {
const testVal = 123.456;
const expected = '123.46 %';
const wrapper = shallowMount(PriceChart);
const wrapper = mount(PriceChart, {
global: {
stubs: {
Highcharts: {
template: '<span />',
},
},
},
});
const received = wrapper.vm.formatPercentage(testVal);

expect(received).toBe(expected);
});
});
describe('formatCurrencyValue', () => {
it('returns value as "$" rounded to 2 decimals if value is less than a million', () => {
const testVal = 999999.9911;
const expected = '$999999.99';
const wrapper = shallowMount(PriceChart);
const wrapper = mount(PriceChart, {
global: {
stubs: {
Highcharts: {
template: '<span />',
},
},
},
});
const received = wrapper.vm.formatCurrencyValue(testVal);

expect(received).toBe(expected);
});
it('returns value "$" divided by a million rounded to 2 decimals and appended with "M" if value is greater than a million and less than a billion', () => {
const testVal = 1234567.89;
const expected = '$1.23M';
const wrapper = shallowMount(PriceChart);
const wrapper = mount(PriceChart, {
global: {
stubs: {
Highcharts: {
template: '<span />',
},
},
},
});
const received = wrapper.vm.formatCurrencyValue(testVal);

expect(received).toBe(expected);
});
it('returns value "$" divided by a billion rounded to 2 decimals and appended with "B" if value is greater than a billion', () => {
const testVal = 123456789123.45678;
const expected = '$123.46B';
const wrapper = shallowMount(PriceChart);
const wrapper = mount(PriceChart, {
global: {
stubs: {
Highcharts: {
template: '<span />',
},
},
},
});
const received = wrapper.vm.formatCurrencyValue(testVal);

expect(received).toBe(expected);
Expand Down
Loading

0 comments on commit b589851

Please sign in to comment.