Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erwan committed Sep 11, 2024
1 parent 33bc644 commit 318cf07
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 212 deletions.
79 changes: 0 additions & 79 deletions docs/templates/assets/index-4aa72204.js

This file was deleted.

79 changes: 79 additions & 0 deletions docs/templates/assets/index-e349b9a9.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/templates/assets/trilogy-0f3ce7a7.css

This file was deleted.

1 change: 1 addition & 0 deletions docs/templates/assets/trilogy-5062bfff.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="theme-color" content="#000000" />
<meta name="description" content="Trilogy React Typescript" />
<title>Trilogy DS</title>
<script type="module" crossorigin src="/templates/assets/index-4aa72204.js"></script>
<script type="module" crossorigin src="/templates/assets/index-e349b9a9.js"></script>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion docs/templates/trilogy-mangled.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/templates/trilogy-partials.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/templates/trilogy.css

Large diffs are not rendered by default.

203 changes: 94 additions & 109 deletions packages/react/components/alert/test/Alert.test.tsx
Original file line number Diff line number Diff line change
@@ -1,141 +1,126 @@
import * as React from "react";
import { fireEvent, render } from "@testing-library/react";
import { Alert } from "../index";
import { StatusProps } from "../StatusProps";
import { StatusState } from "../../../objects";
import { IconName } from "../../icon";
import renderer from "react-test-renderer";
import { fireEvent, render } from '@testing-library/react'
import * as React from 'react'
import renderer from 'react-test-renderer'
import { StatusState } from '../../../objects'
import { IconName } from '../../icon'
import { Alert } from '../index'

describe("Alert", () => {
it("should render correctly", () => {
describe('Alert', () => {
it('should render correctly', () => {
const { getByTestId } = render(
<Alert
testId={"alert"}
testId={'alert'}
display
alert={StatusState.INFO}
title="Alert information"
description="Lorem Ipsum is simply dummy text of the printing and type.."
/>
);
const alert = getByTestId("alert");
expect(alert).toBeInTheDocument();
});
status={StatusState.INFO}
title='Alert information'
description='Lorem Ipsum is simply dummy text of the printing and type..'
/>,
)
const alert = getByTestId('alert')
expect(alert).toBeInTheDocument()
})

it("should have the right className", () => {
it('should have the right className', () => {
const { getByTestId } = render(
<Alert
testId={"alert"}
testId={'alert'}
display
alert={StatusState.INFO}
title="Alert information"
description="Lorem Ipsum is simply dummy text of the printing and type.."
/>
);
status={StatusState.INFO}
title='Alert information'
description='Lorem Ipsum is simply dummy text of the printing and type..'
/>,
)

const alert = getByTestId("alert");
expect(alert).toHaveClass("alert");
});
const alert = getByTestId('alert')
expect(alert).toHaveClass('alert')
})

test("should render with correct props and className based on StatusState", () => {
const props: StatusProps = {
testId: "alert",
test('should render with correct props and className based on StatusState', () => {
const props = {
testId: 'alert',
display: true,
alert: StatusState.INFO,
title: "Alert information",
description:
"Lorem Ipsum is simply dummy text of the printing and type..",
status: StatusState.INFO,
title: 'Alert information',
description: 'Lorem Ipsum is simply dummy text of the printing and type..',
iconName: IconName.EYE_SLASH,
};
const { getByTestId } = render(<Alert {...props} />);
const alert = getByTestId("alert");
expect(alert).toHaveClass("is-info");
});
}
const { getByTestId } = render(<Alert {...props} />)
const alert = getByTestId('alert')
expect(alert).toHaveClass('is-info')
})

test("snapshot", () => {
test('snapshot', () => {
const tree = renderer
.create(
<Alert
testId={"alert"}
testId={'alert'}
display={true}
alert={StatusState.INFO}
title="Alert information"
description="Lorem Ipsum is simply dummy text of the printing and type.."
status={StatusState.INFO}
title='Alert information'
description='Lorem Ipsum is simply dummy text of the printing and type..'
iconName={IconName.TIMES}
/>
/>,
)
.toJSON();
.toJSON()

expect(tree).toMatchSnapshot();
});
expect(tree).toMatchSnapshot()
})

it("should have iconClassName with right icon", () => {
it('should have iconClassName with right icon', () => {
const { getByTestId } = render(
<Alert
testId={"alert"}
testId={'alert'}
display
alert={StatusState.INFO}
iconClassname="testIconClassName"
status={StatusState.INFO}
iconName={IconName.BELL}
/>
);
const alert = getByTestId("alert");
expect(alert.firstChild).toHaveClass("testIconClassName");
expect(alert.firstChild?.firstChild).toHaveClass("tri-bell");
});
/>,
)
const alert = getByTestId('alert')
expect(alert.firstChild).toHaveClass('icon')
expect(alert.firstChild?.firstChild).toHaveClass('tri-bell')
})

it("should have icon SUCCESS icon", () => {
const { getByTestId } = render(
<Alert testId={"alert"} display alert={StatusState.SUCCESS} />
);
const alert = getByTestId("alert");
expect(alert.firstChild?.firstChild).toHaveClass(IconName.CHECK_CIRCLE);
});
it('should have icon SUCCESS icon', () => {
const { getByTestId } = render(<Alert testId={'alert'} display status={StatusState.SUCCESS} />)
const alert = getByTestId('alert')
expect(alert.firstChild?.firstChild).toHaveClass(IconName.CHECK_CIRCLE)
})

it("should have icon WARNING icon", () => {
const { getByTestId } = render(
<Alert testId={"alert"} display alert={StatusState.WARNING} />
);
const alert = getByTestId("alert");
expect(alert.firstChild?.firstChild).toHaveClass(IconName.ALERT);
});
it('should have icon WARNING icon', () => {
const { getByTestId } = render(<Alert testId={'alert'} display status={StatusState.WARNING} />)
const alert = getByTestId('alert')
expect(alert.firstChild?.firstChild).toHaveClass(IconName.ALERT)
})

it("should have icon INFO icon", () => {
const { getByTestId } = render(
<Alert testId={"alert"} display alert={StatusState.INFO} />
);
const alert = getByTestId("alert");
expect(alert.firstChild?.firstChild).toHaveClass(IconName.INFOS_CIRCLE);
});
it('should have icon INFO icon', () => {
const { getByTestId } = render(<Alert testId={'alert'} display status={StatusState.INFO} />)
const alert = getByTestId('alert')
expect(alert.firstChild?.firstChild).toHaveClass(IconName.INFOS_CIRCLE)
})

it("should have icon ERROR icon", () => {
const { getByTestId } = render(
<Alert testId={"alert"} display alert={StatusState.ERROR} />
);
const alert = getByTestId("alert");
expect(alert.firstChild?.firstChild).toHaveClass(
IconName.EXCLAMATION_CIRCLE
);
});
it('should have icon ERROR icon', () => {
const { getByTestId } = render(<Alert testId={'alert'} display status={StatusState.ERROR} />)
const alert = getByTestId('alert')
expect(alert.firstChild?.firstChild).toHaveClass(IconName.EXCLAMATION_CIRCLE)
})

it("should have icon default icon", () => {
const { getByTestId } = render(<Alert testId={"alert"} display />);
const alert = getByTestId("alert");
expect(alert.firstChild?.firstChild).toHaveClass(IconName.INFOS_CIRCLE);
});
it('should have icon default icon', () => {
const { getByTestId } = render(<Alert testId={'alert'} display />)
const alert = getByTestId('alert')
expect(alert.firstChild?.firstChild).toHaveClass(IconName.INFOS_CIRCLE)
})

it("should execute onClick fn", () => {
let isClick = false;
const { getByTestId } = render(
<Alert testId={"alert"} display onClick={() => (isClick = true)} />
);
const alert = getByTestId("alert");
fireEvent.click(alert);
expect(isClick).toBe(true);
});
it('should execute onClick fn', () => {
let isClick = false
const { getByTestId } = render(<Alert testId={'alert'} display onClick={() => (isClick = true)} />)
const alert = getByTestId('alert')
fireEvent.click(alert)
expect(isClick).toBe(true)
})

it("should return div", () => {
const { container } = render(<Alert testId={"alert"} />);
const divElm = container.querySelector("div");
expect(divElm).toBeInTheDocument();
});
});
it('should return div', () => {
const { container } = render(<Alert testId={'alert'} />)
const divElm = container.querySelector('div')
expect(divElm).toBeInTheDocument()
})
})
12 changes: 1 addition & 11 deletions packages/react/components/badge/test/Badge.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import * as React from 'react'
import { fireEvent, render, screen } from '@testing-library/react'

