Skip to content

Commit c6a0970

Browse files
committed
Added the Playwright tests for TextInput, added a couple of tests to the unit tests,and updated the folder structure
1 parent 23a63f2 commit c6a0970

File tree

9 files changed

+179
-16
lines changed

9 files changed

+179
-16
lines changed

packages/react-sdk-components/tests/e2e/Digv2/CaseReference.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/CaseReference.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-undef */
33

44
const { test, expect } = require('@playwright/test');
5-
const config = require('../../config');
6-
const common = require('../../common');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
77

88
test.beforeEach(async ({ page }) => {
99
await page.goto('http://localhost:3502/portal');

packages/react-sdk-components/tests/e2e/Digv2/CaseView.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/CaseView.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/** We're testing the visibility of tabs within the Case Summary area in the Case View here, more tests to be added in the future. */
55

66
const { test, expect } = require('@playwright/test');
7-
const config = require('../../config');
8-
const common = require('../../common');
7+
const config = require('../../../config');
8+
const common = require('../../../common');
99

1010
// These values represent the visibility(as authored in the app) of the tabs
1111
const detailsTabVisible = false;

packages/react-sdk-components/tests/e2e/Digv2/DataReference.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/DataReference.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-undef */
33

44
const { test, expect } = require('@playwright/test');
5-
const config = require('../../config');
6-
const common = require('../../common');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
77

88
test.beforeEach(async ({ page }) => {
99
await page.goto('http://localhost:3502/portal');

packages/react-sdk-components/tests/e2e/Digv2/EmbeddedData.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/EmbeddedData.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-undef */
33

44
const { test, expect } = require('@playwright/test');
5-
const config = require('../../config');
6-
const common = require('../../common');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
77

88
test.beforeEach(async ({ page }) => {
99
await page.setViewportSize({ width: 1720, height: 1080 });

packages/react-sdk-components/tests/e2e/Digv2/Query.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/Query.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-undef */
22
const { test, expect } = require('@playwright/test');
3-
const config = require('../../config');
4-
const common = require('../../common');
3+
const config = require('../../../config');
4+
const common = require('../../../common');
55

66
test.beforeEach(async ({ page }) => {
77
await page.setViewportSize({ width: 1720, height: 1080 });

packages/react-sdk-components/tests/e2e/Digv2/UserReference.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ComplexFields/UserReference.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-undef */
33

44
const { test, expect } = require('@playwright/test');
5-
const config = require('../../config');
6-
const common = require('../../common');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
77

88
test.beforeEach(async ({ page }) => {
99
await page.setViewportSize({ width: 1720, height: 1080 });
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/* eslint-disable no-template-curly-in-string */
2+
/* eslint-disable no-undef */
3+
4+
const { test, expect } = require('@playwright/test');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
7+
8+
// These values represent the data values used for the conditions and are initialised in pyDefault DT
9+
const isDisabled = true;
10+
const isVisible = true;
11+
12+
test.beforeEach(async ({ page }) => {
13+
await page.setViewportSize({ width: 1720, height: 1080 });
14+
await page.goto('http://localhost:3502/portal');
15+
});
16+
17+
test.describe('E2E test', () => {
18+
let attributes;
19+
20+
test('should login, create case and run the Text Input tests', async ({ page }) => {
21+
await common.Login(
22+
config.config.apps.digv2.user.username,
23+
config.config.apps.digv2.user.password,
24+
page
25+
);
26+
27+
/** Testing announcement banner presence */
28+
const announcementBanner = page.locator('h6:has-text("Announcements")');
29+
await expect(announcementBanner).toBeVisible();
30+
31+
/** Testing worklist presence */
32+
const worklist = page.locator('h6:has-text("My Worklist")');
33+
await expect(worklist).toBeVisible();
34+
35+
/** Creating a Form Field case-type */
36+
const complexFieldsCase = page.locator('div[role="button"]:has-text("Form Field")');
37+
await complexFieldsCase.click();
38+
39+
/** Selecting Text Input from the Category dropdown */
40+
const selectedCategory = page.locator('div[data-test-id="76729937a5eb6b0fd88c42581161facd"]');
41+
await selectedCategory.click();
42+
await page.getByRole('option', { name: 'TextInput' }).click();
43+
44+
/** Selecting Required from the Sub Category dropdown */
45+
let selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
46+
await selectedSubCategory.click();
47+
await page.getByRole('option', { name: 'Required' }).click();
48+
49+
/** Required tests */
50+
const requiredTextInput = page.locator(
51+
'input[data-test-id="6d83ba2ad05ae97a2c75e903e6f8a660"]'
52+
);
53+
attributes = await common.getAttributes(requiredTextInput);
54+
await expect(attributes.includes('required')).toBeTruthy();
55+
56+
const notRequiredTextInput = page.locator(
57+
'input[data-test-id="206bc0200017cc475d88b1bf4279cda0"]'
58+
);
59+
attributes = await common.getAttributes(notRequiredTextInput);
60+
await expect(attributes.includes('required')).toBeFalsy();
61+
62+
/** Selecting Disable from the Sub Category dropdown */
63+
selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
64+
await selectedSubCategory.click();
65+
await page.getByRole('option', { name: 'Disable' }).click();
66+
67+
// /** Disable tests */
68+
const alwaysDisabledTextInput = page.locator(
69+
'input[data-test-id="52ad9e3ceacdb9ccea7ca193c213228a"]'
70+
);
71+
attributes = await common.getAttributes(alwaysDisabledTextInput);
72+
await expect(attributes.includes('disabled')).toBeTruthy();
73+
74+
const conditionallyDisabledTextInput = page.locator(
75+
'input[data-test-id="9fd3c38fdf5de68aaa56e298a8c89587"]'
76+
);
77+
attributes = await common.getAttributes(conditionallyDisabledTextInput);
78+
if (isDisabled) {
79+
await expect(attributes.includes('disabled')).toBeTruthy();
80+
} else {
81+
await expect(attributes.includes('disabled')).toBeFalsy();
82+
}
83+
84+
const neverDisabledTextInput = page.locator(
85+
'input[data-test-id="0aac4de2a6b79dd12ef91c6f16708533"]'
86+
);
87+
attributes = await common.getAttributes(neverDisabledTextInput);
88+
await expect(attributes.includes('disabled')).toBeFalsy();
89+
90+
/** Selecting Update from the Sub Category dropdown */
91+
selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
92+
await selectedSubCategory.click();
93+
await page.getByRole('option', { name: 'Update' }).click();
94+
95+
/** Update tests */
96+
const readonlyTextInput = page.locator(
97+
'input[data-test-id="2fff66b4f045e02eab5826ba25608807"]'
98+
);
99+
attributes = await common.getAttributes(readonlyTextInput);
100+
await expect(attributes.includes('readonly')).toBeTruthy();
101+
102+
const EditableTextInput = page.locator(
103+
'input[data-test-id="95134a02d891264bca28c3aad682afb7"]'
104+
);
105+
attributes = await common.getAttributes(EditableTextInput);
106+
await expect(attributes.includes('readonly')).toBeFalsy();
107+
108+
/** Selecting Visibility from the Sub Category dropdown */
109+
selectedSubCategory = page.locator('div[data-test-id="9463d5f18a8924b3200b56efaad63bda"]');
110+
await selectedSubCategory.click();
111+
await page.getByRole('option', { name: 'Visibility' }).click();
112+
113+
/** Visibility tests */
114+
await expect(
115+
page.locator('input[data-test-id="a03145775f20271d9f1276b0959d0b8e"]')
116+
).toBeVisible();
117+
118+
const neverVisibleTextInput = await page.locator(
119+
'input[data-test-id="05bf85e34402515bd91335928c06117d"]'
120+
);
121+
await expect(neverVisibleTextInput).not.toBeVisible();
122+
123+
const conditionallyVisibleTextInput = await page.locator(
124+
'input[data-test-id="d4b374793638017e2ec1b86c81bb1208"]'
125+
);
126+
127+
if (isVisible) {
128+
await expect(conditionallyVisibleTextInput).toBeVisible();
129+
} else {
130+
await expect(conditionallyVisibleTextInput).not.toBeVisible();
131+
}
132+
}, 10000);
133+
});
134+
135+
test.afterEach(async ({ page }) => {
136+
await page.close();
137+
});

packages/react-sdk-components/tests/e2e/Digv2/Confirmation.spec.js renamed to packages/react-sdk-components/tests/e2e/Digv2/ViewTemplates/Confirmation.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-undef */
33

44
const { test, expect } = require('@playwright/test');
5-
const config = require('../../config');
6-
const common = require('../../common');
5+
const config = require('../../../config');
6+
const common = require('../../../common');
77

88
test.beforeEach(async ({ page }) => {
99
await page.goto('http://localhost:3502/portal');

packages/react-sdk-components/tests/unit/components/forms/TextInput/index.test.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from 'react';
2-
import { render } from '@testing-library/react';
2+
import { render, fireEvent } from '@testing-library/react';
33
import TextInput from '../../../../../src/components/field/TextInput';
44

5+
const onBlur = jest.fn();
6+
const onChange = jest.fn();
57
const getDefaultProps = (): any => {
68
return {
79
required: true,
810
testId: 'textInputTestId',
911
label: 'TextInput',
10-
displayMode: false
12+
displayMode: false,
13+
onChange,
14+
onBlur
1115
};
1216
};
1317

@@ -59,4 +63,26 @@ describe('Test Text Input component', () => {
5963
const readOnlySpan = getByText('Hi there!');
6064
expect(readOnlySpan).toBeVisible();
6165
});
66+
67+
test('TextInput Component invoke handlers for blur and change events', () => {
68+
const props = getDefaultProps();
69+
const TextInputComponent = render(<TextInput {...props} />);
70+
fireEvent.change(TextInputComponent.getByTestId('textInputTestId'), {
71+
target: { value: 'a' }
72+
});
73+
fireEvent.blur(TextInputComponent.getByTestId('textInputTestId'));
74+
expect(onChange).toHaveBeenCalled();
75+
expect(onBlur).toHaveBeenCalled();
76+
});
77+
78+
test('TextInput Component should not invoke on blur handler for read only fields', () => {
79+
const props = getDefaultProps();
80+
props.readOnly = true;
81+
const TextInputComponent = render(<TextInput {...props} />);
82+
fireEvent.change(TextInputComponent.getByTestId('textInputTestId'), {
83+
target: { value: 'a' }
84+
});
85+
fireEvent.blur(TextInputComponent.getByTestId('textInputTestId'));
86+
expect(onBlur).toHaveBeenCalled();
87+
});
6288
});

0 commit comments

Comments
 (0)