Skip to content

Commit

Permalink
Fix st.slider tests to address flakiness (streamlit#4107)
Browse files Browse the repository at this point in the history
* Update st.slider tests to fix flakiness

* Update tests to use .contains vs .wait
  • Loading branch information
mayagbarnes authored Nov 30, 2021
1 parent f63fdb6 commit 54a7cb2
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions e2e/specs/st_slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
describe("st.slider", () => {
beforeEach(() => {
cy.visit("http://localhost:3000/");
// Open sidebar expander
cy.get(".streamlit-expanderHeader").click();
});

it("looks right", () => {
// Make the ribbon decoration line disappear
cy.get("[data-testid='stDecoration']").invoke("css", "display", "none");

cy.get(".stSlider")
.eq(2)
.eq(1)
.matchThemedSnapshots("slider");
});

it("shows labels", () => {
// Open sidebar expander
cy.get(".streamlit-expanderHeader").click();
cy.get(".stSlider label").contains("Label B");

cy.get(".stSlider label").should(
"have.text",
"Label A" +
Expand All @@ -45,7 +47,7 @@ describe("st.slider", () => {

it("shows full label when the label is long", () => {
cy.get(".stSlider")
.eq(4)
.eq(3)
.matchThemedSnapshots("slider_with_long_label");
});

Expand All @@ -56,12 +58,20 @@ describe("st.slider", () => {
});

it("does not overlap expander container when thumb value is long", () => {
// Open sidebar expander
cy.get(".streamlit-expanderHeader").click();
cy.get(".stSlider label").contains("Label B");

cy.get(".stSlider")
.eq(1)
.matchThemedSnapshots("expander_thumb_value");
});

it("has correct values", () => {
// Open sidebar expander
cy.get(".streamlit-expanderHeader").click();
cy.get(".stSlider label").contains("Label B");

cy.get(".stMarkdown").should(
"have.text",
"Value A: 12345678" +
Expand All @@ -80,40 +90,40 @@ describe("st.slider", () => {

// trigger click in the center of the slider
cy.get('.stSlider [role="slider"]')
.eq(2)
.eq(1)
.parent()
.click();

cy.get(".stMarkdown")
.eq(2)
.eq(1)
.should("have.text", "Value 1: 50");
});

it("increments the value on right arrow key press", () => {
cy.get('.stSlider [role="slider"]')
.eq(2)
.eq(1)
.click()
.type("{rightarrow}", { force: true });

cy.get(".stMarkdown")
.eq(2)
.eq(1)
.should("have.text", "Value 1: 26");
});

it("decrements the value on left arrow key press", () => {
cy.get('.stSlider [role="slider"]')
.eq(2)
.eq(1)
.click()
.type("{leftarrow}", { force: true });

cy.get(".stMarkdown")
.eq(2)
.eq(1)
.should("have.text", "Value 1: 24");
});

it("maintains its state on rerun", () => {
cy.get('.stSlider [role="slider"]')
.eq(2)
.eq(1)
.click()
.type("{leftarrow}", { force: true });

Expand All @@ -124,7 +134,7 @@ describe("st.slider", () => {
});

cy.get(".stMarkdown")
.eq(2)
.eq(1)
.should("have.text", "Value 1: 24");
});

Expand Down

0 comments on commit 54a7cb2

Please sign in to comment.