More tests around the requests grid

pull/4097/head
tidusjar 4 years ago
parent b6ce223acd
commit 5ef8aff677

@ -161,6 +161,7 @@ export interface IEpisodesRequests {
available: boolean;
requested: boolean;
approved: boolean;
requestStatus: string;
selected: boolean; // This is for the UI only
}

@ -3,7 +3,7 @@
<mat-tab *ngFor="let season of tv.seasonRequests">
<ng-template mat-tab-label>
<div class="{{getStatusClass(season)}} top-right">
<div attr.data-test="classStatus{{season.seasonNumber}}" class="{{getStatusClass(season)}} top-right">
<span>{{ 'Requests.Season' | translate }} {{season.seasonNumber}}</span>
</div>
</ng-template>
@ -12,13 +12,13 @@
<ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox *ngIf="isSeasonCheckable(season)" (change)="$event ? masterToggle(season.episodes) : null"
<mat-checkbox attr.data-test="masterCheckbox{{season.seasonNumber}}" *ngIf="isSeasonCheckable(season)" (change)="$event ? masterToggle(season.episodes) : null"
[checked]="selection.hasValue() && isAllSelected(season.episodes)"
[indeterminate]="selection.hasValue() && !isAllSelected(season.episodes)">
</mat-checkbox>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox *ngIf="!row.available && !row.requested && !row.approved" (click)="$event.stopPropagation()"
<mat-checkbox attr.data-test="episodeCheckbox{{season.seasonNumber}}{{row.episodeNumber}}" *ngIf="!row.available && !row.requested && !row.approved" (click)="$event.stopPropagation()"
(change)="$event ? selection.toggle(row) : null"
[checked]="selection.isSelected(row)">
</mat-checkbox>
@ -43,7 +43,7 @@
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef> {{ 'Requests.GridStatus' | translate }} </th>
<td mat-cell *matCellDef="let ep">
<div class="{{getEpisodeStatusClass(ep)}} top-right">
<div attr.data-test="episodeStatus{{season.seasonNumber}}{{ep.episodeNumber}}" class="{{getEpisodeStatusClass(ep)}} top-right">
<span>{{ep.requestStatus | translate}}</span>
</div>
</td>
@ -71,11 +71,11 @@
<mat-icon>add</mat-icon></button>
<mat-menu #aboveMenu="matMenu" yPosition="above">
<button mat-menu-item (click)="requestAllSeasons()">{{'Search.TvShows.AllSeasons' | translate }}</button>
<button id="requestAll" mat-menu-item (click)="requestAllSeasons()">{{'Search.TvShows.AllSeasons' | translate }}</button>
<button mat-menu-item (click)="requestFirstSeason()">{{ 'Search.TvShows.FirstSeason' | translate }}</button>
<button id="requestFirst" mat-menu-item (click)="requestFirstSeason()">{{ 'Search.TvShows.FirstSeason' | translate }}</button>
<button mat-menu-item (click)="requestLatestSeason()">{{ 'Search.TvShows.LatestSeason' | translate }}</button>
<button id="requestLatest" mat-menu-item (click)="requestLatestSeason()">{{ 'Search.TvShows.LatestSeason' | translate }}</button>
<button mat-menu-item (click)="submitRequests()">{{ 'Common.Request' | translate }}</button>
<button id="requestSelected" mat-menu-item (click)="submitRequests()">{{ 'Common.Request' | translate }}</button>
</mat-menu>

