Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
nidaqg committed Nov 6, 2024
1 parent dcb6eac commit d718a47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
const columnHelper = createColumnHelper()

//Create cells for columns, with customization for first column
const createCellFunction = (cellAccessors: string[], customRenderer?: (row: Row<GenericObject>, value: any) => JSX.Element, index:number) => {
const createCellFunction = (cellAccessors: string[], customRenderer?: (row: Row<GenericObject>, value: any) => JSX.Element, index?: number) => {
const columnCells = ({
row,
getValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useState} from "react"
import { render, screen, waitFor } from "../utilities/test-utils"

import { AdvancedTable } from "playbook-ui"
import { AdvancedTable, Pill } from "playbook-ui"

const MOCK_DATA = [
{
Expand Down Expand Up @@ -88,6 +88,28 @@ const columnDefinitions = [
},
]

const columnDefinitionsCustomRenderer = [
{
accessor: "year",
label: "Year",
cellAccessors: ["quarter", "month", "day"],
},
{
accessor: "newEnrollments",
label: "New Enrollments",
customRenderer: (row, value) => (
<Pill text={value}
variant="success"
/>
),
},
{
accessor: "scheduledMeetings",
label: "Scheduled Meetings",
},
]


const subRowHeaders = ["Quarter"]

const testId = "advanced_table"
Expand Down Expand Up @@ -463,3 +485,17 @@ test("responsive none prop functions as expected", () => {
const kit = screen.getByTestId(testId)
expect(kit).toHaveClass("pb_advanced_table table-responsive-none")
})

test("customRenderer prop functions as expected", () => {
render(
<AdvancedTable
columnDefinitions={columnDefinitionsCustomRenderer}
data={{ testid: testId }}
tableData={MOCK_DATA}
/>
)

const kit = screen.getByTestId(testId)
const pill = kit.querySelector(".pb_pill_kit_success_lowercase")
expect(pill).toBeInTheDocument()
})

0 comments on commit d718a47

Please sign in to comment.