Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi-kumar-pilla committed Sep 16, 2024
1 parent 405826e commit 8563187
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 36 deletions.
15 changes: 15 additions & 0 deletions cypress/fixtures/mock/compatibleMetadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"has_missing_dependencies": false,
"package_compatibilities": [
{
"package_name": "fsspec",
"package_version": "2023.9.1",
"is_compatible": true
},
{
"package_name": "kedro-datasets",
"package_version": "2.0.0",
"is_compatible": true
}
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[
{
{
"has_missing_dependencies": true,
"package_compatibilities": [
{
"package_name": "fsspec",
"package_version": "2023.8.1",
"is_compatible": false
},
{
},
{
"package_name": "kedro-datasets",
"package_version": "1.8.0",
"is_compatible": false
}
]
}
]
}
12 changes: 0 additions & 12 deletions cypress/fixtures/mock/package-compatibilities-compatible.json

This file was deleted.

32 changes: 32 additions & 0 deletions cypress/tests/ui/flowchart/banners.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('Banners in Kedro-Viz', () => {
beforeEach(() => {
// Clears localStorage before each test
cy.clearLocalStorage();
});

it("shows a missing dependencies banner in viz lite mode if the kedro project dependencies are not installed.", () => {
// Intercept the network request to mock with a fixture
cy.__interceptRest__(
'/api/metadata',
'GET',
'/mock/inCompatibleMetadata.json'
).as("appMetadata");

// Action
cy.reload();

// Assert after action
cy.get('[data-test="flowchart-wrapper--lite-banner"]').should('exist');
cy.get('.banner-message-body').should('contains.text', 'please install the missing Kedro project dependencies')
cy.get('.banner-message-title').should('contains.text', 'Missing dependencies')

// Test Learn more link
cy.get(".banner a")
.should("contains.attr", "href", "https://docs.kedro.org/projects/kedro-viz/en/latest/kedro-viz_visualisation.html#visualise-a-kedro-project-without-installing-project-dependencies");

// Close the banner
cy.get(".banner-close").click()
cy.get('[data-test="flowchart-wrapper--lite-banner"]').should('not.exist');

});
});
8 changes: 4 additions & 4 deletions cypress/tests/ui/flowchart/shareable-urls.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ describe('Shareable URLs with empty localStorage', () => {
it('verifies that users can open the Deploy Kedro-Viz modal if the localStorage is empty. #TC-52', () => {
// Intercept the network request to mock with a fixture
cy.__interceptRest__(
'/api/package-compatibilities',
'/api/metadata',
'GET',
'/mock/package-compatibilities-compatible.json'
'/mock/compatibleMetadata.json'
);

// Action
Expand All @@ -25,9 +25,9 @@ describe('Shareable URLs with empty localStorage', () => {
it("shows an incompatible message given the user's fsspec package version is outdated. #TC-53", () => {
// Intercept the network request to mock with a fixture
cy.__interceptRest__(
'/api/package-compatibilities',
'/api/metadata',
'GET',
'/mock/package-compatibilities-incompatible.json'
'/mock/inCompatibleMetadata.json'
);

// Action
Expand Down
6 changes: 3 additions & 3 deletions src/components/experiment-wrapper/experiment-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const ExperimentWrapper = ({ theme, runsMetadata }) => {
}, []);

useEffect(() => {
async function getPackageCompatibility() {
async function checkPackageCompatibility() {
try {
const request = await fetchMetadata();
const response = await request.json();
Expand All @@ -206,11 +206,11 @@ const ExperimentWrapper = ({ theme, runsMetadata }) => {
setIsKedroDatasetsCompatible(kedroDatasetsPackage.is_compatible);
}
} catch (error) {
console.error('package-compatibilities fetch error: ', error);
console.error('metadata fetch error: ', error);
}
}

getPackageCompatibility();
checkPackageCompatibility();
}, []);

useEffect(() => {
Expand Down
14 changes: 7 additions & 7 deletions src/components/flowchart-wrapper/flowchart-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { isRunningLocally, mapNodeTypes } from '../../utils';
import { useGeneratePathname } from '../../utils/hooks/use-generate-pathname';
import './flowchart-wrapper.scss';
import Banner from '../ui/banner';
import { getDataTestAttribute } from '../../utils/get-data-test-attribute';

/**
* Main flowchart container. Handles showing/hiding the sidebar nav for flowchart view,
Expand Down Expand Up @@ -315,13 +316,11 @@ export const FlowChartWrapper = ({
};

const showBanner = (bannerKey) => {
return true;
// [TODO: Uncomment below part after design testing]
// const bannerStatus = loadLocalStorage(localStorageBannerStatus);
// const shouldShowBanner =
// displayBanner[bannerKey] &&
// (bannerStatus[bannerKey] || bannerStatus[bannerKey] === undefined);
// return shouldShowBanner;
const bannerStatus = loadLocalStorage(localStorageBannerStatus);
const shouldShowBanner =
displayBanner[bannerKey] &&
(bannerStatus[bannerKey] || bannerStatus[bannerKey] === undefined);
return shouldShowBanner;
};

if (isInvalidUrl) {
Expand Down Expand Up @@ -350,6 +349,7 @@ export const FlowChartWrapper = ({
}}
btnUrl={BANNER_METADATA.liteModeWarning.docsLink}
onClose={() => handleBannerClose(BANNER_KEYS.LITE)}
dataTest={getDataTestAttribute('flowchart-wrapper', 'lite-banner')}
/>
)}
<div className="pipeline-wrapper">
Expand Down
6 changes: 3 additions & 3 deletions src/components/shareable-url-modal/shareable-url-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ShareableUrlModal = ({ onToggleModal, onSetBanner, visible }) => {
const [isPreviewEnabled, setIsPreviewEnabled] = useState(false);

useEffect(() => {
async function getPackageCompatibility() {
async function checkPackageCompatibility() {
try {
const request = await fetchMetadata();
const response = await request.json();
Expand All @@ -71,11 +71,11 @@ const ShareableUrlModal = ({ onToggleModal, onSetBanner, visible }) => {
}
}
} catch (error) {
console.error('package-compatibilities fetch error: ', error);
console.error('metadata fetch error: ', error);
}
}

getPackageCompatibility();
checkPackageCompatibility();
}, [onSetBanner]);

const setStateForPublishedView = () => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/ui/banner/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Banner = ({
btnText = 'Learn More',
position = 'top',
onClose = null,
dataTest,
}) => {
const [isVisible, setIsVisible] = useState(true);

Expand All @@ -30,7 +31,10 @@ const Banner = ({
}

return (
<div className={classnames('banner', `banner-${position}`)}>
<div
className={classnames('banner', `banner-${position}`)}
data-test={dataTest}
>
{icon && <div className="banner-icon">{icon}</div>}
<div className="banner-message">
<span className="banner-message-title">{message.title}</span>
Expand Down

0 comments on commit 8563187

Please sign in to comment.