first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
import * as scroll from '../../../actions/interaction/scroll.operation';
|
||||
import { ERROR_MESSAGES } from '../../../constants';
|
||||
import * as transport from '../../../transport';
|
||||
import { createMockExecuteFunction } from '../helpers';
|
||||
|
||||
const baseNodeParameters = {
|
||||
resource: 'interaction',
|
||||
operation: 'scroll',
|
||||
sessionId: 'test-session-123',
|
||||
windowId: 'win-123',
|
||||
additionalFields: {},
|
||||
};
|
||||
|
||||
const baseAutomaticNodeParameters = {
|
||||
...baseNodeParameters,
|
||||
scrollingMode: 'automatic',
|
||||
scrollToElement: 'the bottom of the page',
|
||||
scrollWithin: '',
|
||||
};
|
||||
|
||||
const baseManualNodeParameters = {
|
||||
...baseNodeParameters,
|
||||
scrollingMode: 'manual',
|
||||
scrollToEdge: {
|
||||
edgeValues: {
|
||||
yAxis: 'bottom',
|
||||
xAxis: '',
|
||||
},
|
||||
},
|
||||
scrollBy: {
|
||||
scrollValues: {
|
||||
yAxis: '200px',
|
||||
xAxis: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
success: true,
|
||||
message: 'Scrolled successfully',
|
||||
};
|
||||
|
||||
jest.mock('../../../transport', () => {
|
||||
const originalModule = jest.requireActual<typeof transport>('../../../transport');
|
||||
return {
|
||||
...originalModule,
|
||||
apiRequest: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe('Test Airtop, scroll operation', () => {
|
||||
afterAll(() => {
|
||||
jest.unmock('../../../transport');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should execute automatic scroll operation successfully', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await scroll.execute.call(
|
||||
createMockExecuteFunction(baseAutomaticNodeParameters),
|
||||
0,
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/sessions/test-session-123/windows/win-123/scroll',
|
||||
{
|
||||
scrollToElement: 'the bottom of the page',
|
||||
configuration: {},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
sessionId: baseAutomaticNodeParameters.sessionId,
|
||||
windowId: baseAutomaticNodeParameters.windowId,
|
||||
success: true,
|
||||
message: 'Scrolled successfully',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should execute manual scroll operation successfully', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
apiRequestMock.mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await scroll.execute.call(
|
||||
createMockExecuteFunction(baseManualNodeParameters),
|
||||
0,
|
||||
);
|
||||
|
||||
expect(apiRequestMock).toHaveBeenCalledWith(
|
||||
'POST',
|
||||
'/sessions/test-session-123/windows/win-123/scroll',
|
||||
{
|
||||
configuration: {},
|
||||
scrollToEdge: {
|
||||
yAxis: 'bottom',
|
||||
xAxis: '',
|
||||
},
|
||||
scrollBy: {
|
||||
yAxis: '200px',
|
||||
xAxis: '',
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
json: {
|
||||
sessionId: baseManualNodeParameters.sessionId,
|
||||
windowId: baseManualNodeParameters.windowId,
|
||||
success: true,
|
||||
message: 'Scrolled successfully',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should throw error when scrollingMode is 'automatic' and 'scrollToElement' parameter is empty", async () => {
|
||||
const nodeParameters = {
|
||||
...baseAutomaticNodeParameters,
|
||||
scrollToElement: '',
|
||||
};
|
||||
|
||||
await expect(scroll.execute.call(createMockExecuteFunction(nodeParameters), 0)).rejects.toThrow(
|
||||
ERROR_MESSAGES.REQUIRED_PARAMETER.replace('{{field}}', 'Element Description'),
|
||||
);
|
||||
});
|
||||
|
||||
it("should validate scroll amount formats when scrollingMode is 'manual'", async () => {
|
||||
const invalidNodeParameters = {
|
||||
...baseManualNodeParameters,
|
||||
scrollBy: {
|
||||
scrollValues: {
|
||||
yAxis: 'one hundred pixels',
|
||||
xAxis: '',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await expect(
|
||||
scroll.execute.call(createMockExecuteFunction(invalidNodeParameters), 0),
|
||||
).rejects.toThrow(ERROR_MESSAGES.SCROLL_BY_AMOUNT_INVALID);
|
||||
});
|
||||
|
||||
it('should throw an error when the API returns an error response', async () => {
|
||||
const apiRequestMock = transport.apiRequest as jest.Mock;
|
||||
const errorResponse = {
|
||||
errors: [
|
||||
{
|
||||
message: 'Failed to scroll',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
apiRequestMock.mockResolvedValueOnce(errorResponse);
|
||||
|
||||
await expect(
|
||||
scroll.execute.call(createMockExecuteFunction(baseAutomaticNodeParameters), 0),
|
||||
).rejects.toThrow('Failed to scroll');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user