Skip to content

Commit

Permalink
chore: add refactored files for updated reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Pettedson John committed Apr 29, 2024
1 parent f743be0 commit ba89b35
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
11 changes: 7 additions & 4 deletions functional-test/fixtures/steps/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, Locator, Page } from '@playwright/test';
import { HomePage } from '../../pages/homePage';
import { AddNotePage } from '../../pages/addNotePage';
import { LoginPage } from '../../pages/loginPage';
import setUpData from "../../helpers/dataSetUpHelper";
import createCaseBasedOnCaseType from "../../helpers/dataSetUpHelper";
const addNoteTestConfig = require('../../data/uiJsonTestData/add-note.json');
const eventTestConfig = require('../../data/uiJsonTestData/event-name.json');

Expand All @@ -21,17 +21,20 @@ export class Note {
let homePage = new HomePage(this.page);
let addNotePage = new AddNotePage(this.page);

var pipCaseId = await setUpData("PIP");
var pipCaseId = await createCaseBasedOnCaseType("PIP");
await loginPage.goToLoginPage();
await loginPage.verifySuccessfulLoginForCaseworker('Case list');

await homePage.goToHomePage(pipCaseId);
await homePage.chooseEvent(eventTestConfig.addNoteEvent);
await addNotePage.submitNote(addNoteTestConfig.noteSummaryValue);

await addNotePage.verifyPageContent();
await addNotePage.inputData(addNoteTestConfig.noteSummaryValue);
await addNotePage.confirmSubmission();
await addNotePage.confirmSubmission();

await homePage.verifyTabContent(addNoteTestConfig.noteFieldValue, addNoteTestConfig.noteSummaryValue);
}


}
}
13 changes: 5 additions & 8 deletions functional-test/helpers/dataSetUpHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ import piprepFtoFSandLPayload from '../data/apiJsonTestData/pip_sandl_rep_ftof.j
import piprepSandLPayload from '../data/apiJsonTestData/pip_sandl_rep.json';


async function setUpData(caseType: string) {
async function createCaseBasedOnCaseType(caseType: string) {
let apiContext;
let dataPayload;
// create new test data

//Formulate API Context For Request,wrapping the Request Endpoint
apiContext = await request.newContext({
// All requests we send go to this API endpoint.
// All requests we send go to this API Endpoint.
baseURL: urls.tribunalsApiUri,
});

console.log('creating new test data...');

dataPayload =
caseType == "PIP"
? pipPayload
Expand Down Expand Up @@ -57,8 +56,6 @@ async function setUpData(caseType: string) {
let caseId = locationUrl.substring(locationUrl.lastIndexOf('/') + 1);
console.log(`Case id is ${caseId}`);
return caseId;


}

export default setUpData;
export default createCaseBasedOnCaseType;
20 changes: 16 additions & 4 deletions functional-test/lib/webActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ export class WebActions {
this.page = page;
}

async chooseOptionByLabel(elementId: string, labelText: string) {
this.page.locator(elementId).selectOption({label: labelText});
async chooseOptionByLabel(elementLocator: string, labelText: string) {
await this.page.locator(elementLocator).selectOption({label: labelText});
}

async verifyPageLabel(elementLocator: string, labelText: string) {
await expect(this.page.locator(elementLocator)).toHaveText(labelText);
}

async inputField (elementLocator: string, inputValue: string) {
await this.page.fill(elementLocator, inputValue);
}

async clickButton(elementLocator: string): Promise<void> {
await this.page.click(elementLocator);
}

async clickNextStepButton(elementId: string): Promise<void> {
this.page.click(elementId);
await this.page.click(elementId);
}
}
}
32 changes: 19 additions & 13 deletions functional-test/pages/addNotePage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, Locator, Page } from '@playwright/test';
import { WebActions } from '../lib/webActions'
import {expect, Locator, Page} from '@playwright/test';
import {WebActions} from '../lib/webActions'

let webActions: WebActions;

Expand All @@ -8,24 +8,30 @@ export class AddNotePage {
readonly page: Page;
readonly textDetailsField: Locator;
readonly submitButton: Locator;


constructor(page: Page) {
this.page = page;
this.textDetailsField = page.locator('#tempNoteDetail');
this.submitButton = page.getByRole('button', {name: 'Submit'});
/*this.textDetailsField = page.locator('#tempNoteDetail');
this.submitButton = page.getByRole('button', {name: 'Submit'});*/

webActions = new WebActions(this.page);

}

async submitNote(noteSummary: string): Promise<void> {
await this.textDetailsField.fill(noteSummary);
await this.submitButton.click();
async verifyPageContent() {
await webActions.verifyPageLabel('.govuk-caption-l', 'Add a note'); //Captor Text
await webActions.verifyPageLabel('.govuk-heading-l', 'Add a case note'); //Heading Text
await webActions.verifyPageLabel('.form-label', 'Enter note'); //Field Label
}

x
async inputData(elementData: string): Promise<void> {
await webActions.inputField('#tempNoteDetail', elementData);
}

async confirmSubmission(): Promise<void> {
await this.submitButton.click();
await webActions.clickButton('[type=\'submit\']');
}
}

}
16 changes: 7 additions & 9 deletions functional-test/pages/homePage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, Locator, Page } from '@playwright/test';
import { WebActions } from '../lib/webActions'
import {expect, Locator, Page} from '@playwright/test';
import {WebActions} from '../lib/webActions'

let webActions: WebActions;

Expand All @@ -11,8 +11,8 @@ export class HomePage {
readonly submitNextStepButton: string;
readonly nextStepDropDown: string;
readonly eventTitle: Locator;


constructor(page: Page) {
this.page = page;
this.summaryTab = page.locator('//div[contains(text(), "Summary")]');
Expand Down Expand Up @@ -40,10 +40,8 @@ export class HomePage {
async verifyTabContent(fieldLabel: string, fieldValue: string): Promise<void> {
await expect(this.notePadTab).toBeVisible();
await this.notePadTab.click();
let noteSummaryField = await this.page
.locator(`//*[normalize-space()="${fieldLabel}"]/../..//td[normalize-space()="${fieldValue}"]`);
await expect(this.page
.locator(`//*[normalize-space()="${fieldLabel}"]/../..//td[normalize-space()="${fieldValue}"]`)).toBeVisible();

await expect(noteSummaryField).toBeVisible();
}

}
}

0 comments on commit ba89b35

Please sign in to comment.