Removed @cached and changed tests

This commit is contained in:
Sérgio Saquetim 2024-08-05 16:27:49 -03:00
parent 3dc23b6c42
commit 8a40eef21b
No known key found for this signature in database
GPG Key ID: B4E3D7F11E793062
3 changed files with 56 additions and 9 deletions

View File

@ -64,6 +64,10 @@ export default class SidebarSection extends Component {
}
},
{
collapseSection: (sectionName) =>
this.sidebarState.collapseSection(sectionName),
expandSection: (sectionName) =>
this.sidebarState.expandSection(sectionName),
sectionName: this.args.sectionName,
collapsable: this.args.collapsable,
isCollapsed: this.isCollapsed,

View File

@ -1,4 +1,4 @@
import { cached, tracked } from "@glimmer/tracking";
import { tracked } from "@glimmer/tracking";
import { registerDestructor } from "@ember/destroyable";
import Service, { service } from "@ember/service";
import { TrackedSet } from "@ember-compat/tracked-built-ins";
@ -53,7 +53,6 @@ export default class SidebarState extends Service {
this.restorePreviousState();
}
@cached
get currentPanel() {
return this.panels.find((panel) => panel.key === this.currentPanelKey);
}

View File

@ -1040,22 +1040,66 @@ acceptance("Sidebar - Transformers", function (needs) {
navigation_menu: "sidebar",
});
test("sidebar-section-set-expanded-state transformer", async function (assert) {
const transformed = [];
test("sidebar-section-set-expanded-state transformer - collapse all sections", async function (assert) {
let shouldCollapse = true;
withPluginApi("1.34.0", (api) => {
withPluginApi("1.35.0", (api) => {
api.registerBehaviorTransformer(
"sidebar-section-set-expanded-state",
({ context, next }) => {
transformed.push(context.sectionName);
next();
({ context }) => {
if (shouldCollapse) {
context.collapseSection(context.sectionName);
} else {
context.expandSection(context.sectionName);
}
}
);
});
await visit("/");
assert.ok(transformed.length > 0, "sections were transformed");
// the tests target .sidebar-section-header-collapsable because sections without a header are not collapsable
assert
.dom(
".sidebar-section.sidebar-section--collapsed .sidebar-section-header-collapsable"
)
.exists();
assert
.dom(
".sidebar-section.sidebar-section--expanded .sidebar-section-header-collapsable"
)
.doesNotExist();
});
test("sidebar-section-set-expanded-state transformer - expand all sections", async function (assert) {
const shouldCollapse = false;
withPluginApi("1.35.0", (api) => {
api.registerBehaviorTransformer(
"sidebar-section-set-expanded-state",
({ context }) => {
if (shouldCollapse) {
context.collapseSection(context.sectionName);
} else {
context.expandSection(context.sectionName);
}
}
);
});
await visit("/");
// the tests target .sidebar-section-header-collapsable because sections without a header are not collapsable
assert
.dom(
".sidebar-section.sidebar-section--collapsed .sidebar-section-header-collapsable"
)
.doesNotExist();
assert
.dom(
".sidebar-section.sidebar-section--expanded .sidebar-section-header-collapsable"
)
.exists();
});
});