// Component to test
import { getEnumNames } from '@/helpers'
import { getColorClassName } from '@/objects'
import { has } from '@/services'
import { Badge, BadgeColor, BadgeTextDirection } from '../'
import { Badge, BadgeTextDirection } from '../'

describe('Badge component', () => {
test('should contain toto as text', () => {
Expand Down Expand Up @@ -59,13 +56,6 @@ describe('Badge component', () => {
expect(screen.getByText(BadgeTextDirection.RIGHT).previousElementSibling).toBeNull()
})

test('should have a correct color className', () => {
getEnumNames(BadgeColor).forEach((element) => {
render(<Badge color={element}>{element}</Badge>)
expect(screen.getByText(element)).toHaveClass(has(`background-${getColorClassName(element)}`))
})
})

test('should onClick attribut work', () => {
const mockCallBack = jest.fn()
render(<Badge onClick={mockCallBack}>DEFAULT</Badge>)
Expand Down
3 changes: 1 addition & 2 deletions packages/react/components/box/test/Box.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ describe("Box component", () => {
shadowless
background="SUCCESS"
backgroundSrc="test"
leftBorder="SUCCESS"
flat
hat
/>
);
const box = getByTestId("box");
expect(box).toHaveClass(
"box is-shadowless has-background-success is-loaded has-background is-highlighted is-success is-flat has-hat"
"box is-shadowless has-background-success has-background is-base is-loaded is-flat has-hat"
);
});
test("Should have skeleton", () => {
Expand Down
4 changes: 0 additions & 4 deletions packages/react/components/chips/test/Chips.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ describe("Chips", () => {
expect(getByText("Hello, world!")).toHaveAttribute("disabled");
});

it("applies the inverted class if the inverted prop is true", () => {
const { getByText } = render(<Chips inverted>Hello, world!</Chips>);
expect(getByText("Hello, world!")).toHaveClass("has-background-white");
});

it("calls the onClick handler when clicked", () => {
const handleClick = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/react/components/progress/test/Progress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("ProgressItem", () => {
percent={50}
minPercent={0}
maxPercent={200}
alert={StatusState.SUCCESS}
status={StatusState.SUCCESS}
accessibilityLabel="Loading progress"
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/components/toaster/test/Toaster.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const ToasterViewComp: React.FC = () => {
title,
description,
iconName: IconName.INFOS_CIRCLE,
alert: StatusState.WARNING,
status: StatusState.WARNING,
onClick: () => setBtnName("click toast"),
closable: () => setTitle("close toast"),
onHide: () => console.log("onHide"),
Expand Down

0 comments on commit 318cf07

Please sign in to comment.