streamlit

Форк
0
/
hostframe.spec.js 
132 строки · 5.0 Кб
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

17
describe("Host communication", () => {
18
    before(() => {
19
        cy.visit("hostframe.html");
20
        cy.get("#toolbar button").should("have.length", 10);
21
        cy.get("iframe")
22
            .iframe(() => {
23
                cy.waitForScriptFinish()
24
            });
25
    });
26

27
    it("handles a host theme message", () => {
28
        cy.get("iframe").iframe(() => {
29
            cy.prepForElementSnapshots()
30
        });
31

32
        cy.get("iframe").first().matchImageSnapshot("theme-message-before");
33
        cy.get("#toolbar").contains("Send Theme").click();
34
        cy.get("iframe").first().matchImageSnapshot("theme-message-after");
35
    });
36

37
    it("handles a host rerun script message", () => {
38
        cy.get("#toolbar").contains("Rerun Script").click();
39
        // Check that status widget is running
40
        cy.get("iframe").iframe(() => {
41
            cy.get("[data-testid='stStatusWidget']").should("exist")
42
        });
43
    });
44

45
    it("handles a host stop script message", () => {
46
        // Make sure script is running
47
        cy.get("#toolbar").contains("Rerun Script").click();
48
        // Check that status widget is running
49
        cy.get("iframe").iframe(() => {
50
            cy.get("[data-testid='stStatusWidget']").should("exist")
51
        });
52

53
        // Stop script
54
        cy.get("#toolbar").contains("Stop Script").click();
55
        // Check that status widget is no longer running
56
        cy.get("iframe").iframe(() => {
57
            cy.get("[data-testid='stStatusWidget']").should("not.exist")
58
        });
59
    });
60

61
    it("handles a host close modal message", () => {
62
        cy.get("iframe")
63
            .iframe(() => {
64
                // Open the Main Menu
65
                cy.get("#MainMenu > button").click()
66
                // Open the Settings Modal
67
                cy.getIndexed('[data-testid="main-menu-list"] > ul', 1).click({ force: true })
68
                cy.get("div[role='dialog']").should("exist")
69
            });
70
        // Close modal
71
        cy.get("#toolbar").contains("Close modal").click();
72
        // Check that modal is no longer open
73
        cy.get("iframe").iframe(() => {
74
            cy.get("div[role='dialog']").should("not.exist")
75
        });
76
    });
77

78
    it("handles a host menu item message", () => {
79
        // Add Menu Item message
80
        cy.get("#toolbar").contains("Add Menu Item").click({ force: true });
81
        cy.get("iframe")
82
            .iframe(() => {
83
                // Open the Main Menu
84
                cy.get("#MainMenu > button").click()
85
                // Check that new menu item exists
86
                cy.getIndexed('[data-testid="main-menu-list"] > ul', 4).should("have.text", "Adopt a Corgi")
87
                // Exit main menu
88
                cy.get(".main").type('{esc}')
89
            });
90
    });
91

92
    it("handles a host toolbar item message", () => {
93
        // Add Toolbar Item message
94
        cy.get("#toolbar").contains("Add Toolbar Item").click();
95
        cy.get("iframe")
96
            .iframe(() => {
97
                // Check toolbar contents
98
                cy.get('.stActionButton').should("exist")
99
                cy.getIndexed('[data-testid="stActionButton"]', 0).should("have.text", "Favorite")
100
                cy.getIndexed('[data-testid="stActionButton"]', 1).should("have.text", "Share")
101
            });
102
    });
103

104
    it("displays the toolbar with horizontal buttons", () => {
105
        cy.get("iframe").first().matchImageSnapshot("toolbarActions");
106
    })
107

108
    it("handles a hide sidebar nav message", () => {
109
        cy.get("iframe").iframe(() => {
110
            // Check that initially, MPA sidebar nav is visible
111
            cy.get("[data-testid='stSidebarNav']").should("exist")
112
        });
113
        // Trigger hide sidebar nav
114
        cy.get("#toolbar").contains("Hide Sidebar Nav").click();
115
        cy.get("iframe").iframe(() => {
116
            // Check that MPA sidebar nav is hidden
117
            cy.get("[data-testid='stSidebarNav']").should("not.exist")
118
        });
119
    });
120

121
    it("handles a host sidebar downshift message", () => {
122
        // Trigger sidebar downshift
123
        cy.get("#toolbar").contains("Sidebar Chevron Downshift").click();
124
        cy.get("iframe")
125
            .iframe(() => {
126
                // Close sidebar
127
                cy.get("[data-testid='stSidebar'] button").click()
128
                // Check chevron positioning
129
                cy.get("[data-testid='collapsedControl']").should("have.css", "top", "50px")
130
            });
131
    });
132
});
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.