Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:mudita/mudita-center into CP-3097
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszMudita committed Dec 13, 2024
2 parents 22ee623 + 7c67e12 commit d2c3534
Show file tree
Hide file tree
Showing 51 changed files with 1,449 additions and 183 deletions.
30 changes: 30 additions & 0 deletions apps/mudita-center-e2e/src/helpers/mock-prebackup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { E2EMockClient } from "../../../../libs/e2e-mock/client/src"

// Helper function to mock PRE_BACKUP responses
export function mockPreBackupResponses(path: string) {
// Mock initial PRE_BACKUP response with status 202 (processing)
E2EMockClient.mockResponse({
path,
endpoint: "PRE_BACKUP",
method: "POST",
status: 202,
body: {},
})

// After 10 seconds, update the response to status 200 (completed)
// setTimeout(() => {
// E2EMockClient.mockResponse({
// path,
// endpoint: "PRE_BACKUP",
// method: "POST",
// status: 200,
// body: {
// backupId,
// features: {
// CONTACTS_V1: "path/to/backup/calls.json",
// CALL_LOGS_V1: "path/to/backup/call_logs.json",
// },
// },
// })
// }, 10000)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import {
PredefinedBackupProgressTestIds,
ProgressBarTestIds,
} from "../../../../libs/e2e-test-ids/src"
import { OverviewPage } from "./overview.page"

class ModalBackupKompaktPage extends OverviewPage {
Expand Down Expand Up @@ -87,5 +91,27 @@ class ModalBackupKompaktPage extends OverviewPage {
public get passwordsDoNotMatch() {
return $('[data-testid="interactive-text-input-error-text"]')
}

public get backupInProgressModal() {
return $('//*[@data-testid="modal-content-backupbackup-create"]')
}

public get creatingBackupTitle() {
return $(`//*[@data-testid="predefined-backup-progress-title"]`)
}

public get creatingBackupDescription() {
return $(
`//*[@data-testid="${PredefinedBackupProgressTestIds.Description}"]`
)
}

public get creatingBackupProgressBar() {
return $(`//*[@data-testid="${ProgressBarTestIds.Progress}"]`)
}

public get creatingBackupProgressBarDetails() {
return $(`//*[@data-testid="${ProgressBarTestIds.Details}"]`)
}
}
export default new ModalBackupKompaktPage()
90 changes: 90 additions & 0 deletions apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { E2EMockClient } from "../../../../../libs/e2e-mock/client/src"
import {
overviewConfigForBackup,
overviewDataWithOneSimCard,
} from "../../../../../libs/e2e-mock/responses/src"
import ModalBackupKompaktPage from "../../page-objects/modal-backup-kompakt.page"
import { mockPreBackupResponses } from "../../helpers/mock-prebackup"

describe("E2E mock sample - overview view", () => {
before(async () => {
E2EMockClient.connect()
//wait for a connection to be established
await browser.waitUntil(() => {
return E2EMockClient.checkConnection()
})
})

after(() => {
E2EMockClient.stopServer()
E2EMockClient.disconnect()
})

it("Connect device", async () => {
E2EMockClient.mockResponse({
path: "path-1",
body: overviewConfigForBackup,
endpoint: "FEATURE_CONFIGURATION",
method: "GET",
status: 200,
})
E2EMockClient.mockResponse({
path: "path-1",
body: overviewDataWithOneSimCard,
endpoint: "FEATURE_DATA",
method: "GET",
status: 200,
})
E2EMockClient.addDevice({
path: "path-1",
serialNumber: "first-serial-number",
})

await browser.pause(6000)
const menuItem = await $(`//a[@href="#/generic/mc-overview"]`)

await menuItem.waitForDisplayed({ timeout: 10000 })
await expect(menuItem).toBeDisplayed()
})

it("Mock prebackup, wait for Overview Page and click Create Backup", async () => {
mockPreBackupResponses("path-1")
const createBackupButton = await ModalBackupKompaktPage.createBackupButton
await expect(createBackupButton).toBeDisplayed()
await expect(createBackupButton).toBeClickable()
await createBackupButton.click()
})

it("Click Create backup and click skip password to start backup", async () => {
const createBackupProceedNext =
await ModalBackupKompaktPage.createBackupProceedNext
await expect(createBackupProceedNext).toBeClickable()
await createBackupProceedNext.click()

const createBackupPasswordSkip =
await ModalBackupKompaktPage.createBackupPasswordSkip
await createBackupPasswordSkip.click()
})

it("Verify backup creating modal, check if backup is in progress", async () => {
const backupInProgressModal =
await ModalBackupKompaktPage.backupInProgressModal
await expect(backupInProgressModal).toBeDisplayed()
await expect(ModalBackupKompaktPage.creatingBackupTitle).toHaveText(
"Creating backup"
)
await expect(ModalBackupKompaktPage.creatingBackupDescription).toHaveText(
"Please wait and do not unplug your device from computer."
)
const creatingBackupProgressBar =
await ModalBackupKompaktPage.creatingBackupProgressBar

const creatingBackupProgressBarValue =
await creatingBackupProgressBar.getAttribute("value")
expect(creatingBackupProgressBarValue).toBe("10")

const creatingBackupProgressBarDetails =
await ModalBackupKompaktPage.creatingBackupProgressBarDetails
await expect(creatingBackupProgressBarDetails).toHaveText("10%")
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export enum TestFilesPaths {
helpVerifyFeedback = "src/specs/help/help-verify-feedback.ts",
helpSectionSearchNoResults = "src/specs/help/help-section-search-noresults.e2e.ts",
helpLinkInsideContainer = "src/specs/help/help-link-inside-container.ts",
kompaktPrebackupApi = "src/specs/overview/kompakt-prebackup-api.ts",
}
export const toRelativePath = (path: string) => `./${path}`
3 changes: 3 additions & 0 deletions apps/mudita-center-e2e/wdio.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.helpVerifyFeedback),
toRelativePath(TestFilesPaths.helpSectionSearchNoResults),
toRelativePath(TestFilesPaths.helpLinkInsideContainer),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
suites: {
standalone: [
Expand Down Expand Up @@ -113,6 +114,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest),
toRelativePath(TestFilesPaths.kompaktDrawerStressTest),
toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
multidevicePureHarmony: [],
multideviceSingleHarmony: [],
Expand Down Expand Up @@ -152,6 +154,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest),
toRelativePath(TestFilesPaths.kompaktDrawerStressTest),
toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo),
toRelativePath(TestFilesPaths.kompaktPrebackupApi),
],
},
// Patterns to exclude.
Expand Down
33 changes: 13 additions & 20 deletions libs/core/settings/services/configuration.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import MockAdapter from "axios-mock-adapter"
import axios from "axios"
import { Configuration } from "Core/settings/dto"
import { ConfigurationService } from "Core/settings/services/configuration.service"

Expand All @@ -19,12 +17,6 @@ jest.mock("history", () => ({
})),
}))

const createMockAdapter = (): MockAdapter => {
return new MockAdapter(axios)
}

let axiosMock: MockAdapter = createMockAdapter()

const previousEnvironment = { ...process.env }

const configuration: Configuration = {
Expand All @@ -45,10 +37,6 @@ const defaultConfig = {
},
}

beforeEach(() => {
axiosMock = createMockAdapter()
})

beforeAll(() => {
process.env = {
...previousEnvironment,
Expand All @@ -62,16 +50,24 @@ afterAll(() => {
}
})

const mockGet = jest.fn()

jest.mock("shared/http-client", () => ({
HttpClient: {
create: jest.fn(() => ({
get: mockGet,
})),
},
}))

jest.doMock(
"Core/settings/static/default-app-configuration.json",
() => defaultConfig
)

describe("When API return success status code", () => {
test("returns API response", async () => {
axiosMock
.onGet("http://localhost/v2-app-configuration")
.replyOnce(200, configuration)
mockGet.mockResolvedValueOnce({ data: configuration, status: 200 })

const subject = new ConfigurationService()
const result = await subject.getConfiguration()
Expand All @@ -81,11 +77,8 @@ describe("When API return success status code", () => {

describe("When API return failed status code", () => {
test("returns default configuration value", async () => {
axiosMock.onGet("http://localhost/v2-app-configuration").replyOnce(500, {
error: "Luke, I'm your error",
})
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
mockGet.mockResolvedValueOnce({ error: "Luke, I'm your error", status: 500 })

const appConfiguration = require("../static/app-configuration.json")
const subject = new ConfigurationService()
const result = await subject.getConfiguration()
Expand Down
11 changes: 7 additions & 4 deletions libs/core/settings/services/configuration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*/

import https from "https"
import { Axios, AxiosResponse } from "axios"
import { HttpClient } from "shared/http-client"
import {
BaseHttpAxiosResponse,
BaseHttpClientService,
HttpClient,
} from "shared/http-client"
import defaultConfiguration from "Core/settings/static/default-app-configuration.json"
import { Configuration } from "Core/settings/dto"
import { MuditaCenterServerRoutes } from "Core/__deprecated__/api/mudita-center-server/mudita-center-server-routes"
Expand All @@ -20,7 +23,7 @@ export interface getNewConfigurationParams {
}

export class ConfigurationService {
private instance: Axios
private instance: BaseHttpClientService
private defaultConfiguration: Configuration =
defaultConfiguration as unknown as Configuration

Expand Down Expand Up @@ -52,7 +55,7 @@ export class ConfigurationService {

private async getNewConfiguration(
params: getNewConfigurationParams
): Promise<AxiosResponse<Configuration>> {
): Promise<BaseHttpAxiosResponse<Configuration>> {
return this.instance.get<Configuration>(
MuditaCenterServerRoutes.AppConfigurationV2,
{
Expand Down
13 changes: 11 additions & 2 deletions libs/device/feature/src/lib/api-features/api-features.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,17 @@ export class APIFeaturesService {
}

@IpcEvent(APIFeaturesServiceEvents.FeatureData)
public async getFeatureData(feature: string): Promise<ResultObject<unknown>> {
const device = this.deviceProtocol.apiDevice
public async getFeatureData({
feature,
deviceId,
}: {
feature: string
deviceId?: DeviceId
}): Promise<ResultObject<unknown>> {
const device = deviceId
? this.deviceProtocol.getAPIDeviceById(deviceId)
: this.deviceProtocol.apiDevice

if (!device) {
return Result.failed(new AppError(GeneralError.NoDevice, ""))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) Mudita sp. z o.o. All rights reserved.
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { ipcRenderer } from "electron-better-ipc"
import { Feature } from "generic-view/models"
import { APIFeaturesServiceEvents } from "device/models"
import { ResultObject } from "Core/core/builder"
import { DeviceId } from "Core/device/constants/device-id"

export const getFeatureDataRequest = (
deviceId: DeviceId,
feature: string
): Promise<ResultObject<Feature["data"]>> => {
return ipcRenderer.callMain(APIFeaturesServiceEvents.FeatureData, {
deviceId,
feature,
})
}
1 change: 1 addition & 0 deletions libs/device/feature/src/lib/api-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./api-features.service"
export * from "./get-overview-data.request"
export * from "./get-overview-configuration.request"
export * from "./get-feature-configuration.request"
export * from "./get-feature-data.request"
27 changes: 24 additions & 3 deletions libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { findIndex, pullAt, find } from "lodash"
import { findIndex, pullAt, find, merge } from "lodash"
import { PortInfo } from "serialport"
import {
AddKompakt,
Expand Down Expand Up @@ -205,7 +205,25 @@ class MockDescriptor {
method,
responses: perDeviceOnceResponses,
})
return foundResponse.response
return merge(
foundResponse.response,
this.fillEndpointSpecificFields(endpoint, method, body)
)
}
}
return undefined
}

private fillEndpointSpecificFields(
endpoint: APIEndpointType,
method: APIMethodsType,
body: Record<string, unknown> | undefined
) {
if ((method === "POST" || method === "GET") && endpoint === "PRE_BACKUP") {
return {
body: {
backupId: body?.["backupId"],
},
}
}
return undefined
Expand All @@ -223,7 +241,10 @@ class MockDescriptor {
const foundResponse = this.findResponse(perDeviceResponses, body)

if (foundResponse) {
return foundResponse.response
return merge(
foundResponse.response,
this.fillEndpointSpecificFields(endpoint, method, body)
)
}
}
return undefined
Expand Down
Loading

0 comments on commit d2c3534

Please sign in to comment.