Skip to content

Commit

Permalink
Allow service actions to use both input type and process type. Add se…
Browse files Browse the repository at this point in the history
…rvices testing.
  • Loading branch information
twinkarma committed Jun 28, 2024
1 parent 385cd70 commit 8c235a9
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 29 deletions.
20 changes: 9 additions & 11 deletions src/components/NavItems/Assistant/AssistantRuleBook.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const ASSISTANT_ACTIONS = [
{
title: "navbar_magnifier",
icon: magnifierIconOff,
linksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
processLinksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
cTypes: [CONTENT_TYPE.IMAGE],
exceptions: [],
useInputUrl: false,
Expand All @@ -177,7 +177,7 @@ export const ASSISTANT_ACTIONS = [
{
title: "navbar_metadata",
icon: metadataIconOff,
linksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
processLinksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
cTypes: [CONTENT_TYPE.IMAGE, CONTENT_TYPE.VIDEO],
exceptions: [
/(pbs.twimg.com)|(youtu.be|youtube)|(instagram)|(fbcdn.net)|(vimeo)|(tiktok.com)/,
Expand All @@ -201,7 +201,7 @@ export const ASSISTANT_ACTIONS = [
{
title: "navbar_forensic",
icon: forensicIconOff,
linksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
processLinksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
cTypes: [CONTENT_TYPE.IMAGE],
exceptions: [],
useInputUrl: false,
Expand All @@ -212,7 +212,7 @@ export const ASSISTANT_ACTIONS = [
{
title: "navbar_ocr",
icon: forensicIconOff,
linksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
processLinksAccepted: [KNOWN_LINKS.MISC, KNOWN_LINKS.OWN],
cTypes: [CONTENT_TYPE.IMAGE],
exceptions: [],
useInputUrl: false,
Expand All @@ -223,7 +223,7 @@ export const ASSISTANT_ACTIONS = [
{
title: "assistant_video_download_action",
icon: videoIconOff,
linksAccepted: [KNOWN_LINKS.TELEGRAM, KNOWN_LINKS.MISC],
linksAccepted: [KNOWN_LINKS.TELEGRAM, KNOWN_LINKS.FACEBOOK],
cTypes: [CONTENT_TYPE.VIDEO],
exceptions: [],
useInputUrl: false,
Expand All @@ -241,12 +241,10 @@ export const selectCorrectActions = (
) => {
let possibleActions = ASSISTANT_ACTIONS.filter(
(action) =>
((action.useInputUrl &&
action.linksAccepted.includes(inputUrlType) &&
action.cTypes.includes(contentType)) ||
(!action.useInputUrl &&
action.linksAccepted.includes(processUrlType) &&
action.cTypes.includes(contentType))) &&
(!action.linksAccepted || action.linksAccepted.includes(inputUrlType)) &&
(!action.processLinksAccepted ||
action.processLinksAccepted.includes(processUrlType)) &&
action.cTypes.includes(contentType) &&
(action.exceptions.length === 0 || !processUrl.match(action.exceptions)),
);
return possibleActions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const AssistantImageResult = () => {
height={"100%"}
alt={processUrl}
width={"100%"}
data-testid="assistant-media-image"
/>
</CardMedia>
<CardActions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,18 @@ const AssistantVideoResult = () => {

return (
<Card variant={"outlined"}>
<CardMedia data-testid="assistant-video-container">
<CardMedia data-testid="assistant-media-video-container">
{useIframe() && preprocessLinkForEmbed(processUrl) && (
<Iframe
hidden={downloadVideoFound()}
frameBorder="0"
url={preprocessLinkForEmbed(processUrl)}
allow="fullscreen"
height="400"
width="100%"
data-testid="assistant-video-iframe"
/>
<div data-testid="assistant-media-video-iframe">
<Iframe
hidden={downloadVideoFound()}
frameBorder="0"
url={preprocessLinkForEmbed(processUrl)}
allow="fullscreen"
height="400"
width="100%"
/>
</div>
)}
{!useIframe() && preprocessLinkForEmbed(processUrl) && (
<video
Expand All @@ -122,7 +123,7 @@ const AssistantVideoResult = () => {
controls={true}
height="400"
width="100%"
data-testid="assistant-video-tag"
data-testid="assistant-media-video-tag"
/>
)}
{!preprocessLinkForEmbed(processUrl) && (
Expand All @@ -135,7 +136,7 @@ const AssistantVideoResult = () => {
justifyContent: "center",
}}
>
<div data-testid="assistant-video-noembed">
<div data-testid="assistant-media-video-noembed">
{keyword("embedding_not_supported")}
</div>
</div>
Expand Down
111 changes: 105 additions & 6 deletions tests/e2e/assistant.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, expect } from './fixtures';


// test('example test', async ({ page }) => {
// await page.goto('https://example.com');
// await expect(page.locator('body')).toHaveText('Changed by my-extension');
Expand All @@ -18,29 +19,127 @@ test('Assstant page', async ({ page, extensionId }) => {

});

const MediaType = {
video: "video",
image: "image"
};

const MediaVideoStatus = {
iframe: 0,
video: 1,
noEmbed: 2,
};

const MediaServices = {
analysisVideo: "navbar_analysis_video",
analysisImage: "navbar_analysis_image",
keyframes: "navbar_keyframes",
thumbnails: "navbar_thumbnails",
magnifier: "navbar_magnifier",
metadata: "navbar_metadata",
videoRights: "navbar_rights",
forensic: "navbar_forensic",
ocr: "navbar_ocr",
videoDownload: "assistant_video_download_action",
};

[
{url: "https://www.facebook.com/natgeo/videos/10157990199633951", gridIndex: 0, services: ["navbar_analysis_video", "navbar_keyframes", "assistant_video_download_action"]},
{url: "https://t.me/disclosetv/13970", services: ["navbar_metadata", "assistant_video_download_action"]},
].forEach(({url, gridIndex, services}) => {
test(`Test assistant services for url ${url}`, async ({ page, extensionId }) => {
// Youtube video
{
url: "https://www.youtube.com/watch?v=UXrkN0iQmZQ",
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.iframe,
services: [MediaServices.analysisVideo, MediaServices.keyframes, MediaServices.thumbnails, MediaServices.videoRights]
},
// Facebook post with video
{
url: "https://www.facebook.com/natgeo/videos/10157990199633951",
videoGridIndex: 0,
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.video,
services: [MediaServices.analysisVideo, MediaServices.keyframes, MediaServices.videoDownload]
},
// Telegram post with video
{
url: "https://t.me/disclosetv/13970",
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.video,
services: [MediaServices.metadata, MediaServices.videoDownload]
},
// Instagram post with an image
{
url: "https://www.instagram.com/p/CI2b-3usJoH/",
mediaType: MediaType.image,
services: [MediaServices.magnifier, MediaServices.forensic, MediaServices.ocr]
},
// Instagram post with a video reel
{
url: "https://www.instagram.com/p/C8JwcyOiFDD/",
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.noEmbed,
services: []
}
].forEach(({url, videoGridIndex, imageGridIndex, mediaType, mediaStatus, services}) => {
test(`Test assistant media services for url: ${url}`, async ({ page, extensionId }) => {

// Navigate to the assistant page
await page.goto(`chrome-extension://${extensionId}/popup.html#/app/assistant/`);
// Accept local storage usage
await page.getByText("Accept").click();

// Component to display media should not be displayed at the start
await expect(page.getByTestId("url-media-results")).not.toBeVisible();

// Choose to enter url instead of uploading a file
await page.getByTestId("assistant-webpage-link").click();
await page.locator("[data-testid='assistant-url-selected-input'] input").fill(url);
await page.getByTestId("assistant-url-selected-analyse-btn").click();

// Expecting a media post with images or video
await expect(page.getByTestId("url-media-results")).toBeVisible({timeout: 20000});

if(gridIndex !== undefined && gridIndex !== null){
await page.getByTestId("assistant-media-grid-video-"+gridIndex).click();
// If multiple images/videos exist, click on the media grid first
if(Number.isInteger(videoGridIndex))
await page.getByTestId("assistant-media-grid-video-"+videoGridIndex).click();

if(Number.isInteger(imageGridIndex))
await page.getByTestId("assistant-media-grid-image-"+imageGridIndex).click();

// If expecting an image, check that the image is shown
if(mediaType === MediaType.image){
await expect(page.getByTestId("assistant-media-image")).toBeVisible();
}

if(mediaType === MediaType.video){
await expect(page.getByTestId("assistant-media-video-container")).toBeVisible();
if(mediaStatus !== null && mediaStatus !== undefined){
switch (mediaStatus) {
case MediaVideoStatus.iframe:
await expect(page.getByTestId("assistant-media-video-iframe")).toBeVisible();
break;
case MediaVideoStatus.video:
await expect(page.getByTestId("assistant-media-video-tag")).toBeVisible();
break;
case MediaVideoStatus.noEmbed:
await expect(page.getByTestId("assistant-media-video-noembed")).toBeVisible();
break;

}
}
}

// Checks that expected services are shown
for( const serviceId of services){
await expect(page.getByTestId(serviceId)).toBeVisible({timeout: 10000});
}

// Ensure disabled services are not showing
for( const serviceKey in MediaServices){
const serviceId = MediaServices[serviceKey];
if(!services.includes(serviceId))
await expect(page.getByTestId(serviceId)).not.toBeVisible();
}

});
}
);
Expand Down

0 comments on commit 8c235a9

Please sign in to comment.