Skip to content

Commit

Permalink
adds initial testing framework
Browse files Browse the repository at this point in the history
updates tests to comply with formatting
  • Loading branch information
keno dressel authored and davidyuk committed Mar 17, 2020
1 parent 475dccc commit 48bcb7f
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ yarn-error.log*
*.sw?

*.iml
cypress/*
4 changes: 3 additions & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"pluginsFile": "tests/e2e/plugins/index.js"
"video": false,
"pluginsFile": "tests/e2e/plugins/index.js",
"screenshotOnRunFailure": false
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "aepp-raendom",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down
10 changes: 5 additions & 5 deletions src/components/tipRecords/TipRecord.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{{ tip.amount_ae }} <span class="ae">AE</span>
</span>
<fiat-value :amount="tip.total_amount"></fiat-value>
<span class="ml-4" v-on:click.stop>
<span class="ml-4 retip__wrapper" v-on:click.stop>
<retip :tipid="tip.id" :retip-icon="true"/>
{{ tip.retip_amount_ae }} <span class="ae">AE</span>
<fiat-value :amount="tip.retip_amount_ae"></fiat-value>
Expand Down Expand Up @@ -248,13 +248,13 @@
@media (min-width: 576px){
.tip__record .tip__body .tip__author .date.wholeaddr{
padding-top: 0;
}
}
}
@media (min-width: 768px) {
.tip__record .tip__body .tip__author .date.wholeaddr{
padding-top: 0;
}
}
}
@media (min-width: 992px) {
Expand All @@ -265,7 +265,7 @@
.date{
padding-top: 0;
}
}
}
}
@media (min-width: 1200px) {
Expand All @@ -276,7 +276,7 @@
.date.wholeaddr{
padding-top: .3rem;
}
}
}
}
@media only screen and (max-width: 1024px){
Expand Down
32 changes: 19 additions & 13 deletions src/utils/aeternity.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,25 @@ const timeout = async (promise) => {
};

aeternity.initProvider = async (force = false) => {
try {
// TESTING
if (process && process.env && process.env.PRIVATE_KEY && process.env.PUBLIC_KEY) {
aeternity.contractAddress = 'ct_2GRP3xp7KWrKtZSnYfdcLnreRWrntWf5aTsxtLqpBHp71EFc3i';
aeternity.oracleContract = {
methods: {
get_state: async () => ({success_claimed_urls: []})
}
}
force = false
aeternity.client = await Universal({
compilerUrl: 'https://latest.compiler.aepps.com',
nodes: [{ name: 'testnet', instance: await Node({ url: 'https://sdk-testnet.aepps.com', internalUrl: 'https://sdk-testnet.aepps.com' }) }],
accounts: [
MemoryAccount({ keypair: { secretKey: process.env.PRIVATE_KEY, publicKey: process.env.PUBLIC_KEY } }),
],
address: process.env.PUBLIC_KEY,
});
}
try {
if (force || aeternity.contractAddress && !aeternity.contract)
aeternity.contract = await aeternity.client.getContractInstance(TIPPING_INTERFACE, {contractAddress: aeternity.contractAddress});
if (force || aeternity.oracleContractAddress && !aeternity.oracleContract)
Expand Down Expand Up @@ -73,18 +91,6 @@ aeternity.isTestnet = () => {
aeternity.initClient = async () => {
let result = true;

if (process && process.env && process.env.PRIVATE_KEY && process.env.PUBLIC_KEY) {
aeternity.client = await Universal({
compilerUrl: 'https://latest.compiler.aepps.com',
nodes: [{ name: 'testnet', instance: await Node({ url: 'https://sdk-testnet.aepps.com', internalUrl: 'https://sdk-testnet.aepps.com' }) }],
accounts: [
MemoryAccount({ keypair: { secretKey: process.env.PRIVATE_KEY, publicKey: process.env.PUBLIC_KEY } }),
],
address: process.env.PUBLIC_KEY,
});
return await aeternity.initProvider();
}

if (!aeternity.client) {
try {
aeternity.client = await aeternity.initStaticClient();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class Backend {
MAINNET_URL;

constructor() {
this.BACKEND_URL = "https://raendom-backend.z52da5wt.xyz";
this.BACKEND_URL = process.env && process.env.PUBLIC_KEY ? 'http://localhost/' : "https://raendom-backend.z52da5wt.xyz";
this.MAINNET_URL = 'https://mainnet.aeternal.io/'
}

Expand Down
19 changes: 18 additions & 1 deletion src/utils/walletSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Node, RpcAepp } from '@aeternity/aepp-sdk/es';
import Detector from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/wallet-detector';
import BrowserWindowMessageConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message';
import aeternity from "./aeternity";
import { MemoryAccount, Universal } from '@aeternity/aepp-sdk'

// Send wallet connection info to Aepp through content script
const NODE_URL = 'https://sdk-mainnet.aepps.com';
Expand Down Expand Up @@ -33,7 +34,23 @@ export const wallet = {
},

async init (successCallback) {
window !== window.parent;
if (process && process.env && process.env.PRIVATE_KEY && process.env.PUBLIC_KEY) {
this.client = await Universal({
compilerUrl: COMPILER_URL,
nodes: [{ name: 'testnet', instance: await Node({ url: 'https://sdk-testnet.aepps.com', internalUrl: 'https://sdk-testnet.aepps.com' }) }],
accounts: [
MemoryAccount({ keypair: { secretKey: process.env.PRIVATE_KEY, publicKey: process.env.PUBLIC_KEY } }),
],
address: process.env.PUBLIC_KEY,
});
aeternity.client = this.client;
this.height = await this.client.height();
this.client.rpcClient = {
getCurrentAccount: async () => process.env.PUBLIC_KEY
}
await aeternity.initProvider(true);
return successCallback();
}

this.client = await RpcAepp({
name: 'Superhero',
Expand Down
59 changes: 59 additions & 0 deletions tests/e2e/specs/home.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
describe('Home.vue', function () {

describe('overall view', () => {
before(() => {
cy.visit('/');
});
it('Home should be active', () => {
cy.get(':nth-child(1) > a > span').should('have.class', 'active');
});
it('Should show aggregated data', () => {
cy.get(':nth-child(1) > .overview__value').should('be.visible');
});
it('Wallet Install is hidden on found wallet', () => {
cy.get('.wallet-install').should('not.be.visible');
});
it('Tip mask is shown on found wallet', () => {
cy.get('.tip__post').should('be.visible');
});
});

describe('create tip', () => {
const randomString = [...Array(20)].map(() => Math.random().toString(36)[2]).join('');
it('Should create tip', () => {
cy.get('.col-md-4 > .input-group > .form-control').type('0.1');
cy.get('.col-md-8 > .form-control').type('https://aeternity.com');
cy.get(':nth-child(3) > .form-control').type(randomString, { force: true });
cy.get('.btn').click();
});

it('Created tip should be visible', () => {
cy.contains(randomString, {timeout: 10000}).should('be.visible');
});

it('Tip should navigate to SingleTipView', () => {
cy.contains(randomString).click();
cy.url().should('contain', '/tip/');
});
});

describe('retip', () => {
before(() => {
cy.visit('/');
cy.server();
cy.route('/v2/accounts/ak_fUq2NesPXcYZ1CcqBcGC3StpdnQw3iVxMA3YSeCNAwfN4myQk').as('getAccount');
});
it('Should be able to retip tip', () => {
cy.wait('@getAccount');
// Define route here so we do not trigger it while loading initially
cy.route('POST', '/v2/debug/transactions/dry-run').as('dryRun');
cy.get('.tip__amount .retip__icon').first().click();
cy.get('.retip__container').should('be.visible');
cy.get('.retip__container input').type('0.01');
cy.get('.retip__container .btn').click();
cy.wait('@dryRun', { requestTimeout: 10000 });
cy.get('.retip__wrapper').should('be.visible');
cy.get('.retip__container').should('not.be.visible');
});
});
});
19 changes: 19 additions & 0 deletions tests/e2e/specs/singletipview.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
describe('TipRecord.vue', function () {
before(() => {
cy.visit('/#/tip/1');
});

it('Content should be visible', () => {
cy.get('.title > span').should('be.visible');
cy.get('.tip__amount').should('be.visible');
cy.get('.tip__amount').should('contain.text', '0.1');
});

const randomString = [...Array(20)].map(() => Math.random().toString(36)[2]).join('');
it.skip('Should be able to post comment', () => {
// Needs backend implementation
cy.get('.form-control').type(randomString);
cy.get('.btn').click();
});

});
2 changes: 1 addition & 1 deletion tests/e2e/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This is will overwrite an existing command --
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

0 comments on commit 48bcb7f

Please sign in to comment.