Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/compass-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"clean": "node -e \"fs.rmSync('lib', { recursive: true, force: true })\" || true",
"precompile": "npm run clean",
"compile": "tsc -p tsconfig.json",
"typecheck": "tsc -p tsconfig-lint.json --noEmit",
"eslint": "eslint-compass",
"prettier": "prettier-compass",
"lint": "npm run eslint . && npm run prettier -- --check .",
"depcheck": "compass-scripts check-peer-deps && depcheck",
"check": "npm run lint && npm run depcheck",
"check": "npm run typecheck && npm run lint && npm run depcheck",
"check-ci": "npm run check",
"test": "mocha",
"test-cov": "nyc --compact=false --produce-source-map=false -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ describe('ContentWithFallback', function () {
);

expect(container.children.length).to.equal(2);
const [contentContainer, contextMenuContainer] = container.children;
const [contentContainer, contextMenuContainer] = Array.from(
container.children
);
expect(contentContainer.children.length).to.equal(0);
expect(contextMenuContainer.getAttribute('data-testid')).to.equal(
'context-menu-container'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import HadronDocument from 'hadron-document';
import Document from './document';

const EditableDoc = ({ doc }) => {
const EditableDoc = ({ doc }: { doc: HadronDocument }) => {
const [editing, setEditing] = useState(false);

return (
Expand Down Expand Up @@ -61,8 +61,11 @@ describe('Document', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('str').uuid}"]`
`[data-id="${doc.get('str')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}
const keyEditor = within(el).getByTestId('hadron-document-key-editor');

userEvent.clear(keyEditor);
Expand All @@ -71,16 +74,19 @@ describe('Document', function () {

expect(screen.getByDisplayValue('new_name')).to.exist;

expect(doc.get('new_name').key).to.eq('str');
expect(doc.get('new_name').currentKey).to.eq('new_name');
expect(doc.get('new_name')?.key).to.eq('str');
expect(doc.get('new_name')?.currentKey).to.eq('new_name');
});

it('should change element string value on edit', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('str').uuid}"]`
`[data-id="${doc.get('str')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

const valueEditor = within(el).getByTestId(
'hadron-document-value-editor'
Expand All @@ -90,16 +96,19 @@ describe('Document', function () {
userEvent.keyboard('bla');
userEvent.tab();

expect(doc.get('str').currentValue).to.eq('bla');
expect(doc.get('str').currentType).to.eq('String');
expect(doc.get('str')?.currentValue).to.eq('bla');
expect(doc.get('str')?.currentType).to.eq('String');
});

it('should change element number value on edit', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('num').uuid}"]`
`[data-id="${doc.get('num')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

const valueEditor = within(el).getByTestId(
'hadron-document-value-editor'
Expand All @@ -109,16 +118,19 @@ describe('Document', function () {
userEvent.keyboard('321');
userEvent.tab();

expect(doc.get('num').currentValue.valueOf()).to.eq(321);
expect(doc.get('num').currentType).to.eq('Int32');
expect(doc.get('num')?.currentValue?.valueOf()).to.eq(321);
expect(doc.get('num')?.currentType).to.eq('Int32');
});

it('should change element date value on edit', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('date').uuid}"]`
`[data-id="${doc.get('date')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

const valueEditor = within(el).getByTestId(
'hadron-document-value-editor'
Expand All @@ -128,26 +140,29 @@ describe('Document', function () {
userEvent.keyboard('2000-01-01');
userEvent.tab();

expect((doc.get('date').currentValue as Date).toISOString()).to.eq(
expect((doc.get('date')?.currentValue as Date).toISOString()).to.eq(
'2000-01-01T00:00:00.000Z'
);
expect(doc.get('date').currentType).to.eq('Date');
expect(doc.get('date')?.currentType).to.eq('Date');
});

it('should change element type on edit', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('num').uuid}"]`
`[data-id="${doc.get('num')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

const typeEditor = within(el).getByTestId('hadron-document-type-editor');

userEvent.selectOptions(typeEditor, 'String');
userEvent.tab();

expect(doc.get('num').currentValue.valueOf()).to.eq('123');
expect(doc.get('num').currentType).to.eq('String');
expect(doc.get('num')?.currentValue?.valueOf()).to.eq('123');
expect(doc.get('num')?.currentType).to.eq('String');
});
});

Expand All @@ -168,8 +183,11 @@ describe('Document', function () {
render(<Document value={doc} editable editing></Document>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('null_value').uuid}"]`
`[data-id="${doc.get('null_value')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

const typeEditor = within(el).getByTestId('hadron-document-type-editor');

Expand All @@ -182,16 +200,19 @@ describe('Document', function () {
userEvent.keyboard('foo bar');
userEvent.tab();

expect(doc.get('null_value').currentValue.valueOf()).to.eq('foo bar');
expect(doc.get('null_value').currentType).to.eq('String');
expect(doc.get('null_value')?.currentValue?.valueOf()).to.eq('foo bar');
expect(doc.get('null_value')?.currentType).to.eq('String');
});

it('should autofocus key editor when double-clicking key', function () {
render(<EditableDoc doc={doc}></EditableDoc>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('str').uuid}"]`
`[data-id="${doc.get('str')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

userEvent.dblClick(within(el).getByTestId('hadron-document-clickable-key'));

Expand All @@ -204,8 +225,11 @@ describe('Document', function () {
render(<EditableDoc doc={doc}></EditableDoc>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('str').uuid}"]`
`[data-id="${doc.get('str')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

userEvent.dblClick(
within(el).getByTestId('hadron-document-clickable-value')
Expand All @@ -220,8 +244,11 @@ describe('Document', function () {
render(<EditableDoc doc={doc}></EditableDoc>);

const el = document.querySelector<HTMLElement>(
`[data-id="${doc.get('null_value').uuid}"]`
`[data-id="${doc.get('null_value')?.uuid}"]`
);
if (!el) {
throw new Error('Could not find element');
}

userEvent.dblClick(
within(el).getByTestId('hadron-document-clickable-value')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import FileInput, {
} from './file-picker-dialog';

describe('FileInput', function () {
let spy;
let spy: sinon.SinonSpy;

beforeEach(function () {
spy = sinon.spy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,31 @@ describe('GuideCueService', function () {

context('marks group as visited', function () {
context('when all the cues of group are added', function () {
const cue1 = {
cueId: 'one',
step: 1,
groupId: 'group-two',
isIntersecting: true,
} as unknown as Cue;
const cue2 = {
cueId: 'two',
step: 2,
groupId: 'group-two',
isIntersecting: true,
};
let cue1: Cue;
let cue2: Cue;

let markCueAsVisited: Sinon.SinonSpy;

beforeEach(function () {
cue1 = {
cueId: 'one',
step: 1,
groupId: 'group-two',
isVisited: false,
isIntersecting: true,
};
cue2 = {
cueId: 'two',
step: 2,
groupId: 'group-two',
isVisited: false,
isIntersecting: true,
};

markCueAsVisited = Sinon.spy(guideCueStorage, 'markCueAsVisited');
guideCueService.addCue(cue1 as any);
guideCueService.addCue(cue2 as any);
guideCueService.markGroupAsVisited(cue1.groupId);
guideCueService.addCue(cue1);
guideCueService.addCue(cue2);
guideCueService.markGroupAsVisited(cue1.groupId!);
});

it('updates isVisited property for all group cues', function () {
Expand Down Expand Up @@ -444,19 +449,21 @@ describe('GuideCueService', function () {
});

context('when all the cues of group are not added', function () {
const cue1 = {
cueId: 'one',
step: 1,
groupId: 'group-two',
isIntersecting: true,
} as unknown as Cue;
let cue1: Cue;

let markCueAsVisited: Sinon.SinonSpy;

beforeEach(function () {
cue1 = {
cueId: 'one',
step: 1,
groupId: 'group-two',
isIntersecting: true,
isVisited: false,
};
markCueAsVisited = Sinon.spy(guideCueStorage, 'markCueAsVisited');
guideCueService.addCue(cue1 as any);
guideCueService.markGroupAsVisited(cue1.groupId);
guideCueService.addCue(cue1);
guideCueService.markGroupAsVisited(cue1.groupId!);
});

it('does not update isVisited property for group cues', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const renderGuideCue = (props: Partial<ComponentProps<typeof GuideCue>>) => {
</Button>
<GuideCue
cueId=""
groupId=""
step={0}
title=""
description=""
trigger={({ ref }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function renderPopover(
hideCloseButton={props?.hideCloseButton}
customFocusTrapFallback={`#${innerContentTestId}`}
setOpen={() => {}}
trigger={({ onClick, ref, children }) => (
trigger={({ onClick, children }) => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, ref needs to be passed to the trigger for the component to work (looking at the test, we just don't test the behavior that relies on this)

Copy link
Member Author

@Anemy Anemy Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will push up some more tests shortly. Ran into something weird here I really don't know the cause of.

Making any of the tests in this file async with a await setTimeout like

await new Promise(resolve => setTimeout(resolve, 10));

(or our waitFor helper) will cause the test to not report any results. I've tried with other tests in compass-components and they don't have the same behavior. It looks like it's something in the render of InteractivePopover that causes it. Maybe the focus trap? Not sure. Going to look at it a bit more, but I'll avoid spending too much time on it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding more specs! That's indeed weird, was looking through some other tests and what's weird is that some other components that use this one have async tests (at leat at a glance, maybe they're not hitting it) and those are passing 🤔

<>
<button type="button" onClick={onClick} ref={ref}>
<button type="button" onClick={onClick}>
Trigger Button Text
</button>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('ListEditor', function () {
});

describe('when rendered with multiple items', function () {
let onAddItemSpy;
let onRemoveItemSpy;
let onAddItemSpy: sinon.SinonSpy;
let onRemoveItemSpy: sinon.SinonSpy;

beforeEach(function () {
onAddItemSpy = sinon.spy();
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-components/src/components/loader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function renderLoader() {
return render(<SpinLoader size="12px" />);
}

function renderCancelLoader(spy) {
function renderCancelLoader(spy: sinon.SinonSpy) {
return render(
<CancelLoader
data-testid="my-test-id"
Expand All @@ -34,7 +34,7 @@ describe('SpinLoader Component', function () {
});

describe('CancelLoader Component', function () {
let spy;
let spy: sinon.SinonSpy;

beforeEach(function () {
spy = sinon.spy();
Expand Down
Loading
Loading