@ -50,6 +50,7 @@ export class TvRequestGridComponent {
season.episodes.forEach(ep => {
if (this.selection.isSelected(ep)) {
ep.requested = true;
ep.requestStatus = "Common.PendingApproval";
seasonsViewModel.episodes.push({ episodeNumber: ep.episodeNumber });
}
});
@ -65,6 +66,27 @@ export class TvRequestGridComponent {
this.selection.clear();
if (this.tv.firstSeason) {
this.tv.seasonRequests[0].episodes.forEach(ep => {
ep.requested = true;
ep.requestStatus = "Common.PendingApproval";
});
}
if (this.tv.requestAll) {
this.tv.seasonRequests.forEach(season => {
season.episodes.forEach(ep => {
ep.requested = true;
ep.requestStatus = "Common.PendingApproval";
});
});
}
if (this.requestLatestSeason) {
this.tv.seasonRequests[this.tv.seasonRequests.length - 1].episodes.forEach(ep => {
ep.requested = true;
ep.requestStatus = "Common.PendingApproval";
});
}
} else {
this.notificationService.send(requestResult.errorMessage ? requestResult.errorMessage : requestResult.message);
}

@ -70,6 +70,7 @@
<button *ngIf="!request.available" mat-raised-button color="warn" (click)="changeAvailability(request, true);">{{ 'Requests.MarkAvailable' | translate }}</button>
<button *ngIf="request.available" mat-raised-button color="warn" (click)="changeAvailability(request, false);">{{ 'Requests.MarkUnavailable' | translate }}</button>
<button *ngIf="!request.denied" mat-raised-button color="danger" (click)="deny(request);">{{ 'Requests.Deny' | translate }}</button>
<button mat-raised-button color="danger" (click)="delete(request);">{{ 'Requests.RequestPanel.Delete' | translate }}</button>
</div>

@ -40,6 +40,15 @@ export class TvRequestsPanelComponent {
}
}
public async delete(request: IChildRequests) {
const result = await this.requestService.deleteChild(request.id).toPromise();
if (result) {
this.tvRequest.splice(this.tvRequest.indexOf(request),1);
this.messageService.send("Request has been Deleted", "Ok");
}
}
public changeAvailability(request: IChildRequests, available: boolean) {
request.available = available;
request.seasonRequests.forEach((season) => {

@ -105,7 +105,7 @@
</div>
<div class="col-12 col-md-10">
<tv-request-grid [tvRequest]="tvRequest" [isAdmin]="isAdmin" [tv]="tv"></tv-request-grid>
<tv-request-grid id="requests-grid" [tvRequest]="tvRequest" [isAdmin]="isAdmin" [tv]="tv"></tv-request-grid>
</div>
<div class="col-12 col-md-2">

@ -1,6 +1,7 @@
{
"$schema": "https://on.cypress.io/cypress.schema.json",
"supportFile": "cypress/support/index.ts",
"baseUrl": "http://localhost:3577",
"integrationFolder": "cypress/tests",
"testFiles": "**/*.spec.ts*",
"retries": {
@ -8,10 +9,11 @@
"openMode": 1
},
"watchForFileChanges": true,
"projectId": "o5451s",
"viewportWidth": 2560,
"viewportHeight": 1440,
"chromeWebSecurity": false,
"ignoreTestFiles": ["**/snapshots/*"],
"screenshotOnRunFailure": false,
"video": false,
"reporter": "junit",
"reporterOptions": {
"mochaFile": "results/junit/regression-[hash].xml"

@ -32,7 +32,6 @@ Cypress.Commands.add("landingSettings", (enabled) => {
})
Cypress.Commands.add('login', (username, password) => {
cy.clearLocalStorage();
cy.request({
method: 'POST',
url: '/api/v1/token',
@ -88,4 +87,16 @@ Cypress.Commands.add('generateUniqueId', () => {
const uniqueSeed = Date.now().toString();
const id = Cypress._.uniqueId(uniqueSeed);
return id;
});
});
Cypress.Commands.add("getByData", (selector, ...args) => {
return cy.get(`[data-test=${selector}]`, ...args);
});
Cypress.Commands.add("getByData", (selector) => {
return cy.get(`[data-test=${selector}]`);
});
Cypress.Commands.add("getByDataLike", (selector) => {
return cy.get(`[data-test*=${selector}]`);
});

@ -0,0 +1,169 @@
describe("TV Requests Grid", function () {
beforeEach(() => {
cy.login();
});
it("Season not available", () => {
cy.visit("/details/tv/121361");
cy.getByData("classStatus1").should("not.have.class", "available");
cy.getByData("classStatus1").should("not.have.class", "requested");
cy.getByData("classStatus1").should("not.have.class", "approved");
cy.getByData("masterCheckbox1").should("be.visible");
cy.getByDataLike("episodeCheckbox1").each((element) => {
expect(element.length).to.be.greaterThan(0);
});
});
it("Season is requested", () => {
cy.intercept("GET", "**/v2/search/Tv/121361", (req) => {
req.reply((res) => {
const body = res.body;
const requests = body.seasonRequests[0].episodes;
requests.forEach((req) => {
req.requested = true;
req.approved = false;
req.requestStatus = "Common.PendingApproval";
});
body.seasonRequests[0].episodes = requests;
res.send(body);
});
}).as("detailsResponse");
cy.visit("/details/tv/121361");
cy.wait("@detailsResponse");
cy.getByData("classStatus1").should("not.have.class", "available");
cy.getByData("classStatus1").should("have.class", "requested");
cy.getByData("classStatus1").should("not.have.class", "approved");
// checkboxes
cy.getByData("masterCheckbox1").should("not.exist");
cy.getByDataLike("episodeCheckbox1").should("not.exist");
cy.getByDataLike("episodeStatus1").each((element) => {
expect(element.hasClass("requested")).to.be.true;
expect(element.text()).contain('Pending Approval');
});
});
it("Season is approved", () => {
cy.intercept("GET", "**/v2/search/Tv/121361", (req) => {
req.reply((res) => {
const body = res.body;
const requests = body.seasonRequests[0].episodes;
requests.forEach((req) => {
req.approved = true;
req.requested = true;
req.requestStatus = "Common.Approved";
});
body.seasonRequests[0].episodes = requests;
res.send(body);
});
}).as("detailsResponse");
cy.visit("/details/tv/121361");
cy.wait("@detailsResponse");
cy.getByData("classStatus1").should("not.have.class", "available");
cy.getByData("classStatus1").should("not.have.class", "requested");
cy.getByData("classStatus1").should("have.class", "approved");
// checkboxes
cy.getByData("masterCheckbox1").should("not.exist");
cy.getByDataLike("episodeCheckbox1").should("not.exist");
cy.getByDataLike("episodeStatus1").each((element) => {
expect(element.hasClass("approved")).to.be.true;
expect(element.text()).contain('Approved');
});
});
it("Season is available", () => {
cy.intercept("GET", "**/v2/search/Tv/121361", (req) => {
req.reply((res) => {
const body = res.body;
const requests = body.seasonRequests[0].episodes;
requests.forEach((req) => {
req.available = true;
req.requestStatus = "Common.Available";
});
body.seasonRequests[0].episodes = requests;
res.send(body);
});
}).as("detailsResponse");
cy.visit("/details/tv/121361");
cy.wait("@detailsResponse");
cy.getByData("classStatus1").should("have.class", "available");
cy.getByData("classStatus1").should("not.have.class", "requested");
cy.getByData("classStatus1").should("not.have.class", "approved");
// checkboxes
cy.getByData("masterCheckbox1").should("not.exist");
cy.getByDataLike("episodeCheckbox1").should("not.exist");
cy.getByDataLike("episodeStatus1").each((element) => {
expect(element.hasClass("available")).to.be.true;
expect(element.text()).contain('Available');
});
});
it("Request no episodes", () => {
cy.visit("/details/tv/121361");
cy.get('#addFabBtn').click();
cy.get('#requestSelected').click();
cy.verifyNotification('You need to select some episodes!');
});
it("Request single episodes", () => {
cy.visit("/details/tv/121361");
const episodeCheckbox = 'episodeCheckbox11';
cy.getByData(episodeCheckbox).click();
cy.get('#addFabBtn').click();
cy.get('#requestSelected').click();
cy.verifyNotification('Request for Game of Thrones has been added successfully');
cy.getByData('episodeStatus11')
.should('contain.text', 'Pending Approval')
.should('have.class', 'requested')
});
it("Request First Season", () => {
cy.visit("/details/tv/121361");
cy.get('#addFabBtn').click();
cy.get('#requestFirst').click();
cy.verifyNotification('Request for Game of Thrones has been added successfully');
cy.getByDataLike('episodeStatus1')
.should('contain.text', 'Pending Approval')
.should('have.class', 'requested')
});
it.only("Request Latest Season", () => {
cy.visit("/details/tv/121361");
cy.get('#addFabBtn').click();
cy.get('#requestLatest').click();
cy.verifyNotification('Request for Game of Thrones has been added successfully');
cy.getByData("classStatus8").click();
cy.getByData("classStatus8").should("have.class", "requested");
cy.getByDataLike('episodeStatus8')
.should('contain.text', 'Pending Approval')
.should('have.class', 'requested')
});
});

3
tests/global.d.ts vendored

@ -11,6 +11,9 @@ declare namespace Cypress {
verifyNotification(text: string): Chainable<any>;
createUser(username: string, password: string, claims: any[]): Chainable<any>;
generateUniqueId(): Chainable<string>;
getByData(selector: string, args: any[]): Chainable<any>;
getByData(selector: string): Chainable<any>;
getByDataLike(selector: string): Chainable<any>;
requestGenericMovie(): Chainable<any>;
requestMovie(movieId: number): Chainable<any>;

@ -9,6 +9,10 @@
"main": "index.js",
"repository": "https://github.com/ombi-app/ombi.automation",
"author": "TidusJar",
"retries": {
"runMode": 2,
"openMode": 1
},
"scripts": {
"cypress:version": "cypress version",
"cypress:verify": "cypress verify",

Loading…
Cancel
Save