streamlit
1/**
2* Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17describe("st.caption", () => {18before(() => {19cy.loadApp("http://localhost:3000/");20});21
22it("displays correct number of elements", () => {23cy.get(24".element-container .stMarkdown [data-testid='stCaptionContainer']"25).should("have.length", 6);26});27
28it("matches snapshots", () => {29cy.get(30".element-container .stMarkdown [data-testid='stCaptionContainer']"31).then(els => {32cy.wrap(els.slice(1)).each((el, i) => {33return cy.wrap(el).matchThemedSnapshots(`caption-${i}`);34});35});36});37
38it("displays correct content inside caption", () => {39cy.get(40".element-container .stMarkdown [data-testid='stCaptionContainer']"41).then(els => {42expect(els[1].textContent).to.eq("This is a caption!");43expect(els[2].textContent).to.eq(44"This is a caption that contains markdown inside it!"45);46cy.wrap(els[2])47.get("em")48.should("have.text", "caption");49cy.wrap(els[2])50.get("strong")51.should("have.text", "markdown inside it");52// html should be escaped when unsafe_allow_html=False53expect(els[3].textContent).to.eq(54"This is a caption that contains <div>html</div> inside it!"55);56// html should render when unsafe_allow_html=True57expect(els[4].textContent).to.eq(58"This is a caption that contains html inside it!"59);60});61});62
63it("matches snapshot in sidebar", () => {64cy.get("[data-testid='stSidebar'] .stMarkdown").matchThemedSnapshots(65`caption-in-sidebar`66);67});68});69