-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from matterway/feat/navigate-and-create-entries
Feat/navigate and create entries
- Loading branch information
Showing
12 changed files
with
196 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
// Keep shared selectors here, | ||
export const SELECTORS = {}; | ||
|
||
/** | ||
* @example | ||
* | ||
* export const SELECTORS = { | ||
* loader: { | ||
* materialNumberLabel: '#userarea-scrl-cnt > div > div:first-child label span', | ||
* materialNumberInput: 'input[title="Material Number"]', | ||
* }, | ||
* xPurchDocTableCell: '//table//tr//span[text()="Purch.Doc."]', | ||
* xCurrencyInput: '//span[contains(text(), "Targ. Val.")]//following::input[2]', | ||
* xTranslatedSpan: (title: string) => `//span[contains(text(), ${title}`, | ||
* }; | ||
*/ | ||
export const SELECTORS = { | ||
navigateToProjectManagement: { | ||
projects: 'span[title="Projects"]', | ||
xAddRecordsBtn: '//a[contains(text(), "Add record")]', | ||
}, | ||
createEntries: { | ||
projectName: '[name="projectname"]', | ||
startDate: '[name="startdate"]', | ||
targetEndDate: '[name="targetenddate"]', | ||
budget: '[name="targetbudget"]', | ||
xSaveBtn: '//button//*[contains(text(), "Save")]', | ||
xProjectsBreadcrumb: | ||
'//li[@class="breadcrumb-item u-text-ellipsis"]//a[contains(text(), "Projects")]', | ||
}, | ||
highlightCreatedEntries: { | ||
xProjectName: (projectName: string) => | ||
`//table[contains(@class, 'listViewActive')]//a[contains(text(), "${projectName}")]`, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import type {Context} from '@matterway/sdk'; | ||
import {showSuccessNotice} from '@matterway/sdk'; | ||
import {highlightXPath, showSuccessNotice} from '@matterway/sdk'; | ||
import {t} from 'i18next'; | ||
import manifest from 'manifest.json'; | ||
|
||
// You can duplicate this step to represent different endings for this task | ||
// which are not "technical errors", such as "could not find the material". | ||
|
||
export async function successStep(ctx: Context) { | ||
export async function successStep(ctx: Context, highlights: string[]) { | ||
console.log('step: successStep'); | ||
|
||
// Only add logic here if it is performing closure specific to this ending | ||
|
||
await showSuccessNotice(ctx, { | ||
title: manifest.name, | ||
description: manifest.description, | ||
title: '', | ||
description: '', | ||
text: '', | ||
subtitle: t('success.subtitle'), | ||
text: t('success.text'), | ||
icon: 'checkmark-circle-outline', | ||
}); | ||
|
||
await Promise.all( | ||
highlights.map((highlight) => { | ||
return highlightXPath(ctx, highlight).stop(); | ||
}), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
clickByXPath, | ||
fill, | ||
waitForSelector, | ||
type Context, | ||
setValue, | ||
showProgress, | ||
} from '@matterway/sdk'; | ||
import {SELECTORS} from 'shared/selectors'; | ||
import {Entry} from 'shared/types'; | ||
import dayjs from 'dayjs'; | ||
import {t} from 'i18next'; | ||
import {isEmpty} from 'lodash-es'; | ||
|
||
export async function createEntriesStep(ctx: Context, excelData: Entry[]) { | ||
console.log('step: createEntriesStep', excelData); | ||
await showProgress(ctx, t('progress.createData')); | ||
|
||
const { | ||
navigateToProjectManagement: {xAddRecordsBtn}, | ||
createEntries: { | ||
projectName, | ||
startDate, | ||
targetEndDate, | ||
budget, | ||
xSaveBtn, | ||
xProjectsBreadcrumb, | ||
}, | ||
} = SELECTORS; | ||
|
||
if (excelData.length > 0) { | ||
for (const entry of excelData) { | ||
if (isEmpty(entry.projectName)) { | ||
continue; | ||
} | ||
|
||
const formattedDate = dayjs(entry.startDate).format('YYYY-MM-DD'); | ||
const formattedEndDate = dayjs(entry.targetEndDate).format('YYYY-MM-DD'); | ||
|
||
await clickByXPath(ctx, xAddRecordsBtn); | ||
await showProgress(ctx, t('progress.createData')); | ||
await waitForSelector(ctx, projectName); | ||
await fill(ctx, projectName, entry.projectName); | ||
await setValue(ctx, startDate, formattedDate); | ||
await setValue(ctx, targetEndDate, formattedEndDate); | ||
await fill(ctx, budget, String(entry.budget)); | ||
await clickByXPath(ctx, xSaveBtn); | ||
await showProgress(ctx, t('progress.createData')); | ||
await clickByXPath(ctx, xProjectsBreadcrumb); | ||
await showProgress(ctx, t('progress.createData')); | ||
} | ||
} | ||
|
||
console.log('step: createEntriesStep end'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {highlightXPath, type Context} from '@matterway/sdk'; | ||
import {isEmpty} from 'lodash-es'; | ||
import {SELECTORS} from 'shared/selectors'; | ||
import {Entry} from 'shared/types'; | ||
|
||
export async function highlightCreatedEntriesStep( | ||
ctx: Context, | ||
excelData: Entry[], | ||
) { | ||
console.log('step: highlightCreatedEntriesStep', {excelData}); | ||
const { | ||
highlightCreatedEntries: {xProjectName}, | ||
} = SELECTORS; | ||
|
||
const highlightedPromises = []; | ||
|
||
if (excelData.length > 0) { | ||
for (const entry of excelData) { | ||
if (isEmpty(entry.projectName)) { | ||
continue; | ||
} | ||
|
||
const tableElements = await ctx.page.$x(xProjectName(entry.projectName)); | ||
|
||
if (tableElements.length > 1) { | ||
for (let i = 1; i <= tableElements.length; i++) { | ||
highlightedPromises.push( | ||
`(${xProjectName(entry.projectName)})[${i}]`, | ||
); | ||
} | ||
} else { | ||
highlightedPromises.push(xProjectName(entry.projectName)); | ||
} | ||
} | ||
} | ||
|
||
await Promise.all( | ||
highlightedPromises.map((selector) => { | ||
return highlightXPath(ctx, selector); | ||
}), | ||
); | ||
|
||
console.log('step: highlightCreatedEntriesStep end'); | ||
return highlightedPromises; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {click, showProgress, waitForXPath, type Context} from '@matterway/sdk'; | ||
import {t} from 'i18next'; | ||
import {SELECTORS} from 'shared/selectors'; | ||
|
||
export async function navigateToProjectManagementStep(ctx: Context) { | ||
console.log('step: navigateToProjectManagementStep'); | ||
await showProgress(ctx, t('progress.createData')); | ||
|
||
const {projects, xAddRecordsBtn} = SELECTORS.navigateToProjectManagement; | ||
|
||
await click(ctx, projects); | ||
await waitForXPath(ctx, xAddRecordsBtn); | ||
|
||
console.log('step: navigateToProjectManagementStep end'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters