Skip to content

Commit

Permalink
feat: render single whitelisted property as full-width (#366)
Browse files Browse the repository at this point in the history
* feat: display full-width property if only one whitelisted

* chore(test): add basic tests
  • Loading branch information
silvester-pari authored Oct 24, 2023
1 parent 27bd90f commit bac0f23
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 9 deletions.
25 changes: 17 additions & 8 deletions elements/stacinfo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,28 @@ export class EOxStacInfo extends LitElement {
${parseEntries(this.properties).length > 0
? html`
<section id="properties" part="properties">
<ul>
<ul
class=${parseEntries(this.properties).length === 1
? "single-property"
: nothing}
>
${map(
parseEntries(this.properties),
([, value]) => html`
<slot name=${value.label.toLowerCase()}>
<li>
<span class="label">
${
// TODO
// @ts-ignore
value.label
} </span
>:
${when(
parseEntries(this.properties).length > 1,
() => html`
<span class="label">
${
// TODO
// @ts-ignore
value.label
} </span
>:
`
)}
<span class="value">
${
// TODO
Expand Down
2 changes: 1 addition & 1 deletion elements/stacinfo/src/style.eox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ slot[name=footer] {
list-style: none;
padding: 0;
}
#properties li {
#properties ul:not(.single-property) li {
flex-basis: 50%;
padding: 20px 0;
}
Expand Down
14 changes: 14 additions & 0 deletions elements/stacinfo/stacinfo.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export const AllProperties = {
},
};

/**
* If only one property is whitelisted, then it renders the content full-width and without the key.
*/
export const SingleProperty = {
args: {
...Basic.args,
header: [],
subheader: [],
properties: ["description"],
featured: [],
footer: [],
},
};

/**
* Individual STAC properties can be rendered in a more prominent way by using the `featured` property.
*/
Expand Down
60 changes: 60 additions & 0 deletions elements/stacinfo/test/general.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import "../src/main";

describe("Stacinfo", () => {
const testBody = (json) => {
cy.intercept("/collection*", {
body: json,
});
};

it("loads stacinfo", () => {
testBody({
type: "Collection",
});
cy.mount(
`
<eox-stacinfo for="/collection"></eox-stacinfo>`
).as("eox-stacinfo");
cy.get("eox-stacinfo").shadow();
});

it("creates list items for all properties", () => {
const body = {
type: "Collection",
title: "Foobar",
id: "foobar",
};
testBody(body);
cy.mount(
`
<eox-stacinfo for="/collection"></eox-stacinfo>`
).as("eox-stacinfo");
cy.get("eox-stacinfo")
.shadow()
.within(() => {
cy.get("li", { multiple: true }).should(
"have.length",
Object.keys(body).length
);
});
});

it("creates a single-property class if only one property is whitelisted", () => {
testBody({
type: "Collection",
description: "Hello world!",
});
cy.mount(
`
<eox-stacinfo
for="/collection"
properties='["description"]'
></eox-stacinfo>`
).as("eox-stacinfo");
cy.get("eox-stacinfo")
.shadow()
.within(() => {
cy.get("#properties ul.single-property").should("exist");
});
});
});

0 comments on commit bac0f23

Please sign in to comment.