Skip to content

Commit 664bd4f

Browse files
committed
UPSE-386: Update Playwright search tests for portlet 'favorite' flag
1 parent 7aad824 commit 664bd4f

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

tests/api/search-v5_0.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import { test, expect } from "@playwright/test";
22
import { config } from "../general-config";
33
import { loginViaApi } from "../ux/utils/ux-general-utils";
4+
import {
5+
PortletDefBasicInfo,
6+
getPortletDetails,
7+
} from "./utils/api-portlets-utils";
8+
import {
9+
favoritePortlet,
10+
unfavoritePortlet,
11+
} from "./utils/api-preferences-utils";
12+
13+
interface PortletSearchResult {
14+
description: string;
15+
fname: string;
16+
name: string;
17+
score: string;
18+
title: string;
19+
url: string;
20+
favorite: boolean;
21+
}
22+
23+
interface PortletSearchResults {
24+
portlets: PortletSearchResult[];
25+
}
426

527
test("search all", async ({ request }) => {
628
await loginViaApi(request, config.users.admin);
@@ -18,11 +40,32 @@ test("search all", async ({ request }) => {
1840
score: "4.0",
1941
title: "Daily Business Cartoon",
2042
url: "/uPortal/p/daily-business-cartoon.ctf3/max/render.uP",
43+
favorite: false,
2144
},
2245
],
2346
});
2447
});
2548

49+
test("search favorited portlet", async({ request }) => {
50+
await loginViaApi(request, config.users.admin);
51+
const portletFname = 'daily-business-cartoon';
52+
const portletDetails: PortletDefBasicInfo = await getPortletDetails(request, portletFname);
53+
if (!portletDetails) {
54+
console.error('could not retrieve portlet details in order to get portlet ID');
55+
test.fail();
56+
} else {
57+
const portletId = portletDetails.id;
58+
expect(await favoritePortlet(request, portletId)).not.toBeNull();
59+
const response = await request.get(`${config.url}api/v5-0/portal/search?q=cartoon&type=portlets`);
60+
expect(await unfavoritePortlet(request, portletId)).toBe(true);
61+
expect(response.status()).toEqual(200);
62+
const portletSearchResults: PortletSearchResults = JSON.parse(await response.text()) as PortletSearchResults;
63+
const portletFound: PortletSearchResult = portletSearchResults.portlets[0];
64+
expect(portletFound.favorite).toBe(true);
65+
expect(portletFound.fname).toBe(portletFname);
66+
}
67+
});
68+
2669
test("search type people", async ({ request }) => {
2770
await loginViaApi(request, config.users.admin);
2871
const response = await request.get(
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, APIRequestContext } from "@playwright/test";
2+
import { config } from "../../general-config";
3+
4+
export type PortletDefBasicInfo = {
5+
id: string;
6+
name: string;
7+
fname: string;
8+
} | null;
9+
10+
type PortletsResponse = {
11+
portlets: PortletDefBasicInfo[];
12+
};
13+
14+
/*
15+
* Retrieve the details for a portlet identified by it's fname.
16+
*/
17+
export async function getPortletDetails(
18+
request: APIRequestContext,
19+
portletFname: string
20+
): Promise<PortletDefBasicInfo> {
21+
const response = await request.get(`${config.url}api/portlets.json`);
22+
expect(response.status()).toEqual(200);
23+
const portletsJson: PortletsResponse = await response.json() as PortletsResponse;
24+
const portlets: PortletDefBasicInfo[] = portletsJson.portlets;
25+
for (const val of portlets) {
26+
if (val != null && val.fname == portletFname) {
27+
return val;
28+
}
29+
}
30+
return null;
31+
}
32+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { expect, APIRequestContext } from "@playwright/test";
2+
import { config } from "../../general-config";
3+
4+
type PreferenceFavoriteResponse = {
5+
newNodeId: string;
6+
response: string;
7+
};
8+
9+
/*
10+
* Favorite a portlet, indentified by portlet ID. Return new node ID.
11+
*/
12+
export async function favoritePortlet(
13+
request: APIRequestContext,
14+
portletId: string
15+
): Promise<string> {
16+
expect(portletId).not.toBeNull();
17+
const response = await request.post(
18+
`${config.url}api/layout?action=addFavorite&channelId=${portletId}`
19+
);
20+
expect(response.status()).toEqual(200);
21+
const responseBody: PreferenceFavoriteResponse = JSON.parse(await response.text()) as PreferenceFavoriteResponse;
22+
return responseBody.newNodeId;
23+
}
24+
25+
/*
26+
* Unfavorite a portlet, indentified by portlet ID. Returns boolean indicating whether or not operation was successful.
27+
*/
28+
export async function unfavoritePortlet(
29+
request: APIRequestContext,
30+
portletId: string
31+
): Promise<boolean> {
32+
expect(portletId).not.toBeNull();
33+
const response = await request.post(`${config.url}api/layout?action=removeFavorite&channelId=${portletId}`);
34+
expect(response.status()).toEqual(200);
35+
const responseBody: PreferenceFavoriteResponse = JSON.parse(await response.text()) as PreferenceFavoriteResponse;
36+
return responseBody.response === "Removed from Favorites successfully";
37+
}

0 commit comments

Comments
 (0)