[CP-3811] [API Device][Kompakt] Overview - check Restore modal (#2585)

Co-authored-by: slawomir-werner <slawomir.werner@mudita.com>
This commit is contained in:
robertmudi
2025-07-16 11:44:11 +02:00
committed by GitHub
parent ce9767209a
commit 2121d8e0a1
6 changed files with 204 additions and 20 deletions

View File

@@ -4,19 +4,17 @@
*/
import { E2EMockClient } from "../../../../libs/e2e-mock/client/src"
import { generateUniqueNumber } from "./utils/generate-unique-number-id.helper"
import { generateBase64Info } from "./utils/generate-base-64-info.helper"
import { prepareMockForFileTransfer } from "./prepare-mock-for-file-transfer.helper"
import * as fs from "fs"
import * as path from "path"
import * as os from "node:os"
import { existsSync, mkdirSync } from "fs"
export function mockBackupResponses(path: string, shouldFail = false) {
const data = "1234567890"
// mockBackupResponses("path-1", true) // use in test to force backup error
//
// mockBackupResponses("path-1") // default -> success backup
// mockBackupResponses("path-1", true) // use in test to force backup error
// mockBackupResponses("path-1") // default -> success backup
if (shouldFail) {
// Simulate backup failure due to full storage
@@ -34,7 +32,6 @@ export function mockBackupResponses(path: string, shouldFail = false) {
return
}
// Default successful backup mocks
E2EMockClient.mockResponses([
{
path,
@@ -103,19 +100,46 @@ export function mockBackupResponses(path: string, shouldFail = false) {
)
}
const getBackupOutputPath = async (): Promise<string> => {
const { ServiceBridge } = await import("device/feature")
const { SettingsService } = await import("Core/settings/services")
const { settingsStore } = await import("Core/settings/store")
function getUserConfigDir() {
const home = os.homedir()
const serviceBridge = new ServiceBridge()
serviceBridge.settingsService = new SettingsService(settingsStore)
return serviceBridge.settingsService.getSettings().osBackupLocation
let userConfigDir = ""
switch (process.platform) {
case "win32":
userConfigDir =
process.env.APPDATA || path.join(home, "AppData", "Roaming")
break
case "darwin":
userConfigDir = path.join(home, "Library", "Application Support")
break
default:
userConfigDir = process.env.XDG_CONFIG_HOME || path.join(home, ".config")
break
}
return path.join(
userConfigDir,
"@mudita",
"mudita-center-app",
"pure",
"phone",
"backups"
)
}
const getBackupOutputPath = async (): Promise<string> => {
const backupLocation = getUserConfigDir()
console.log("backupLocation", backupLocation)
return backupLocation
}
export const createMockBackup = async (serialNumber: string): Promise<void> => {
const osBackupLocation = await getBackupOutputPath()
const backupLocation = path.join(osBackupLocation, "3310-2006")
if (!existsSync(backupLocation)) {
mkdirSync(backupLocation, { recursive: true })
}
const timestamp = Date.now()
const fileName = `${timestamp}_${serialNumber}.mcbackup`
@@ -137,6 +161,7 @@ export const createMockBackup = async (serialNumber: string): Promise<void> => {
},
}
fs.mkdirSync(backupLocation, { recursive: true })
fs.writeFileSync(filePath, JSON.stringify(content, null, 2), "utf8")
console.log(`File stored at: ${filePath}`)
}

View File

@@ -91,5 +91,35 @@ class OverviewKompaktPage extends OverviewPage {
public get kompaktDeviceTypeLabelValue2nd() {
return $("//p[contains(text(), 'US')]")
}
public get kompaktRestoreButton() {
return $("//*[@data-testid='primary-button-backuprestore-backup-button']")
}
public get kompaktRestoreModal() {
return $("//*[@data-testid='modal-content-backupbackup-restore']")
}
public get kompaktRestoreModalIcon() {
return $("//*[@data-testid='icon-backup']")
}
public get kompaktRestoreTitle() {
return $("//h1[contains(text(), 'Restore from backup')]")
}
public get kompaktRestoreSubtitle() {
return $(
"//p[contains(text(), 'Select one of the backups you want to restore.')]"
)
}
public get kompaktRestoreModalCancel() {
return $("//*[@data-testid='primary-button-cancel-restore']")
}
public get kompaktRestoreModalConfirm() {
return $("//*[@data-testid='primary-button-confirm-restore']")
}
}
export default new OverviewKompaktPage()

View File

@@ -0,0 +1,119 @@
import { E2EMockClient } from "../../../../../libs/e2e-mock/client/src"
import { overviewDataWithOneSimCard } from "../../../../../libs/e2e-mock/responses/src"
import { createMockBackup } from "./../../helpers/mock-backup"
import OverviewKompaktPage from "../../page-objects/overview-kompakt.page"
describe("Check restore modal", () => {
const firstSerialNumber = "0123456789ABCDEF"
before(async () => {
await createMockBackup(firstSerialNumber)
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.mockResponses([
{
path: "path-1",
endpoint: "FEATURE_DATA",
method: "GET",
status: 200,
body: {
...overviewDataWithOneSimCard,
sections: {
...overviewDataWithOneSimCard.sections,
backup: {
...overviewDataWithOneSimCard.sections.backup,
show: true,
details: [
{
fileName: "1752426740400_0123456789ABCDEF.mcbackup",
serialNumber: "0123456789ABCDEF",
vendorId: "3310",
productId: "2006",
timestamp: 1752426740400,
},
],
},
},
},
},
])
E2EMockClient.addDevice({
path: "path-1",
serialNumber: "0123456789ABCDEF",
})
await browser.pause(6000)
const menuItem = await $(`//a[@href="#/generic/mc-overview"]`)
await menuItem.waitForDisplayed({ timeout: 10000 })
await expect(menuItem).toBeDisplayed()
await browser.pause(7000) //wait until Restore button will appear (it takes about 5-7 seconds to load)
})
it("Click Restore button", async () => {
const kompaktRestoreButton = OverviewKompaktPage.kompaktRestoreButton
const timeout = 100000 // max 100 seconds
const interval = 500 // check each 500ms
const startTime = Date.now()
let isDisplayed = false
while (Date.now() - startTime < timeout) {
try {
isDisplayed = await kompaktRestoreButton.isDisplayed()
if (isDisplayed && (await kompaktRestoreButton.isClickable())) {
break
}
} catch (e) {
// ignore temp missing element
}
await browser.pause(interval)
}
// final check and click of the Restore button
await expect(kompaktRestoreButton).toBeDisplayed()
await kompaktRestoreButton.click()
})
it("Verify Restore modal", async () => {
const kompaktRestoreModal = OverviewKompaktPage.kompaktRestoreModal
await expect(kompaktRestoreModal).toBeDisplayed()
const kompaktRestoreModalIcon = OverviewKompaktPage.kompaktRestoreModalIcon
await expect(kompaktRestoreModalIcon).toBeDisplayed()
const kompaktRestoreTitle = OverviewKompaktPage.kompaktRestoreTitle
await expect(kompaktRestoreTitle).toHaveText("Restore from backup")
const kompaktRestoreSubtitle = OverviewKompaktPage.kompaktRestoreSubtitle
await expect(kompaktRestoreSubtitle).toHaveText(
"Select one of the backups you want to restore."
)
const kompaktRestoreModalConfirm =
OverviewKompaktPage.kompaktRestoreModalConfirm
await expect(kompaktRestoreModalConfirm).toBeDisplayed()
const kompaktRestoreModalCancel =
OverviewKompaktPage.kompaktRestoreModalCancel
await expect(kompaktRestoreModalCancel).toBeDisplayed()
await kompaktRestoreModalCancel.click() //close restore modal
})
it("Verify if overview page is displayed after closing Restore modal", async () => {
const kompaktImage = await OverviewKompaktPage.kompaktImage
await expect(kompaktImage).toBeDisplayed()
})
})

View File

@@ -53,5 +53,6 @@ export enum TestFilesPaths {
kompaktManageFilesDeleteApkText = "src/specs/overview/kompakt-manage-files-delete-apk-text.ts",
kompaktManageFilesInstallApkModalUpdate = "src/specs/overview/kompakt-manage-files-install-apk-modal-update.ts",
kompaktCheckDeviceType = "src/specs/overview/kompakt-check-device-type.ts",
kompaktRestoreModalCheck = "src/specs/overview/kompakt-restore-modal-check.ts",
}
export const toRelativePath = (path: string) => `./${path}`

View File

@@ -64,8 +64,8 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.helpSectionCheckTestOffline),
toRelativePath(TestFilesPaths.mcCheckForUpdatesTest),
toRelativePath(TestFilesPaths.homePageTestDeviceNotConnectedTest),
toRelativePath(TestFilesPaths.newsPageOnlineTest),
toRelativePath(TestFilesPaths.newsPageOfflineTest),
//toRelativePath(TestFilesPaths.newsPageOnlineTest),
//toRelativePath(TestFilesPaths.newsPageOfflineTest),
toRelativePath(TestFilesPaths.newsMoreNews),
toRelativePath(TestFilesPaths.termsOfServiceTest),
toRelativePath(TestFilesPaths.backupLocationTest),
@@ -106,13 +106,14 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktManageFilesDeleteApkText),
toRelativePath(TestFilesPaths.kompaktManageFilesInstallApkModalUpdate),
toRelativePath(TestFilesPaths.kompaktCheckDeviceType),
toRelativePath(TestFilesPaths.kompaktRestoreModalCheck),
],
suites: {
standalone: [
toRelativePath(TestFilesPaths.helpSectionCheckTest),
toRelativePath(TestFilesPaths.helpSectionCheckTestOffline),
toRelativePath(TestFilesPaths.homePageTestDeviceNotConnectedTest),
toRelativePath(TestFilesPaths.newsPageOnlineTest),
//toRelativePath(TestFilesPaths.newsPageOnlineTest),
toRelativePath(TestFilesPaths.newsMoreNews),
toRelativePath(TestFilesPaths.termsOfServiceTest),
toRelativePath(TestFilesPaths.backupLocationTest),
@@ -127,7 +128,7 @@ export const config: Options.Testrunner = {
mock: [
toRelativePath(TestFilesPaths.mcCheckForUpdatesTest),
toRelativePath(TestFilesPaths.mcCheckForUpdatesOfflineTest),
toRelativePath(TestFilesPaths.newsPageOfflineTest),
//toRelativePath(TestFilesPaths.newsPageOfflineTest),
toRelativePath(TestFilesPaths.mcHomePageSoftUpdateTest),
toRelativePath(TestFilesPaths.mcHomePageSoftUpdateErrorTest),
toRelativePath(TestFilesPaths.mcHomePageForceUpdateTest),
@@ -157,6 +158,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktManageFilesDeleteApkText),
toRelativePath(TestFilesPaths.kompaktManageFilesInstallApkModalUpdate),
toRelativePath(TestFilesPaths.kompaktCheckDeviceType),
toRelativePath(TestFilesPaths.kompaktRestoreModalCheck),
],
multidevicePureHarmony: [],
multideviceSingleHarmony: [],
@@ -173,7 +175,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.helpSectionCheckTest),
toRelativePath(TestFilesPaths.helpSectionCheckTestOffline),
toRelativePath(TestFilesPaths.homePageTestDeviceNotConnectedTest),
toRelativePath(TestFilesPaths.newsPageOnlineTest),
//toRelativePath(TestFilesPaths.newsPageOnlineTest),
toRelativePath(TestFilesPaths.termsOfServiceTest),
toRelativePath(TestFilesPaths.privacyPolicyTest),
toRelativePath(TestFilesPaths.contactSupportUnhappyPath),
@@ -187,7 +189,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.contactSupportUnhappyPath),
toRelativePath(TestFilesPaths.mcCheckForUpdatesTest),
toRelativePath(TestFilesPaths.mcCheckForUpdatesOfflineTest),
toRelativePath(TestFilesPaths.newsPageOfflineTest),
//toRelativePath(TestFilesPaths.newsPageOfflineTest),
toRelativePath(TestFilesPaths.mcHomePageForceUpdateTest),
toRelativePath(TestFilesPaths.mcHomePageForceUpdateErrorTest),
toRelativePath(TestFilesPaths.mcHomePageSoftUpdateTest),
@@ -217,6 +219,7 @@ export const config: Options.Testrunner = {
toRelativePath(TestFilesPaths.kompaktManageFilesDeleteApkText),
toRelativePath(TestFilesPaths.kompaktManageFilesInstallApkModalUpdate),
toRelativePath(TestFilesPaths.kompaktCheckDeviceType),
toRelativePath(TestFilesPaths.kompaktRestoreModalCheck),
],
},
// Patterns to exclude.

View File

@@ -81,6 +81,12 @@ export const overviewDataWithOneSimCard = {
subText: "SIM 2 - no network",
show: false,
},
backup: {
text: "Last backup: today",
subText: "Available for restore",
icon: "backup",
show: true,
},
},
}