This commit is contained in:
tidusjar 2022-12-02 12:27:46 +00:00
commit cd6b70f771
15 changed files with 3540 additions and 440 deletions

27
tests/cypress.config.ts Normal file
View file

@ -0,0 +1,27 @@
import { defineConfig } from 'cypress'
export default defineConfig({
watchForFileChanges: true,
chromeWebSecurity: false,
viewportWidth: 2560,
viewportHeight: 1440,
retries: {
runMode: 2,
openMode: 0,
},
env: {
username: 'a',
password: 'a',
},
projectId: 'o5451s',
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:5000',
specPattern: 'cypress/tests/**/*.spec.ts*',
excludeSpecPattern: ['**/snapshots/*'],
},
})

View file

@ -1,23 +0,0 @@
{
"$schema": "https://on.cypress.io/cypress.schema.json",
"supportFile": "cypress/support/index.ts",
"baseUrl": "http://localhost:5000",
"integrationFolder": "cypress/tests",
"testFiles": "**/*.spec.ts*",
"watchForFileChanges": true,
"chromeWebSecurity": false,
"viewportWidth": 2560,
"viewportHeight": 1440,
"retries": {
"runMode": 2,
"openMode": 0
},
"ignoreTestFiles": [
"**/snapshots/*"
],
"env": {
"username": "a",
"password": "a"
},
"projectId": "o5451s"
}

View file

@ -6,3 +6,5 @@ export * from './search/search.page';
export * from './user-preferences/user-preferences.page';
export * from './requests/requests.page';
export * from './details/movies/moviedetails.page';
export * from './settings/settings.page';
export * from './settings/plex/plex-settings.page';

View file

@ -0,0 +1,118 @@
import { BasePage } from "../../base.page";
class PlexCredentials {
get username(): Cypress.Chainable<any> {
return cy.get('#username');
}
get password(): Cypress.Chainable<any> {
return cy.get('#password');
}
get loadServers(): Cypress.Chainable<any> {
return cy.get('#loadServers');
}
get serverDropdown(): Cypress.Chainable<any> {
return cy.get('#servers');
}
}
class PlexServerModal {
get serverName(): Cypress.Chainable<any> {
return cy.get('#serverName');
}
get hostName(): Cypress.Chainable<any> {
return cy.get('#ip');
}
get port(): Cypress.Chainable<any> {
return cy.get('#port');
}
get ssl(): Cypress.Chainable<any> {
return cy.get('#ssl');
}
get authToken(): Cypress.Chainable<any> {
return cy.get('#authToken');
}
get machineIdentifier(): Cypress.Chainable<any> {
return cy.get('#machineId');
}
get externalHostname(): Cypress.Chainable<any> {
return cy.get('#externalHostname');
}
get batchSize(): Cypress.Chainable<any> {
return cy.get('#batchSize');
}
get loadLibraries(): Cypress.Chainable<any> {
return cy.get('#loadLibs');
}
get testButton(): Cypress.Chainable<any> {
return cy.get('#testPlexButton');
}
get deleteButton(): Cypress.Chainable<any> {
return cy.get('#deleteServer');
}
get cancelButton(): Cypress.Chainable<any> {
return cy.get('#cancel');
}
get saveButton(): Cypress.Chainable<any> {
return cy.get('#saveServer');
}
}
class PlexServersGrid {
serverCardButton(name: string): Cypress.Chainable<any> {
return cy.get(`#${name}-button`);
}
}
class PlexSettingsPage extends BasePage {
get enableCheckbox(): Cypress.Chainable<any> {
return cy.get('#enable');
}
get enableWatchlist(): Cypress.Chainable<any> {
return cy.get('#enableWatchlistImport');
}
get submit(): Cypress.Chainable<any> {
return cy.get('#save');
}
get fullySync(): Cypress.Chainable<any> {
return cy.get('#fullSync');
}
get partialSync(): Cypress.Chainable<any> {
return cy.get('#recentlyAddedSync');
}
get clearAndResync(): Cypress.Chainable<any> {
return cy.get('#clearData');
}
get runWatchlist(): Cypress.Chainable<any> {
return cy.get('#watchlistImport');
}
plexCredentials = new PlexCredentials();
plexServerModal = new PlexServerModal();
plexServerGrid = new PlexServersGrid();
constructor() {
super();
}
visit(options: Cypress.VisitOptions): Cypress.Chainable<Cypress.AUTWindow>;
visit(): Cypress.Chainable<Cypress.AUTWindow>;
visit(id: string): Cypress.Chainable<Cypress.AUTWindow>;
visit(id: string, options: Cypress.VisitOptions): Cypress.Chainable<Cypress.AUTWindow>;
visit(id?: any, options?: any) {
return cy.visit(`/Settings/Plex`, options);
}
}
export const plexSettingsPage = new PlexSettingsPage();

