test coverage on the plex settings page

This commit is contained in:
tidusjar 2022-12-02 15:37:32 +00:00
commit dc0a66f4d8
9 changed files with 142 additions and 19 deletions

View file

@ -77,7 +77,7 @@
<div *ngFor="let lib of this.data.server.plexSelectedLibraries; let i = index"> <div *ngFor="let lib of this.data.server.plexSelectedLibraries; let i = index">
<div class="md-form-field"> <div class="md-form-field">
<div class="checkbox"> <div class="checkbox">
<mat-slide-toggle [id]="lib[i]" [(ngModel)]="lib.enabled" [checked]="lib.enabled" <mat-slide-toggle id="lib-{{i}}" [(ngModel)]="lib.enabled" [checked]="lib.enabled"
for="{{lib.title}}">{{lib.title}}</mat-slide-toggle> for="{{lib.title}}">{{lib.title}}</mat-slide-toggle>
</div> </div>
</div> </div>

View file

@ -37,7 +37,7 @@ export class PlexServerDialogComponent {
public testPlex() { public testPlex() {
this.testerService.plexTest(this.data.server).pipe(take(1)) this.testerService.plexTest(this.data.server).pipe(take(1))
.subscribe(x => { .subscribe(x => {
if (x === true) { if (x) {
this.notificationService.success(`Successfully connected to the Plex server ${this.data.server.name}!`); this.notificationService.success(`Successfully connected to the Plex server ${this.data.server.name}!`);
} else { } else {
this.notificationService.error(`We could not connect to the Plex server ${this.data.server.name}!`); this.notificationService.error(`We could not connect to the Plex server ${this.data.server.name}!`);

View file

@ -0,0 +1,23 @@
{
"request": {
"method": "GET",
"urlPattern": "/library/sections"
},
"response": {
"status": 200,
"jsonBody": {
"mediaContainer": {
"directory":[
{ "key": "1", "title": "lib1"},
{ "key": "2", "title": "lib2"},
{ "key": "3", "title": "lib3"},
{ "key": "4", "title": "lib4"},
{ "key": "5", "title": "lib5"}
]
}
},
"headers": {
"Content-Type": "application/json"
}
}
}

View file

@ -0,0 +1,16 @@
{
"request": {
"method": "GET"
},
"response": {
"status": 200,
"jsonBody": {
"mediaContainer": {
"version": "99"
}
},
"headers": {
"Content-Type": "application/json"
}
}
}

View file

@ -58,12 +58,20 @@ class PlexServerModal {
get saveButton(): Cypress.Chainable<any> { get saveButton(): Cypress.Chainable<any> {
return cy.get('#saveServer'); return cy.get('#saveServer');
} }
getLib(index: number): Cypress.Chainable<any> {
return cy.get(`#lib-${index}`);
}
} }
class PlexServersGrid { class PlexServersGrid {
serverCardButton(name: string): Cypress.Chainable<any> { serverCardButton(name: string): Cypress.Chainable<any> {
return cy.get(`#${name}-button`); return cy.get(`#${name}-button`);
} }
get newServerButton(): Cypress.Chainable<any> {
return cy.get('#newServer');
}
} }
class PlexSettingsPage extends BasePage { class PlexSettingsPage extends BasePage {

View file

@ -17,6 +17,7 @@
import './commands' import './commands'
import './request.commands'; import './request.commands';
import './plex-settings.commands'; import './plex-settings.commands';
import './mock-data.commands';
import "cypress-real-events/support"; import "cypress-real-events/support";
import '@bahmutov/cy-api/support'; import '@bahmutov/cy-api/support';

View file

@ -0,0 +1,15 @@
Cypress.Commands.add('addMock', (mapping) => {
cy.request({
method: 'POST',
url: 'http://localhost:32400/__admin/mappings',
body: mapping
})
})
Cypress.Commands.add('clearMocks', () => {
cy.request({
method: 'DELETE',
url: 'http://localhost:32400/__admin/mappings'
})
})

View file

@ -6,6 +6,10 @@ describe("Plex Settings Tests", () => {
cy.clearPlexServers(); cy.clearPlexServers();
}); });
afterEach(() => {
cy.clearMocks();
})
const plexTvApiResponse = `{ const plexTvApiResponse = `{
"success": true, "success": true,
"message": null, "message": null,
@ -80,8 +84,10 @@ describe("Plex Settings Tests", () => {
}); });
// Need to finish the witemock container it("Load Servers from Plex.TV Api and Test", () => {
it.skip("Load Servers from Plex.TV Api and Test", () => { cy.fixture('/mocks/plex/plex-test.mock').then((json) => {
cy.addMock(json);
});
loadServerFromPlexTvApi(); loadServerFromPlexTvApi();
cy.intercept("POST", "api/v1/tester/plex", (req) => { cy.intercept("POST", "api/v1/tester/plex", (req) => {
req.reply((res) => { req.reply((res) => {
@ -92,11 +98,46 @@ describe("Plex Settings Tests", () => {
const modal = Page.plexServerModal; const modal = Page.plexServerModal;
modal.testButton.click(); modal.testButton.click();
cy.wait("@testResponse"); cy.wait("@testResponse").then(() => {
cy.contains("Successfully connected to the Plex server AutomationServer");
});
}); });
function loadServerFromPlexTvApi() { it("Load Libraries from New Server", () => {
cy.fixture('/mocks/plex/plex-libraries.mock').then((json) => {
cy.addMock(json);
});
cy.intercept("POST", "api/v1/Plex/Libraries").as("libRequest");
newServer();
const modal = Page.plexServerModal;
modal.loadLibraries.click();
cy.wait("@libRequest");
modal.getLib(0).click();
modal.getLib(0).should('contain.text',"lib1");
});
it("Remove server", () => {
loadServerFromPlexTvApi();
const modal = Page.plexServerModal;
modal.saveButton.click();
newServer(false);
modal.saveButton.click();
Page.plexServerGrid.serverCardButton('AutomationServer').click();
modal.deleteButton.click();
Page.plexServerGrid.serverCardButton('ManualServer').click();
modal.deleteButton.click();
Page.plexServerGrid.serverCardButton('AutomationServer').should('not.exist');
Page.plexServerGrid.serverCardButton('ManualServer').should('not.exist');
});
function loadServerFromPlexTvApi(visitPage = true) {
cy.intercept("POST", "api/v1/Plex/servers", (req) => { cy.intercept("POST", "api/v1/Plex/servers", (req) => {
req.reply((res) => { req.reply((res) => {
res.send(plexTvApiResponse); res.send(plexTvApiResponse);
@ -105,7 +146,9 @@ function loadServerFromPlexTvApi() {
cy.intercept("POST", "api/v1/Settings/Plex").as('plexSave'); cy.intercept("POST", "api/v1/Settings/Plex").as('plexSave');
if (visitPage) {
Page.visit(); Page.visit();
}
Page.plexCredentials.username.type('username'); Page.plexCredentials.username.type('username');
Page.plexCredentials.password.type('password'); Page.plexCredentials.password.type('password');
@ -117,6 +160,23 @@ function loadServerFromPlexTvApi() {
Page.plexCredentials.serverDropdown.click().get('mat-option').contains('AutomationServer').click(); Page.plexCredentials.serverDropdown.click().get('mat-option').contains('AutomationServer').click();
} }
function newServer(visitPage = true) {
if (visitPage) {
Page.visit();
}
Page.plexServerGrid.newServerButton.click();
const modal = Page.plexServerModal;
const server = JSON.parse(plexTvApiResponse);
modal.serverName.clear();
modal.serverName.type("ManualServer");
modal.hostName.type(server.servers.server[0].localAddresses);
modal.port.type(server.servers.server[0].port);
modal.authToken.type(server.servers.server[0].accessToken);
modal.machineIdentifier.type(server.servers.server[0].machineIdentifier);
}
}); });

View file

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"lib": ["es2018", "dom"], "lib": ["es2018", "dom"],
"types": ["cypress", "cypress-wait-until", "cypress-image-snapshot", "cypress-real-events", "@bahmutov/cy-api"], "types": ["cypress", "cypress-wait-until", "cypress-image-snapshot", "cypress-real-events", "@bahmutov/cy-api", "node"],
"baseUrl": "./cypress", "baseUrl": "./cypress",
"paths": { "paths": {
"@/*": ["./*"] "@/*": ["./*"]