Skip to content

Commit

Permalink
Update duplicates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvarela committed Aug 22, 2024
1 parent 42df4f3 commit caca25e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 74 deletions.
107 changes: 43 additions & 64 deletions site/gatsby-site/playwright/e2e-full/cite.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { waitForRequest, query, mockDate, test, conditionalIntercept } from '../utils';
import upsertDuplicateClassification from '../fixtures/classifications/upsertDuplicateClassification.json';
import updateIncident50 from '../fixtures/incidents/updateIncident50.json';
import { waitForRequest, query, mockDate, test, conditionalIntercept, fillAutoComplete } from '../utils';
import { format } from 'date-fns';
import incident10 from '../fixtures/incidents/fullIncident10.json';
import incident50 from '../fixtures/incidents/fullIncident50.json';
import { gql } from '@apollo/client';
import { expect } from '@playwright/test';
import config from '../config';
Expand Down Expand Up @@ -163,71 +159,51 @@ test.describe('Cite pages', () => {
expect(data.report.flag).toBe(true);
});

test.skip('Should remove duplicate', async ({ page }) => {
await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON().operationName === 'UpsertClassification',
upsertDuplicateClassification,
'upsertClassification'
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON().operationName === 'UpdateIncident',
updateIncident50,
'updateIncident'
);

await conditionalIntercept(
page,
'**/graphql',
(req) => req.postDataJSON().operationName === 'InsertDuplicate',
{
data: {
insertOneDuplicate: {
__typename: 'Duplicate',
duplicate_incident_number: 10,
true_incident_number: 50,
},
},
},
'insertDuplicate'
);
test('Should remove duplicate', async ({ page, login }) => {

await conditionalIntercept(
page,
'**/graphql',
(req) =>
req.postDataJSON().operationName === 'FindIncident' &&
req.postDataJSON().variables.query.incident_id === 10,
incident10,
'findIncident'
);
test.slow();

await conditionalIntercept(
page,
'**/graphql',
(req) =>
req.postDataJSON().operationName === 'FindIncident' &&
req.postDataJSON().variables.query.incident_id === 50,
incident50,
'findIncident'
);
await init();

await login(page, config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD);
await login(config.E2E_ADMIN_USERNAME, config.E2E_ADMIN_PASSWORD, { customData: { first_name: 'Test', last_name: 'User', roles: ['admin'] } });

await page.goto('/cite/10');
await page.goto('/cite/3');

await page.click('[data-cy="remove-duplicate"]');

await page.fill('#input-duplicateIncidentId', '50');
await page.click('#duplicateIncidentId > a[aria-label="50"]');
await fillAutoComplete(page, '#input-duplicateIncidentId', '2 incident', 'Incident 2');

await page.click('[data-cy="confirm-remove-duplicate"]');

await expect(page.locator('text=Incident 10 marked as duplicate')).toBeVisible();
await expect(page.locator('text=Incident 3 marked as duplicate')).toBeVisible({ timeout: 30000 });

const { data } = await query({
query: gql`
{
duplicates(filter: { duplicate_incident_number: { EQ: 3 } }) {
true_incident_number
}
incident_classifications_3: classifications(filter: { incidents: { EQ: 3 } }) {
namespace
notes
incidents {
incident_id
}
}
incident_classifications_2: classifications(filter: { incidents: { EQ: 2 } }) {
namespace
notes
incidents {
incident_id
}
}
}
`,
});

expect(data.duplicates).toEqual([{ true_incident_number: 2 }]);
expect(data.incident_classifications_3).toHaveLength(0);
expect(data.incident_classifications_2).toHaveLength(3);
});

test('Should pre-fill submit report form', async ({ page }) => {
Expand Down Expand Up @@ -258,14 +234,17 @@ test.describe('Cite pages', () => {
await expect(page.locator('a:has-text("Previous Incident")')).toHaveAttribute('href', '/cite/1');
});

test.skip('Should render Next and Previous incident buttons if duplicate incident', async ({ page }) => {
await page.goto('/cite/90');
test('Should render duplicate page', async ({ page }) => {
await page.goto('/cite/5');

await expect(page.getByText('This incident is a duplicate of Incident 3. All new reports and citations should be directed to incident 3. The reports previously found on this page have been migrated to the previously existing incident.')).toBeVisible();

await expect(page.locator('a:has-text("Next Incident")')).toBeVisible();
await expect(page.locator('a:has-text("Next Incident")')).toHaveAttribute('href', '/cite/91');
await expect(page.locator('a:has-text("Next Incident")')).toHaveAttribute('disabled');


await expect(page.locator('a:has-text("Previous Incident")')).toBeVisible();
await expect(page.locator('a:has-text("Previous Incident")')).toHaveAttribute('href', '/cite/89');
await expect(page.locator('a:has-text("Previous Incident")')).toHaveAttribute('href', '/cite/3');
});

test('Should render the header next/previous buttons', async ({ page }) => {
Expand Down
2 changes: 2 additions & 0 deletions site/gatsby-site/playwright/memory-mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import entities from './seeds/aiidprod/entities';
import reports_es from './seeds/translations/reports_es';
import classifications from './seeds/aiidprod/classifications';
import taxa from './seeds/aiidprod/taxa';
import duplicates from './seeds/aiidprod/duplicates';

import users from './seeds/customData/users';

Expand All @@ -23,6 +24,7 @@ export const init = async (extra?: Record<string, Record<string, Record<string,
entities,
classifications,
taxa,
duplicates,
},
customData: {
users,
Expand Down
14 changes: 14 additions & 0 deletions site/gatsby-site/playwright/seeds/aiidprod/duplicates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ObjectId } from 'bson';
import { Duplicate } from '../../../server/generated/graphql'

export type DBDuplicate = Duplicate;

const items: DBDuplicate[] = [
{
_id: new ObjectId("619b47eb5eed5334edfa3bd7"),
duplicate_incident_number: 5,
true_incident_number: 3,
},
]

export default items;
1 change: 1 addition & 0 deletions site/gatsby-site/playwright/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export async function fillAutoComplete(page: Page, selector: string, sequence: s
await page.locator(selector).clear();
await page.waitForTimeout(1000);
await page.locator(selector).pressSequentially(sequence, { delay: 500 });
await page.waitForTimeout(1000);
await page.getByText(target).click({ timeout: 1000 });
}).toPass();
}
19 changes: 10 additions & 9 deletions site/gatsby-site/src/components/cite/RemoveDuplicateModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ export default function RemoveDuplicateModal({ incident, show, onClose }) {

const [upsertClassification] = useMutation(UPSERT_CLASSIFICATION);

const [updateSubscription] = useMutation(UPSERT_SUBSCRIPTION);
const [upsertSubscription] = useMutation(UPSERT_SUBSCRIPTION);

const { data: classificationsData, loading: classificationsLoading } = useQuery(
FIND_CLASSIFICATION,
{ variables: { filter: { incidents: { incident_id: { EQ: incident.incident_id } } } } }
{ variables: { filter: { incidents: { EQ: incident.incident_id } } } }
);

const { data: subscriptionsData, loading: subscriptionsLoading } = useQuery(
FIND_FULL_SUBSCRIPTIONS,
{ variables: { query: { incident_id: { incident_id: incident.incident_id } } } }
{ variables: { filter: { incident_id: { EQ: incident.incident_id } } } }
);

return (
Expand All @@ -41,7 +41,7 @@ export default function RemoveDuplicateModal({ incident, show, onClose }) {
{({ values, isSubmitting, setSubmitting }) => {
const { data: duplicateIncidentData, loading: duplicateIncidentLoading } = useQuery(
FIND_INCIDENT,
{ variables: { query: { incident_id: values.duplicateIncidentId?.[0] } } }
{ variables: { filter: { incident_id: { EQ: values.duplicateIncidentId?.[0] } } } }
);

const submitBlocked =
Expand Down Expand Up @@ -88,8 +88,8 @@ export default function RemoveDuplicateModal({ incident, show, onClose }) {
try {
await updateIncident({
variables: {
query: { incident_id: true_incident_number },
set: { reports: { link: reportIds } },
filter: { incident_id: { EQ: true_incident_number } },
update: { set: { reports: { link: reportIds } } },
},
});
} catch (e) {
Expand All @@ -108,6 +108,7 @@ export default function RemoveDuplicateModal({ incident, show, onClose }) {
filter: { _id: { EQ: classification._id } },
update: {
...classification,
_id: undefined,
incidents: {
link: classification.incidents
.map((incident) => incident.incident_id)
Expand All @@ -131,10 +132,10 @@ export default function RemoveDuplicateModal({ incident, show, onClose }) {
}
try {
for (const subscription of subscriptionsData.subscriptions) {
await updateSubscription({
await upsertSubscription({
variables: {
query: { _id: subscription._id },
subscription: {
filter: { _id: { EQ: subscription._id } },
update: {
userId: { link: subscription.userId.userId },
incident_id: { link: true_incident_number },
type: subscription.type,
Expand Down
3 changes: 2 additions & 1 deletion site/gatsby-site/src/components/incidents/IncidentsField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { FIND_INCIDENTS_TITLE } from '../../graphql/incidents';

const filterBy = (option, text) => {
return (
option?.title.toLowerCase().includes(text.toLowerCase()) || option.id?.toString().includes(text)
option?.title.toLowerCase().includes(text.toLowerCase()) ||
text.toLowerCase().includes(option.id?.toString())
);
};

Expand Down

0 comments on commit caca25e

Please sign in to comment.