Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Frontend
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
841
Issues
841
List
Boards
Labels
Service Desk
Milestones
Merge Requests
41
Merge Requests
41
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Frontend
Commits
ab6a5129
Commit
ab6a5129
authored
34 minutes ago
by
Ben Hayward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding tests
parent
727ebfcc
feat/plus-tiers-578
1 merge request
!460
WIP: [Sprint/JollyJellyfish](feat) Plus tiers engine#578
Pipeline
#74200299
canceled with stages
in 4 minutes and 32 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
40 deletions
+137
-40
list.component.spec.ts
src/app/modules/channels/list.component.spec.ts
+4
-0
payment-plan.component.spec.ts
src/app/modules/plus/plan/payment-plan.component.spec.ts
+97
-39
payment-plan.component.ts
src/app/modules/plus/plan/payment-plan.component.ts
+36
-1
No files found.
src/app/modules/channels/list.component.spec.ts
View file @
ab6a5129
...
...
@@ -73,6 +73,10 @@ describe('ChannelsListComponent', () => {
// synchronous beforeEach
beforeEach
((
done
)
=>
{
jasmine
.
MAX_PRETTY_PRINT_DEPTH
=
10
;
jasmine
.
clock
().
uninstall
();
jasmine
.
clock
().
install
();
fixture
=
TestBed
.
createComponent
(
ChannelsListComponent
);
comp
=
fixture
.
componentInstance
;
...
...
This diff is collapsed.
Click to expand it.
src/app/modules/plus/plan/payment-plan.component.spec.ts
View file @
ab6a5129
import
{
async
,
ComponentFixture
,
TestBed
}
from
'
@angular/core/testing
'
;
import
{
async
,
ComponentFixture
,
TestBed
,
fakeAsync
,
tick
}
from
'
@angular/core/testing
'
;
import
{
DebugElement
}
from
'
@angular/core
'
;
import
{
By
}
from
'
@angular/platform-browser
'
;
import
{
FormsModule
}
from
'
@angular/forms
'
;
...
...
@@ -39,14 +39,34 @@ let overlayModal = new function () {
});
};
f
describe
(
'
WirePaymentsCreatorComponent
'
,
()
=>
{
describe
(
'
WirePaymentsCreatorComponent
'
,
()
=>
{
let
comp
:
PaymentPlanComponent
;
let
fixture
:
ComponentFixture
<
PaymentPlanComponent
>
;
function
getButton
():
DebugElement
{
function
get
Purchase
Button
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__period-buy-button__blue
'
));
}
function
getMonthlyOffchainButton
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__plans div:nth-child(1) input
'
))
}
function
getYearlyOnchainButton
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__plans div:nth-child(2) span:nth-child(3) input
'
))
}
function
getYearlyOffchainButton
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__plans div:nth-child(2) span:nth-child(2) input
'
))
}
function
getLifeOnchainButton
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__plans div:nth-child(3) span:nth-child(3) input
'
))
}
function
getLifeOffchainButton
():
DebugElement
{
return
fixture
.
debugElement
.
query
(
By
.
css
(
'
.m-plus-plan__plans div:nth-child(3) span:nth-child(2) input
'
))
}
beforeEach
(
async
(()
=>
{
...
...
@@ -84,11 +104,31 @@ fdescribe('WirePaymentsCreatorComponent', () => {
jasmine
.
MAX_PRETTY_PRINT_DEPTH
=
10
;
jasmine
.
clock
().
uninstall
();
jasmine
.
clock
().
install
();
fixture
=
TestBed
.
createComponent
(
PaymentPlanComponent
);
window
.
Minds
.
blockchain
=
{
plus_address
:
'
oxtn
'
plus_address
:
'
0x00000000000000
'
}
// comp.receiver = window.Minds.blockchain.plus_address;
clientMock
.
response
=
{};
clientMock
.
response
[
`api/v2/boost/rates`
]
=
{
'
balance
'
:
301529
,
'
rate
'
:
1
,
'
cap
'
:
5000
,
'
min
'
:
100
,
'
usd
'
:
1000
,
'
tokens
'
:
1
};
clientMock
.
response
[
'
api/v2/blockchain/wallet/balance
'
]
=
{
addresses
:
[{
balance
:
1
},
{
balance
:
1
}]
};
comp
=
fixture
.
componentInstance
;
// LoginForm test instance
fixture
.
detectChanges
();
...
...
@@ -103,53 +143,71 @@ fdescribe('WirePaymentsCreatorComponent', () => {
});
afterEach
(()
=>
{
TestBed
.
resetTestingModule
();
jasmine
.
clock
().
uninstall
();
});
it
(
'
should have a purchase button
'
,
()
=>
{
const
button
=
getButton
();
const
button
=
get
Purchase
Button
();
expect
(
button
).
not
.
toBeNull
();
});
it
(
'
should create the payment object for monthly
'
,
()
=>
{
const
button
=
getButton
();
spyOn
(
comp
,
'
submit
'
).
and
.
stub
();
button
.
nativeElement
.
click
();
expect
(
comp
.
submit
).
toHaveBeenCalledWith
(
'
month
'
);
it
(
'
should have all radio buttons
'
,
()
=>
{
expect
(
getMonthlyOffchainButton
()).
not
.
toBeNull
();
expect
(
getYearlyOnchainButton
()).
not
.
toBeNull
();
expect
(
getYearlyOffchainButton
()).
not
.
toBeNull
();
expect
(
getLifeOnchainButton
()).
not
.
toBeNull
();
expect
(
getLifeOffchainButton
()).
not
.
toBeNull
();
});
it
(
'
should set the amount correctly for monthly offchain
'
,
()
=>
{
comp
.
createWire
(
'
offchain month
'
);
expect
(
comp
.
wire
.
amount
).
toBe
(
20
);
it
(
'
radio buttons should change tier value
'
,
()
=>
{
getMonthlyOffchainButton
().
nativeElement
.
click
();
expect
(
comp
.
tier
).
toBe
(
'
offchain month
'
);
getYearlyOffchainButton
().
nativeElement
.
click
();
expect
(
comp
.
tier
).
toBe
(
'
offchain year
'
);
getYearlyOnchainButton
().
nativeElement
.
click
();
expect
(
comp
.
tier
).
toBe
(
'
onchain year
'
);
getLifeOffchainButton
().
nativeElement
.
click
();
expect
(
comp
.
tier
).
toBe
(
'
offchain lifetime
'
);
getLifeOnchainButton
().
nativeElement
.
click
();
expect
(
comp
.
tier
).
toBe
(
'
onchain lifetime
'
);
});
it
(
'
should create the payment object for yearly
'
,
()
=>
{
const
button
=
getButton
();
spyOn
(
comp
,
'
submit
'
).
and
.
stub
();
button
.
nativeElement
.
click
();
expect
(
comp
.
submit
).
toHaveBeenCalledWith
(
'
year
'
);
});
it
(
'
should call submit on purchase button click
'
,
fakeAsync
(()
=>
{
spyOn
(
comp
,
'
submit
'
).
and
.
stub
();
it
(
'
should set the amount correctly for yearly
'
,
()
=>
{
comp
.
createWire
(
'
offchain month
'
);
expect
(
comp
.
wire
.
amount
).
toBe
(
200
);
});
getMonthlyOffchainButton
().
nativeElement
.
click
();
getPurchaseButton
().
nativeElement
.
click
();
expect
(
comp
.
submit
).
toHaveBeenCalled
();
}));
it
(
'
should have a buy life button
'
,
()
=>
{
const
button
=
getButton
();
expect
(
button
).
not
.
toBeNull
();
});
it
(
'
should load the current balance
'
,
()
=>
fakeAsync
(()
=>
{
comp
.
load
();
tick
();
expect
(
comp
.
inProgress
).
toBeFalsy
();
expect
(
comp
.
rates
).
toBe
({
'
balance
'
:
301529
,
'
rate
'
:
1
,
'
cap
'
:
5000
,
'
min
'
:
100
,
'
usd
'
:
1000
,
'
tokens
'
:
1
});
}));
it
(
'
should create the payment object for life
'
,
()
=>
{
const
button
=
getButton
();
spyOn
(
comp
,
'
submit
'
).
and
.
stub
();
button
.
nativeElement
.
click
();
expect
(
comp
.
submit
).
toHaveBeenCalledWith
(
'
lifetime
'
)
});
it
(
'
should set the amount correctly for lifetime
'
,
()
=>
{
comp
.
createWire
(
'
offchain lifetime
'
);
expect
(
comp
.
wire
.
amount
).
toBe
(
500
);
});
it
(
'
should create the wire object correctly
'
,
fakeAsync
(()
=>
{
comp
.
createWire
(
'
offchain month
'
);
tick
();
expect
(
comp
.
wire
).
not
.
toBeNull
();
expect
(
comp
.
wire
.
amount
).
toBe
(
20
);
expect
(
comp
.
wire
.
recurring
).
toBeFalsy
();
expect
(
comp
.
wire
.
guid
).
not
.
toBeNull
();
}));
});
This diff is collapsed.
Click to expand it.
src/app/modules/plus/plan/payment-plan.component.ts
View file @
ab6a5129
...
...
@@ -12,6 +12,14 @@ import { TokenContractService } from '../../blockchain/contracts/token-contract.
export
type
PayloadType
=
'
onchain
'
|
'
offchain
'
;
/**
* Component containing the logic for payment plan component,
* allowing users to select a plus tier, pay and subscribe.
*
* Based on the creator component.
* @author Ben Hayward
*/
@
Component
({
providers
:
[
CurrencyPipe
],
selector
:
'
m-payment-plan
'
,
...
...
@@ -121,6 +129,9 @@ export class PaymentPlanComponent {
}
/**
* Loads balances for the current wallet.
*/
async
loadBalances
()
{
try
{
let
currentWallet
=
await
this
.
web3Wallet
.
getCurrentWallet
();
...
...
@@ -149,6 +160,11 @@ export class PaymentPlanComponent {
}
}
/**
* Loads current balance by wallet address.
* @param {string} address - wallet address
*/
async
loadCurrentWalletBalance
(
address
)
{
try
{
this
.
balances
.
onChainAddress
=
address
;
...
...
@@ -162,6 +178,9 @@ export class PaymentPlanComponent {
}
}
/**
* Loads the current rate of tokens.
*/
async
loadTokenRate
()
{
let
response
:
any
=
await
this
.
client
.
get
(
`api/v2/blockchain/rate/tokens`
);
...
...
@@ -170,6 +189,7 @@ export class PaymentPlanComponent {
}
}
/**
* Populates the wire object
* .
...
...
@@ -207,6 +227,10 @@ export class PaymentPlanComponent {
this
.
wire
.
guid
=
this
.
minds
.
blockchain
.
plus_guid
;
}
/**
* Called on form submission. Submits the payment and returns success or an error.
*/
async
submit
()
{
this
.
createWire
(
this
.
tier
);
...
...
@@ -257,6 +281,7 @@ export class PaymentPlanComponent {
}
}
/**
* Checks if the user can submit using the current settings
*/
...
...
@@ -271,7 +296,8 @@ export class PaymentPlanComponent {
return
false
;
}
/**
/**
* Validates if the wire payment can be submitted using the current settings
*/
validate
()
{
...
...
@@ -311,6 +337,10 @@ export class PaymentPlanComponent {
}
}
/**
* Resets to default values.
*/
setDefaults
()
{
this
.
wire
.
recurring
=
true
;
let
payloadType
=
localStorage
.
getItem
(
'
preferred-payment-method
'
);
...
...
@@ -320,6 +350,7 @@ export class PaymentPlanComponent {
this
.
setPayloadType
(
<
PayloadType
>
payloadType
);
}
/**
* Sets the wire currency
*/
...
...
@@ -338,6 +369,7 @@ export class PaymentPlanComponent {
this
.
showErrors
();
}
/**
* Sets the wire payment nonce
*/
...
...
@@ -346,6 +378,7 @@ export class PaymentPlanComponent {
this
.
showErrors
();
}
/**
* Sets the onchain specific wire payment nonce
*/
...
...
@@ -353,6 +386,7 @@ export class PaymentPlanComponent {
return
this
.
setNoncePayload
({
receiver
:
this
.
blockchain
.
plus_address
,
address
})
}
/**
* Round by 4
*/
...
...
@@ -360,6 +394,7 @@ export class PaymentPlanComponent {
this
.
wire
.
amount
=
Math
.
round
(
parseFloat
(
`
${
this
.
wire
.
amount
}
`
)
*
10000
)
/
10000
;
}
/**
* Shows visible wire errors
*/
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment