From dd1642f8fc3eee7786b6ec40c45db48ef305e4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kowalczyk?= Date: Tue, 3 Dec 2024 15:01:48 +0100 Subject: [PATCH 01/11] add specific fields to mocked responses --- .../lib/mock-descriptor/mock-descriptor.ts | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts index 8282d6af04..9c376ea158 100644 --- a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts +++ b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts @@ -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, @@ -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 | undefined + ) { + if ((method === "POST" || method === "GET") && endpoint === "PRE_BACKUP") { + return { + body: { + backupId: body?.["backupId"], + }, } } return undefined @@ -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 From 519d56fd5a6fe9b3e25e9ca904df51cc3557708a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kowalczyk?= Date: Tue, 3 Dec 2024 15:03:33 +0100 Subject: [PATCH 02/11] to revert --- libs/e2e-mock/server/src/lib/server.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/e2e-mock/server/src/lib/server.tsx b/libs/e2e-mock/server/src/lib/server.tsx index 2715cf491b..3597d4725a 100644 --- a/libs/e2e-mock/server/src/lib/server.tsx +++ b/libs/e2e-mock/server/src/lib/server.tsx @@ -75,4 +75,5 @@ export function stopServer() { ipc.server.stop() } -export const mockServiceEnabled = process.env.MOCK_SERVICE_ENABLED === "1" +// export const mockServiceEnabled = process.env.MOCK_SERVICE_ENABLED === "1" +export const mockServiceEnabled = true From 69241510968d325a5380997fd54d32c95387cadb Mon Sep 17 00:00:00 2001 From: robertmudi Date: Wed, 4 Dec 2024 19:19:35 +0100 Subject: [PATCH 03/11] CP-2931 added a new test, modifiec mock-descriptor --- .../page-objects/modal-backup-kompakt.page.ts | 8 ++ .../specs/overview/kompakt-prebackup-api.ts | 79 +++++++++++++++++++ .../lib/mock-descriptor/mock-descriptor.ts | 30 +++++++ 3 files changed, 117 insertions(+) create mode 100644 apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts diff --git a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts index 9d5714b246..585e1dde17 100644 --- a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts @@ -87,5 +87,13 @@ class ModalBackupKompaktPage extends OverviewPage { public get passwordsDoNotMatch() { return $('[data-testid="interactive-text-input-error-text"]') } + + public get backupInProgressModal() { + return $('//*[@data-testid=""]') + } + + public get creatingBackupTitle() { + return $('//*[@data-testid=""]') + } } export default new ModalBackupKompaktPage() diff --git a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts new file mode 100644 index 0000000000..0e215ad1b0 --- /dev/null +++ b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts @@ -0,0 +1,79 @@ +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" + +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("Wait for Overview Page and click Create Backup", async () => { + 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() + + await browser.pause(10000) + }) + + xit("Click Create backup and click skip password to start backup", async () => { + const backupInProgressModal = + await ModalBackupKompaktPage.backupInProgressModal + await expect(backupInProgressModal).toBeDisplayed() + const creatingBackupTitle = await ModalBackupKompaktPage.creatingBackupTitle + const creatingBackupTitleText = await creatingBackupTitle?.getProperty( + "textContent" + ) + expect(creatingBackupTitleText).toContain("Creating backup") + }) +}) diff --git a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts index 9c376ea158..785344f3f1 100644 --- a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts +++ b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts @@ -87,6 +87,36 @@ class MockDescriptor { }, } } + // Add method for mocking PRE_BACKUP responses + public mockPreBackupResponses(path: string, backupId: number) { + // Mock initial PRE_BACKUP response with status 202 (processing) + this.addResponse({ + path, + endpoint: "PRE_BACKUP", + method: "POST", + status: 202, + body: { + backupId, + }, + }) + + // After 10 seconds, update the response to status 200 (completed) + setTimeout(() => { + this.addResponse({ + 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) + } public removeResponses({ path, requests }: RestoreDefaultResponses) { requests?.forEach((request) => { From 4ac4ba5b8ab5659d36d6d4a7506efcb05ec513f7 Mon Sep 17 00:00:00 2001 From: robertmudi Date: Thu, 5 Dec 2024 17:32:28 +0100 Subject: [PATCH 04/11] CP-2931-base finished tests, updated wdio conf andtestfilenames --- .../page-objects/modal-backup-kompakt.page.ts | 12 ++++++++++-- .../specs/overview/kompakt-prebackup-api.ts | 18 +++++++++++++++--- .../consts/test-filenames.const.ts | 1 + apps/mudita-center-e2e/wdio.conf.ts | 3 +++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts index 585e1dde17..aa0d189157 100644 --- a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts @@ -89,11 +89,19 @@ class ModalBackupKompaktPage extends OverviewPage { } public get backupInProgressModal() { - return $('//*[@data-testid=""]') + return $('//*[@data-testid="modal-content-backupbackup-create"]') } public get creatingBackupTitle() { - return $('//*[@data-testid=""]') + return $('//*[@data-testid="predefined-backup-progress-title"]') + } + + public get creatingBackupDescription() { + return $('//*[@data-testid="predefined-backup-progress-description"]') + } + + public get creatingBackupProgressBar() { + return $('//*[@data-testid="progressbar-progress"]') } } export default new ModalBackupKompaktPage() diff --git a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts index 0e215ad1b0..73345dda40 100644 --- a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts +++ b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts @@ -62,11 +62,9 @@ describe("E2E mock sample - overview view", () => { const createBackupPasswordSkip = await ModalBackupKompaktPage.createBackupPasswordSkip await createBackupPasswordSkip.click() - - await browser.pause(10000) }) - xit("Click Create backup and click skip password to start backup", async () => { + it("Verify backup creating modal, check if backup is in progress", async () => { const backupInProgressModal = await ModalBackupKompaktPage.backupInProgressModal await expect(backupInProgressModal).toBeDisplayed() @@ -75,5 +73,19 @@ describe("E2E mock sample - overview view", () => { "textContent" ) expect(creatingBackupTitleText).toContain("Creating backup") + const creatingBackupDescription = + await ModalBackupKompaktPage.creatingBackupDescription + const creatingBackupDescriptionText = + await creatingBackupDescription?.getProperty("textContent") + expect(creatingBackupDescriptionText).toContain( + "Please wait and do not unplug your device from computer." + ) + + const creatingBackupProgressBar = + await ModalBackupKompaktPage.creatingBackupProgressBar + + const creatingBackupProgressBarValue = + await creatingBackupProgressBar.getAttribute("value") + await expect(creatingBackupProgressBarValue).toBe("10") }) }) diff --git a/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts b/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts index c94a52db37..86aba47144 100644 --- a/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts +++ b/apps/mudita-center-e2e/src/test-filenames/consts/test-filenames.const.ts @@ -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}` diff --git a/apps/mudita-center-e2e/wdio.conf.ts b/apps/mudita-center-e2e/wdio.conf.ts index ad56e458b2..53cc029d45 100644 --- a/apps/mudita-center-e2e/wdio.conf.ts +++ b/apps/mudita-center-e2e/wdio.conf.ts @@ -82,6 +82,7 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.helpVerifyFeedback), toRelativePath(TestFilesPaths.helpSectionSearchNoResults), toRelativePath(TestFilesPaths.helpLinkInsideContainer), + toRelativePath(TestFilesPaths.kompaktPrebackupApi), ], suites: { standalone: [ @@ -113,6 +114,7 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest), toRelativePath(TestFilesPaths.kompaktDrawerStressTest), toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo), + toRelativePath(TestFilesPaths.kompaktPrebackupApi), ], multidevicePureHarmony: [], multideviceSingleHarmony: [], @@ -152,6 +154,7 @@ export const config: Options.Testrunner = { toRelativePath(TestFilesPaths.kompaktConnectedDevicesModalStressTest), toRelativePath(TestFilesPaths.kompaktDrawerStressTest), toRelativePath(TestFilesPaths.kompaktBackupModalGettingInitialInfo), + toRelativePath(TestFilesPaths.kompaktPrebackupApi), ], }, // Patterns to exclude. From b32a6fa144d884b801cad866576dfd30bf0123c2 Mon Sep 17 00:00:00 2001 From: robertmudi Date: Thu, 5 Dec 2024 19:24:20 +0100 Subject: [PATCH 05/11] CP-2931 upgraded locators and added new assertion --- .../page-objects/modal-backup-kompakt.page.ts | 16 +++++++++++++--- .../specs/overview/kompakt-prebackup-api.ts | 19 ++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts index aa0d189157..7b9a79d7d8 100644 --- a/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts +++ b/apps/mudita-center-e2e/src/page-objects/modal-backup-kompakt.page.ts @@ -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 { @@ -93,15 +97,21 @@ class ModalBackupKompaktPage extends OverviewPage { } public get creatingBackupTitle() { - return $('//*[@data-testid="predefined-backup-progress-title"]') + return $(`//*[@data-testid="predefined-backup-progress-title"]`) } public get creatingBackupDescription() { - return $('//*[@data-testid="predefined-backup-progress-description"]') + return $( + `//*[@data-testid="${PredefinedBackupProgressTestIds.Description}"]` + ) } public get creatingBackupProgressBar() { - return $('//*[@data-testid="progressbar-progress"]') + return $(`//*[@data-testid="${ProgressBarTestIds.Progress}"]`) + } + + public get creatingBackupProgressBarDetails() { + return $(`//*[@data-testid="${ProgressBarTestIds.Details}"]`) } } export default new ModalBackupKompaktPage() diff --git a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts index 73345dda40..3e8621fdce 100644 --- a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts +++ b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts @@ -68,24 +68,21 @@ describe("E2E mock sample - overview view", () => { const backupInProgressModal = await ModalBackupKompaktPage.backupInProgressModal await expect(backupInProgressModal).toBeDisplayed() - const creatingBackupTitle = await ModalBackupKompaktPage.creatingBackupTitle - const creatingBackupTitleText = await creatingBackupTitle?.getProperty( - "textContent" + await expect(ModalBackupKompaktPage.creatingBackupTitle).toHaveText( + "Creating backup" ) - expect(creatingBackupTitleText).toContain("Creating backup") - const creatingBackupDescription = - await ModalBackupKompaktPage.creatingBackupDescription - const creatingBackupDescriptionText = - await creatingBackupDescription?.getProperty("textContent") - expect(creatingBackupDescriptionText).toContain( + 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") - await expect(creatingBackupProgressBarValue).toBe("10") + expect(creatingBackupProgressBarValue).toBe("10") + + const creatingBackupProgressBarDetails = + await ModalBackupKompaktPage.creatingBackupProgressBarDetails + await expect(creatingBackupProgressBarDetails).toHaveText("10%") }) }) From dcc3e849ead37f0c76fba66bde9db8a8d054dcab Mon Sep 17 00:00:00 2001 From: mkurczewski Date: Fri, 6 Dec 2024 10:48:24 +0100 Subject: [PATCH 06/11] Fixed configuration service --- .../services/configuration.service.test.ts | 33 ++++++++----------- .../services/configuration.service.ts | 11 ++++--- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/libs/core/settings/services/configuration.service.test.ts b/libs/core/settings/services/configuration.service.test.ts index 03d3fe3c1d..24eba092fb 100644 --- a/libs/core/settings/services/configuration.service.test.ts +++ b/libs/core/settings/services/configuration.service.test.ts @@ -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" @@ -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 = { @@ -45,10 +37,6 @@ const defaultConfig = { }, } -beforeEach(() => { - axiosMock = createMockAdapter() -}) - beforeAll(() => { process.env = { ...previousEnvironment, @@ -62,6 +50,16 @@ 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 @@ -69,9 +67,7 @@ jest.doMock( 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() @@ -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() diff --git a/libs/core/settings/services/configuration.service.ts b/libs/core/settings/services/configuration.service.ts index c6786aaca6..12932b98f6 100644 --- a/libs/core/settings/services/configuration.service.ts +++ b/libs/core/settings/services/configuration.service.ts @@ -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" @@ -20,7 +23,7 @@ export interface getNewConfigurationParams { } export class ConfigurationService { - private instance: Axios + private instance: BaseHttpClientService private defaultConfiguration: Configuration = defaultConfiguration as unknown as Configuration @@ -52,7 +55,7 @@ export class ConfigurationService { private async getNewConfiguration( params: getNewConfigurationParams - ): Promise> { + ): Promise> { return this.instance.get( MuditaCenterServerRoutes.AppConfigurationV2, { From 570d035b16e54db327409cf1571e1ec8344c720e Mon Sep 17 00:00:00 2001 From: robertmudi Date: Thu, 12 Dec 2024 09:42:14 +0100 Subject: [PATCH 07/11] CP-2931 added helper - mock-prebackup.ts, removed prebackup mock from mock-descriptors, updated test to use the added helper instead of writing it in mockdescriptor or inside the test --- .../src/helpers/mock-prebackup.ts | 32 +++++++++++++++++++ .../specs/overview/kompakt-prebackup-api.ts | 6 ++++ .../lib/mock-descriptor/mock-descriptor.ts | 30 ----------------- 3 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 apps/mudita-center-e2e/src/helpers/mock-prebackup.ts diff --git a/apps/mudita-center-e2e/src/helpers/mock-prebackup.ts b/apps/mudita-center-e2e/src/helpers/mock-prebackup.ts new file mode 100644 index 0000000000..dddabbb9e8 --- /dev/null +++ b/apps/mudita-center-e2e/src/helpers/mock-prebackup.ts @@ -0,0 +1,32 @@ +import { E2EMockClient } from "../../../../libs/e2e-mock/client/src" + +// Helper function to mock PRE_BACKUP responses +export function mockPreBackupResponses(path: string, backupId: number) { + // Mock initial PRE_BACKUP response with status 202 (processing) + E2EMockClient.mockResponse({ + path, + endpoint: "PRE_BACKUP", + method: "POST", + status: 202, + body: { + backupId, + }, + }) + + // 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) +} diff --git a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts index 3e8621fdce..033ed12570 100644 --- a/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts +++ b/apps/mudita-center-e2e/src/specs/overview/kompakt-prebackup-api.ts @@ -4,6 +4,7 @@ import { 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 () => { @@ -46,6 +47,11 @@ describe("E2E mock sample - overview view", () => { await expect(menuItem).toBeDisplayed() }) + it("Mock Pre-Backup Responses", async () => { + // Use the helper function to mock PRE_BACKUP responses (so the backup process will be progressing) + mockPreBackupResponses("path-1", 12345) + }) + it("Wait for Overview Page and click Create Backup", async () => { const createBackupButton = await ModalBackupKompaktPage.createBackupButton await expect(createBackupButton).toBeDisplayed() diff --git a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts index 785344f3f1..9c376ea158 100644 --- a/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts +++ b/libs/e2e-mock/server/src/lib/mock-descriptor/mock-descriptor.ts @@ -87,36 +87,6 @@ class MockDescriptor { }, } } - // Add method for mocking PRE_BACKUP responses - public mockPreBackupResponses(path: string, backupId: number) { - // Mock initial PRE_BACKUP response with status 202 (processing) - this.addResponse({ - path, - endpoint: "PRE_BACKUP", - method: "POST", - status: 202, - body: { - backupId, - }, - }) - - // After 10 seconds, update the response to status 200 (completed) - setTimeout(() => { - this.addResponse({ - 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) - } public removeResponses({ path, requests }: RestoreDefaultResponses) { requests?.forEach((request) => { From d2b15d98022547bd77143fc448e32c69f3090f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kurczewski?= Date: Thu, 12 Dec 2024 10:11:48 +0100 Subject: [PATCH 08/11] [CP-3192] Improved form implementation for contacts import list (#2226) --- libs/generic-view/models/src/lib/form.ts | 1 - .../ui/src/lib/generated/mc-contacts-view.ts | 5 --- .../interactive/form/input/checkbox-input.tsx | 13 ++++--- .../import-contacts/import-contacts-list.tsx | 35 +++---------------- .../import-contacts/import-contacts.tsx | 11 +++++- 5 files changed, 23 insertions(+), 42 deletions(-) diff --git a/libs/generic-view/models/src/lib/form.ts b/libs/generic-view/models/src/lib/form.ts index 1c4901b526..dac1c2057c 100644 --- a/libs/generic-view/models/src/lib/form.ts +++ b/libs/generic-view/models/src/lib/form.ts @@ -22,7 +22,6 @@ const configValidator: z.ZodType = z reValidateMode: z.enum(["onChange", "onBlur", "onSubmit"]).optional(), defaultValues: z.record(z.string(), z.any()).optional(), }), - defaultValues: z.record(z.string(), z.any()).optional(), }) .optional() diff --git a/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts b/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts index a9eed190b2..820243649e 100644 --- a/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts +++ b/libs/generic-view/ui/src/lib/generated/mc-contacts-view.ts @@ -36,11 +36,6 @@ export const generateMcContactsView: ComponentGenerator = ( activeContactId: null, }, }, - defaultValues: { - selectedContacts: [], - allContacts: [], - searchedContact: "", - }, }, childrenKeys: ["contactsLoader"], }, diff --git a/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx b/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx index 728a497335..72b1df1f3a 100644 --- a/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx +++ b/libs/generic-view/ui/src/lib/interactive/form/input/checkbox-input.tsx @@ -77,6 +77,14 @@ export const CheckboxInput: APIFC = ({ [config, fieldRegistrar, getValues, inputName, multiSelect, setValue] ) + const handleRef = useCallback( + (e: HTMLInputElement) => { + inputRef.current = e + fieldRegistrar.ref(e) + }, + [fieldRegistrar] + ) + useEffect(() => { if (multiSelect) { if (multiSelect.selectedValues.length === multiSelect.allValues.length) { @@ -108,10 +116,7 @@ export const CheckboxInput: APIFC = ({ disabled={config.disabled} {...fieldRegistrar} onChange={handleChange} - ref={(e) => { - inputRef.current = e - fieldRegistrar.ref(e) - }} + ref={handleRef} />