View file

@ -0,0 +1,20 @@
import { BasePage } from "../base.page";
class SettingsPage extends BasePage {
constructor() {
super();
}
visit(options: Cypress.VisitOptions): Cypress.Chainable<Cypress.AUTWindow>;
visit(): Cypress.Chainable<Cypress.AUTWindow>;
visit(id: string): Cypress.Chainable<Cypress.AUTWindow>;
visit(id: string, options: Cypress.VisitOptions): Cypress.Chainable<Cypress.AUTWindow>;
visit(id?: any, options?: any) {
return cy.visit(`/Settings/About`, options);
}
}
export const settingsPage = new SettingsPage();

View file

@ -12,10 +12,10 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

View file

@ -113,7 +113,7 @@ Cypress.Commands.add("getByData", (selector) => {
if (element.fireEvent) {
element.fireEvent('on' + event);
} else {
var evObj = document.createEvent('Events');
const evObj = document.createEvent('Events');
evObj.initEvent(event, true, false);

View file

@ -16,6 +16,7 @@
// Import commands.js using ES2015 syntax:
import './commands'
import './request.commands';
import './plex-settings.commands';
import "cypress-real-events/support";
import '@bahmutov/cy-api/support';

View file

@ -0,0 +1,12 @@
Cypress.Commands.add('clearPlexServers', () => {
cy.request({
method: 'POST',
url: '/api/v1/Settings/Plex/',
body: `{"enable":false,"enableWatchlistImport":false,"monitorAll":false,"installId":"0c5c597d-56ea-4f34-8f59-18d34ec82482","servers":[],"id":2}`,
headers: {
'Authorization': 'Bearer ' + window.localStorage.getItem('id_token'),
'Content-Type':"application/json"
}
})
})

View file

@ -0,0 +1,122 @@
import { plexSettingsPage as Page } from "@/integration/page-objects";
describe("Plex Settings Tests", () => {
beforeEach(() => {
cy.login();
cy.clearPlexServers();
});
const plexTvApiResponse = `{
"success": true,
"message": null,
"servers": {
"server": [
{
"accessToken": "myaccessToken",
"name": "AutomationServer",
"address": "1.1.1.1",
"port": "32400",
"version": "1.30.0.6442-5070ad484",
"scheme": "http",
"host": "2.2.2.2",
"localAddresses": "localhost",
"machineIdentifier": "9999999999999999",
"createdAt": "5555555555",
"updatedAt": "6666666666",
"owned": "1",
"synced": "0",
"sourceTitle": null,
"ownerId": null,
"home": null
}
],
"friendlyName": "myPlex",
"identifier": "com.plexapp.plugins.myplex",
"machineIdentifier": "3dd86546546546540ff065465460c2654654654654",
"size": "1"
}
}
`;
it("Load Servers from Plex.TV Api and Save", () => {
loadServerFromPlexTvApi();
const modal = Page.plexServerModal;
modal.serverName.should('have.value','AutomationServer');
modal.hostName.should('have.value','localhost');
modal.port.should('have.value','32400');
modal.authToken.should('have.value','myaccessToken');
modal.machineIdentifier.should('have.value','9999999999999999');
modal.saveButton.click();
Page.plexServerGrid.serverCardButton('AutomationServer').should('be.visible');
Page.submit.click();
cy.wait("@plexSave");
});
it("Load Servers from Plex.TV Api and Edit", () => {
loadServerFromPlexTvApi();
const modal = Page.plexServerModal;
modal.saveButton.click();
Page.plexServerGrid.serverCardButton('AutomationServer').should('be.visible');
Page.submit.click();
cy.wait("@plexSave");
// Edit server
Page.plexServerGrid.serverCardButton('AutomationServer').click();
modal.serverName.should('have.value','AutomationServer');
modal.hostName.should('have.value','localhost');
modal.port.should('have.value','32400');
modal.authToken.should('have.value','myaccessToken');
modal.machineIdentifier.should('have.value','9999999999999999');
});
// Need to finish the witemock container
it.skip("Load Servers from Plex.TV Api and Test", () => {
loadServerFromPlexTvApi();
cy.intercept("POST", "api/v1/tester/plex", (req) => {
req.reply((res) => {
res.send(plexTvApiResponse);
});
}).as("testResponse");
const modal = Page.plexServerModal;
modal.testButton.click();
cy.wait("@testResponse");
});
function loadServerFromPlexTvApi() {
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');
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();
}
});

View file

@ -1,7 +1,8 @@
{
"devDependencies": {
"@bahmutov/cy-api": "^1.5.0",
"cypress": "6.8.0",
"cypress": "11.2.0",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress-wait-until": "^1.7.1",
"typescript": "^4.2.3"
},

File diff suppressed because it is too large Load diff