mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 12:59:39 -07:00
test coverage on the plex settings page
This commit is contained in:
parent
cd6b70f771
commit
dc0a66f4d8
9 changed files with 142 additions and 19 deletions
|
@ -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>
|
||||||
|
|
|
@ -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}!`);
|
||||||
|
|
23
tests/cypress/fixtures/mocks/plex/plex-libraries.mock.json
Normal file
23
tests/cypress/fixtures/mocks/plex/plex-libraries.mock.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
tests/cypress/fixtures/mocks/plex/plex-test.mock.json
Normal file
16
tests/cypress/fixtures/mocks/plex/plex-test.mock.json
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"request": {
|
||||||
|
"method": "GET"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
"status": 200,
|
||||||
|
"jsonBody": {
|
||||||
|
"mediaContainer": {
|
||||||
|
"version": "99"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"headers": {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 {
|
||||||
|
|
|
@ -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';
|
||||||
|
|
||||||
|
|
15
tests/cypress/support/mock-data.commands.ts
Normal file
15
tests/cypress/support/mock-data.commands.ts
Normal 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'
|
||||||
|
})
|
||||||
|
})
|
|
@ -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,30 +98,84 @@ 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.intercept("POST", "api/v1/Plex/servers", (req) => {
|
cy.fixture('/mocks/plex/plex-libraries.mock').then((json) => {
|
||||||
req.reply((res) => {
|
cy.addMock(json);
|
||||||
res.send(plexTvApiResponse);
|
|
||||||
});
|
});
|
||||||
}).as("serverResponse");
|
cy.intercept("POST", "api/v1/Plex/Libraries").as("libRequest");
|
||||||
|
newServer();
|
||||||
|
|
||||||
cy.intercept("POST", "api/v1/Settings/Plex").as('plexSave');
|
const modal = Page.plexServerModal;
|
||||||
|
modal.loadLibraries.click();
|
||||||
|
|
||||||
Page.visit();
|
cy.wait("@libRequest");
|
||||||
|
|
||||||
Page.plexCredentials.username.type('username');
|
modal.getLib(0).click();
|
||||||
Page.plexCredentials.password.type('password');
|
modal.getLib(0).should('contain.text',"lib1");
|
||||||
|
});
|
||||||
|
|
||||||
Page.plexCredentials.loadServers.click();
|
it("Remove server", () => {
|
||||||
|
loadServerFromPlexTvApi();
|
||||||
|
const modal = Page.plexServerModal;
|
||||||
|
modal.saveButton.click();
|
||||||
|
|
||||||
cy.wait("@serverResponse");
|
newServer(false);
|
||||||
|
modal.saveButton.click();
|
||||||
|
|
||||||
Page.plexCredentials.serverDropdown.click().get('mat-option').contains('AutomationServer').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) => {
|
||||||
|
req.reply((res) => {
|
||||||
|
res.send(plexTvApiResponse);
|
||||||
|
});
|
||||||
|
}).as("serverResponse");
|
||||||
|
|
||||||
|
cy.intercept("POST", "api/v1/Settings/Plex").as('plexSave');
|
||||||
|
|
||||||
|
if (visitPage) {
|
||||||
|
Page.visit();
|
||||||
|
}
|
||||||
|
|
||||||
|
Page.plexCredentials.username.type('username');
|
||||||
|
Page.plexCredentials.password.type('password');
|
||||||
|
|
||||||
|
Page.plexCredentials.loadServers.click();
|
||||||
|
|
||||||
|
cy.wait("@serverResponse");
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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": {
|
||||||
"@/*": ["./*"]
|
"@/*": ["./*"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue