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

Added testcases for Tokens & TotalAmount Component #1629

Open
wants to merge 5 commits into
base: develop
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
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
/.idea
/.nyc_output
.DS_Store
/tests/e2e/videos
/tests/e2e/screenshots
/tests/e2e/videos/
/tests/e2e/screenshots/
/coverage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all changes to this file should be undone.


# local env files
.env.local
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
'<rootDir>/config/jest/setEnvVars.js',
'<rootDir>/config/jest/setup.js',
],
collectCoverage: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to collect coverage on every run of test:unit command. I think it would be better to track coverage differently.
#1778

transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.vue$': 'vue-jest',
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/TokenAmount.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { shallowMount } from '@vue/test-utils';
import TokenAmount from '../../src/popup/components/TokenAmount.vue';

let wrapper;

describe('TokenAmount', () => {
beforeEach(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to have a beforeEach and a wrapper variable deinfed out of scope, since you have only one test.

wrapper = shallowMount(TokenAmount, {
propsData: {
amount: 111,
hideFiat: true,
direction: 'sent',
large: false,
noSymbol: true,
highPrecision: false,
},
mocks: {
$store: {
state: {},
getters: {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import and use particular getters instead of mocking them, in order to cover all the cases in the TokenAmount component.

},
},
});
});

it('should match the snapshot', () => {
expect(wrapper.html()).toMatchSnapshot();
});
});
34 changes: 34 additions & 0 deletions tests/unit/Tokens.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { shallowMount } from '@vue/test-utils';
import Tokens from '../../src/popup/components/Tokens.vue';
Copy link
Collaborator

@CedrikNikita CedrikNikita Jan 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not covering all the potential cases of Tokens component.


let wrapper;

describe('Tokens', () => {
beforeEach(() => {
wrapper = shallowMount(Tokens, {
propsData: {
tokens: [{ symbol: 'test123', contractId: '1' }, { symbol: 'test456', contractId: '2' }],
vertical: true,
},
});
});

it('should match the snapshot', () => {
expect(wrapper.html()).toMatchSnapshot();
});

it('should test getAvailableCharLength', async () => {
const getAvailableCharLength = jest.spyOn(wrapper.vm, 'getAvailableCharLength');
let length = wrapper.vm.getAvailableCharLength();
expect(getAvailableCharLength).toHaveBeenCalled();
expect(length).toEqual(5);
await wrapper.setProps({
symbolLength: 11,
doubleSymbolLength: 5,
tokens: [{ symbol: 'test' }, { symbol: 'test456' }],
vertical: true,
});
length = wrapper.vm.getAvailableCharLength();
expect(length).toEqual(7);
});
});
8 changes: 8 additions & 0 deletions tests/unit/__snapshots__/TokenAmount.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TokenAmount should match the snapshot 1`] = `
<span class="token-amount sent"><span><!----> <span class="amount">
111
<!----></span></span>
<!----></span>
`;
11 changes: 11 additions & 0 deletions tests/unit/__snapshots__/Tokens.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tokens should match the snapshot 1`] = `
<span class="tokens rg vertical"><span class="icons"><img src="https://avatars.z52da5wt.xyz/2" title="test456" class="to-token border"> <img src="https://avatars.z52da5wt.xyz/1" title="test123" class="border pair"></span> <span class="symbols"><span class="symbol">
test1...
</span> <span class="separator">
/
</span> <span class="symbol">
test4...
</span></span></span>
`;