Skip to content

Commit

Permalink
fix: lint issues;
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Dec 20, 2024
1 parent ef34879 commit 112c185
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
44 changes: 24 additions & 20 deletions src/components/SitewideBanner/SitewideBanner.test.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
import React from "react";
import { shallow } from "enzyme";
import Cookies from "js-cookie";
import { Alert } from "react-bootstrap";
import SitewideBanner from "./index";
import React from 'react';
import { shallow } from 'enzyme';
import Cookies from 'js-cookie'; // eslint-disable-line import/no-extraneous-dependencies
import { Alert } from 'react-bootstrap'; // eslint-disable-line import/no-extraneous-dependencies
import SitewideBanner from './index';

describe("SitewideBanner", () => {
it("renders correctly when visible", () => {
describe('SitewideBanner', () => {
it('renders correctly when visible', () => {
const wrapper = shallow(
<SitewideBanner
message="Dummy Message"
type="success"
dismissible={true}
dismissible
cookieName="bannerCookie"
cookieExpiryDays={7}
/>
/>,
);

expect(wrapper.find(Alert).props().variant).toBe("success");
expect(wrapper.find(Alert).props().variant).toBe('success');
expect(wrapper.find(Alert).props().dismissible).toBe(true);
const alertContent = wrapper.find(Alert).dive().find("div").first().html();
expect(alertContent).toContain("Dummy Message");
const alertContent = wrapper.find(Alert)
.dive()
.find('div')
.first()
.html();
expect(alertContent).toContain('Dummy Message');
});

it("calls handleDismiss and sets cookie when dismissed", () => {
const setCookieMock = jest.spyOn(Cookies, "set");
it('calls handleDismiss and sets cookie when dismissed', () => {
const setCookieMock = jest.spyOn(Cookies, 'set');
const wrapper = shallow(
<SitewideBanner
message="This is a test message"
type="warning"
dismissible={true}
dismissible
cookieName="bannerCookie"
cookieExpiryDays={7}
/>
/>,
);
wrapper.find(Alert).simulate("close");
wrapper.find(Alert).simulate('close');
expect(wrapper.isEmptyRender()).toBe(true);
expect(setCookieMock).toHaveBeenCalledWith("bannerCookie", "true", {
expect(setCookieMock).toHaveBeenCalledWith('bannerCookie', 'true', {
expires: 7,
});
setCookieMock.mockRestore();
});

it("handles non-dismissible banner correctly", () => {
it('handles non-dismissible banner correctly', () => {
const wrapper = shallow(
<SitewideBanner message="Non-dismissible message" dismissible={false} />
<SitewideBanner message="Non-dismissible message" dismissible={false} />,
);
expect(wrapper.find(Alert).props().dismissible).toBe(false);
});
Expand Down
22 changes: 13 additions & 9 deletions src/components/SitewideBanner/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import Cookies from "js-cookie";
import { Alert, Container } from "react-bootstrap";

const SitewideBanner = ({ message, type, dismissible, cookieName, cookieExpiryDays }) => {
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import Cookies from 'js-cookie';

Check failure on line 3 in src/components/SitewideBanner/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'js-cookie' should be listed in the project's dependencies. Run 'npm i -S js-cookie' to add it
import {

Check failure on line 4 in src/components/SitewideBanner/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'react-bootstrap' should be listed in the project's dependencies. Run 'npm i -S react-bootstrap' to add it
Alert, Container,
} from 'react-bootstrap';

const SitewideBanner = ({
message, type, dismissible, cookieName, cookieExpiryDays,
}) => {
const [isVisible, setIsVisible] = useState(true);

useEffect(() => {
Expand All @@ -15,7 +19,7 @@ const SitewideBanner = ({ message, type, dismissible, cookieName, cookieExpiryDa
const handleDismiss = () => {
setIsVisible(false);
if (cookieName) {
Cookies.set(cookieName, "true", { expires: cookieExpiryDays });
Cookies.set(cookieName, 'true', { expires: cookieExpiryDays });
}
};

Expand All @@ -39,14 +43,14 @@ const SitewideBanner = ({ message, type, dismissible, cookieName, cookieExpiryDa

SitewideBanner.propTypes = {
message: PropTypes.string.isRequired,
type: PropTypes.oneOf(["primary", "success", "warning", "danger", "info", "secondary", "light", "dark"]),
type: PropTypes.oneOf(['primary', 'success', 'warning', 'danger', 'info', 'secondary', 'light', 'dark']),
dismissible: PropTypes.bool,
cookieName: PropTypes.string,
cookieExpiryDays: PropTypes.number,
};

SitewideBanner.defaultProps = {
type: "info",
type: 'info',
dismissible: false,
cookieName: null,
cookieExpiryDays: 7,
Expand Down
1 change: 0 additions & 1 deletion src/containers/MainApp/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import EditCollaborator from '../EditCollaborator';
import EditCourse from '../EditCourse';
import SitewideBanner from '../../components/SitewideBanner';


const MainApp = () => (
<div>
<Header />
Expand Down

0 comments on commit 112c185

Please sign in to comment.