Skip to content

Commit

Permalink
frontend tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshmi2506 committed Feb 1, 2024
1 parent f7e9e48 commit 6bf7707
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 21 deletions.
4 changes: 2 additions & 2 deletions docs/api/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1700,10 +1700,10 @@ components:
ListMetadataRequest:
type: object
properties:
desiredType: string
desired_type: string
minLength: 1
required:
- desiredType
- desired_type
CommitRequest:
type: object
properties:
Expand Down
6 changes: 3 additions & 3 deletions metecho/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,17 +651,17 @@ def get_unsaved_changes(scratch_org, *, originating_user_id):
get_unsaved_changes_job = job(get_unsaved_changes)


def get_nonsource_components(*, scratch_org, desiredType, originating_user_id):
def get_nonsource_components(*, scratch_org, desired_type, originating_user_id):
try:
scratch_org.refresh_from_db()
with dataset_env(scratch_org) as (project_config, org_config, sf, schema, repo):
components = ListComponents(
org_config=org_config,
project_config=project_config,
task_config=TaskConfig({"options": {"metadata_types": desiredType}}),
task_config=TaskConfig({"options": {"metadata_types": desired_type}}),
)()

scratch_org.non_source_changes[desiredType] = [
scratch_org.non_source_changes[desired_type] = [
cmp["MemberName"] for cmp in components
]
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions metecho/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,15 +1475,15 @@ def queue_get_unsaved_changes(self, *, force_get=False, originating_user_id):

get_unsaved_changes_job.delay(self, originating_user_id=originating_user_id)

def queue_get_nonsource_components(self, *, originating_user_id, desiredType: str):
def queue_get_nonsource_components(self, *, originating_user_id, desired_type: str):
from .jobs import get_nonsource_components_job

self.currently_refreshing_changes = True
self.save()
self.notify_changed(originating_user_id=originating_user_id)
get_nonsource_components_job.delay(
scratch_org=self,
desiredType=desiredType,
desired_type=desired_type,
originating_user_id=originating_user_id,
)

Expand Down
2 changes: 1 addition & 1 deletion metecho/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ class CommitSerializer(serializers.Serializer):


class ListMetadataSerializer(serializers.Serializer):
desiredType = serializers.CharField()
desired_type = serializers.CharField()


class CommitDatasetSerializer(serializers.Serializer):
Expand Down
2 changes: 1 addition & 1 deletion metecho/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def listmetadata(self, request, pk=None):
status=status.HTTP_403_FORBIDDEN,
)
scratch_org.queue_get_nonsource_components(
desiredType=serializer.validated_data["desiredType"],
desired_type=serializer.validated_data["desired_type"],
originating_user_id=str(request.user.id),
)
return Response(
Expand Down
13 changes: 3 additions & 10 deletions src/js/components/tasks/retrieveMetadata/changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ interface Props {
refreshing: boolean;
}

export interface Components {
desiredType: string;
}

const ChangesList = ({
type,
allChanges,
Expand Down Expand Up @@ -193,18 +189,15 @@ const ChangesForm = ({
...expandedPanels,
[groupName]: !expandedPanels[groupName],
});
const match = groupName.match(/changes-(.+)/);

// Check if there is a match and get the group name
const alpha = match ? match[1] : null;
const metadata_type = groupName.match(/changes-(.+)/)?.[1];
if (expandedPanels[groupName] === undefined) {
await apiFetch({
url: window.api_urls.scratch_org_listmetadata(id),
dispatch,
opts: {
method: 'POST',
body: JSON.stringify({
desiredType: alpha,
desired_type: metadata_type,
}),
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -392,7 +385,7 @@ const ChangesForm = ({
slds-p-vertical_x-small
slds-p-right_medium"
>
<p>Non source trackable</p>
Non-Source-Trackable
{refreshing ? (
<SpinnerWrapper size="small" variant="brand"></SpinnerWrapper>
) : (
Expand Down
78 changes: 76 additions & 2 deletions test/js/components/tasks/retrieveMetadata/index.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fireEvent, waitFor } from '@testing-library/react';
import fetchMock from 'fetch-mock';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';

Expand Down Expand Up @@ -30,6 +31,11 @@ const defaultChangeset = {
Buz: ['Baz', 'Bing'],
};

const defaultComponents = {
Alpha: ['Beta'],
Gamma: ['Delta', 'Theta'],
};

const defaultIgnored = {
Bang: ['Bazinga'],
};
Expand All @@ -41,6 +47,9 @@ const defaultOrg = {
unsaved_changes: defaultChangeset,
ignored_changes: defaultIgnored,
valid_target_directories: defaultDirs,
non_source_changes: defaultComponents,
has_non_source_changes: true,
currently_refreshing_changes: false,
};

describe('<RetrieveMetadataModal/>', () => {
Expand Down Expand Up @@ -266,7 +275,7 @@ describe('<RetrieveMetadataModal/>', () => {
});

describe('select changes', () => {
let getters, selectAll, selectAllIgnored, group1, group2, inputs;
let getters, selectAll, selectAllIgnored, group1, group2, group3, inputs;

beforeEach(() => {
getters = setup();
Expand All @@ -276,11 +285,13 @@ describe('<RetrieveMetadataModal/>', () => {
selectAllIgnored = getByLabelText('All Ignored Changes');
group1 = getByLabelText('Buz');
group2 = getByLabelText('Bang');
group3 = getByLabelText('Alpha');
inputs = [
getByLabelText('Bar'),
getByLabelText('Baz'),
getByLabelText('Bing'),
getByLabelText('Bazinga'),
getByLabelText('Beta'),
];
});

Expand All @@ -292,27 +303,31 @@ describe('<RetrieveMetadataModal/>', () => {
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(selectAllIgnored);

expect(inputs[0].checked).toBe(true);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(selectAll);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(false);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(selectAllIgnored);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(false);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);
});
});

Expand All @@ -324,27 +339,38 @@ describe('<RetrieveMetadataModal/>', () => {
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(group2);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(group1);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(false);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(group2);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(false);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(group3);
expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(false);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(true);
});
});

Expand All @@ -356,71 +382,119 @@ describe('<RetrieveMetadataModal/>', () => {
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(inputs[2]);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(inputs[3]);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(true);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(inputs[2]);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(true);
expect(inputs[4].checked).toBe(false);

fireEvent.click(inputs[3]);

expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(false);

fireEvent.click(inputs[4]);
expect(inputs[0].checked).toBe(false);
expect(inputs[1].checked).toBe(true);
expect(inputs[2].checked).toBe(false);
expect(inputs[3].checked).toBe(false);
expect(inputs[4].checked).toBe(true);
});
});

describe('accordion panel click', () => {
test('expands/collapses', () => {
const { baseElement, getByTitle } = getters;
const panels = baseElement.querySelectorAll('.slds-accordion__content');

const url = window.api_urls.scratch_org_listmetadata('org-id');
expect(panels[0]).toHaveAttribute('aria-hidden', 'true');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'true');
expect(panels[3]).toHaveAttribute('aria-hidden', 'true');
expect(panels[4]).toHaveAttribute('aria-hidden', 'true');

fireEvent.click(getByTitle('Buz'));

expect(panels[0]).toHaveAttribute('aria-hidden', 'false');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'true');
expect(panels[3]).toHaveAttribute('aria-hidden', 'true');
expect(panels[4]).toHaveAttribute('aria-hidden', 'true');

fireEvent.click(getByTitle('Bang'));

expect(panels[0]).toHaveAttribute('aria-hidden', 'false');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'true');
expect(panels[3]).toHaveAttribute('aria-hidden', 'false');
expect(panels[4]).toHaveAttribute('aria-hidden', 'true');

fireEvent.click(getByTitle('All Ignored Changes'));

expect(panels[0]).toHaveAttribute('aria-hidden', 'false');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'false');
expect(panels[3]).toHaveAttribute('aria-hidden', 'false');
expect(panels[4]).toHaveAttribute('aria-hidden', 'true');

fetchMock.postOnce(url, {
options: { desired_type: 'Alpha' },
});
fireEvent.click(getByTitle('Alpha'));
expect(panels[0]).toHaveAttribute('aria-hidden', 'false');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'false');
expect(panels[3]).toHaveAttribute('aria-hidden', 'false');
expect(panels[4]).toHaveAttribute('aria-hidden', 'false');

fireEvent.click(getByTitle('Alpha'));
expect(panels[0]).toHaveAttribute('aria-hidden', 'false');
expect(panels[1]).toHaveAttribute('aria-hidden', 'true');
expect(panels[2]).toHaveAttribute('aria-hidden', 'false');
expect(panels[3]).toHaveAttribute('aria-hidden', 'false');
expect(panels[4]).toHaveAttribute('aria-hidden', 'true');
});
});
});

test('checks for the spinner', () => {
const { getByText, rerender, store } = setup();
fireEvent.click(getByText('Save & Next'));
setup({
org: {
...defaultOrg,
currently_refreshing_changes: true,
},
store,
rerender,
});
const nonSourceTrackableElement = getByText('Loading...');
expect(nonSourceTrackableElement).not.toBeNull();
});

describe('commit message', () => {
let getters;

Expand Down

0 comments on commit 6bf7707

Please sign in to comment.