Added automation tests for the voting feature

pull/2588/head^2
TidusJar 6 years ago
parent 4508f79a5f
commit 2d0c48a867

@ -65,10 +65,10 @@
<tbody>
<tr *ngFor="let vm of completedVotes">
<td class="vcenter">
<button class="btn btn-info-outline col-md-6" [ngClass]="{'btn-success-outline': vm.myVote == VoteType.Upvote, 'btn-info-outline': vm.myVote != VoteType.Upvote}"
<button id="{{vm.requestId}}upvote" class="btn btn-info-outline col-md-6" [ngClass]="{'btn-success-outline': vm.myVote == VoteType.Upvote, 'btn-info-outline': vm.myVote != VoteType.Upvote}"
(click)="upvote(vm)" [disabled]="vm.myVote == VoteType.Upvote"><i class="fa fa-thumbs-o-up"
aria-hidden="true"></i></button>
<button class="btn btn-info-outline col-md-6" [ngClass]="{'btn-danger-outline': vm.myVote == VoteType.Downvote, 'btn-info-outline': vm.myVote != VoteType.Downvote}"
<button id="{{vm.requestId}}downvote" class="btn btn-info-outline col-md-6" [ngClass]="{'btn-danger-outline': vm.myVote == VoteType.Downvote, 'btn-info-outline': vm.myVote != VoteType.Downvote}"
(click)="downvote(vm)" [disabled]="vm.myVote == VoteType.Downvote"><i class="fa fa-thumbs-o-down"
aria-hidden="true"></i></button>
</td>
@ -76,7 +76,7 @@
height: auto;
width: 100%;"
(click)="toggle($event, vm.image)" src="{{vm.image}}" alt="poster"></td>
<td class="vcenter">{{vm.title}}</td>
<td class="vcenter" [attr.data-test]='vm.requestId'>{{vm.title}}</td>
<td class="vcenter" [innerHTML]="vm.description"></td>
</tr>
</tbody>

@ -0,0 +1,86 @@
/// <reference types="Cypress" />
describe('Voting Feature', function () {
beforeEach(function () {
cy.login('automation', 'password').then(() => {
cy.createUser('basicUser', 'password', [{
value: "requestmovie",
Enabled: "true",
}, {
value: "requesttv",
Enabled: "true",
}, {
value: "requestmusic",
Enabled: "true",
},
]);
cy.createUser('basicUser2', 'password', [{
value: "requestmovie",
Enabled: "true",
}, {
value: "requesttv",
Enabled: "true",
}, {
value: "requestmusic",
Enabled: "true",
},
]);
// Enable voting
cy.request({
method: 'POST',
url: '/api/v1/Settings/vote',
body: {
Enabled: true,
MovieVoteMax: 2,
MusicVoteMax: 2,
TvShowVoteMax: 2,
},
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'),
}
});
// Login as the regular user now
cy.clearLocalStorage();
cy.login('basicUser', 'password').then(() => {
cy.visit('/vote');
});
});
});
it('Loads votes page', function () {
// cy.login('basicUser','password');
cy.contains("Vote");
});
it('Request Movie automatically upvotes when I am the requestor', function () {
cy.requestMovie(335983).then(() => {
cy.visit('/vote');
cy.get('#completedVotes').click();
cy.contains('Venom').should('have.attr', 'data-test').then(($id) => {
cy.get('#' + $id + 'upvote').should('have.attr', 'disabled');
cy.get('#' + $id + 'downvote').should('not.have.attr', 'disabled');
});
});
});
it('Request TV automatically upvotes when I am the requestor', function () {
cy.requestAllTv(305288).then(() => {
cy.visit('/vote');
cy.get('#completedVotes').click();
cy.contains('Stranger Things').should('have.attr', 'data-test').then(($id) => {
cy.get('#' + $id + 'upvote').should('have.attr', 'disabled');
cy.get('#' + $id + 'downvote').should('not.have.attr', 'disabled');
});
});
});
});

@ -34,9 +34,12 @@ Cypress.Commands.add('login', (username, password) => {
}
})
.then((resp) => {
window.localStorage.setItem('id_token', resp.body.access_token)
window.localStorage.setItem('id_token', resp.body.access_token);
});
});
Cypress.Commands.add('removeLogin', () => {
window.localStorage.removeItem('id_token');
});
Cypress.Commands.add('createUser', (username, password, claims) => {
cy.request({
@ -57,3 +60,4 @@ Cypress.Commands.add('verifyNotification', (text) => {
cy.get('.ui-growl-title').should('be.visible');
cy.get('.ui-growl-title').next().contains(text)
});

@ -14,7 +14,8 @@
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
import './commands';
import './request.commands';
// Alternatively you can use CommonJS syntax:
// require('./commands')

@ -0,0 +1,40 @@
Cypress.Commands.add('requestGenericMovie', () => {
cy.request({
method: 'POST',
url: '/api/v1/request/movie',
body: {
TheMovieDbId: 299536
},
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'),
}
})
})
Cypress.Commands.add('requestMovie', (movieId) => {
cy.request({
method: 'POST',
url: '/api/v1/request/movie',
body: {
TheMovieDbId: movieId
},
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'),
}
})
})
Cypress.Commands.add('requestAllTv', (tvId) => {
cy.request({
method: 'POST',
url: '/api/v1/request/tv',
body: {
TvDbId: tvId,
RequestAll: true
},
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'),
}
})
})
Loading…
Cancel
Save