-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathspec-wc.cy.js
More file actions
144 lines (121 loc) · 5.04 KB
/
spec-wc.cy.js
File metadata and controls
144 lines (121 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const origin = "http://localhost:3001";
beforeEach(() => {
cy.intercept("*", (req) => {
req.headers["Origin"] = origin;
req.continue();
});
});
describe("default behaviour", () => {
beforeEach(() => {
cy.visit(origin);
});
it("renders the web component", () => {
cy.get("editor-wc").shadow().find("button").should("contain", "Run");
});
it("defaults to the text output tab", () => {
const runnerContainer = cy
.get("editor-wc")
.shadow()
.find(".proj-runner-container");
runnerContainer
.find(".react-tabs__tab--selected")
.should("contain", "Text output");
});
it("runs the python code", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", 'print("Hello world")');
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc")
.shadow()
.find(".pythonrunner-console-output-line")
.should("contain", "Hello world");
});
it("runs p5 code", () => {
const code = `from p5 import *\n\ndef setup():\n size(400, 400) # width and height of screen\n\ndef draw():\n fill('cyan') # Set the fill color for the sky to cyan\n rect(0, 0, 400, 250) # Draw a rectangle for the sky with these values for x, y, width, height \n \nrun(frame_rate=2)\n`;
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", code);
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().find(".p5Canvas").should("exist");
});
it("does not render visual output tab on page load", () => {
cy.get("editor-wc")
.shadow()
.find("#root")
.should("not.contain", "Visual output");
});
it("renders visual output tab if sense hat imported", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "import sense_hat");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().find("#root").should("contain", "Visual output");
});
it("does not render astro pi component on page load", () => {
cy.get("editor-wc").shadow().find("#root").should("not.contain", "yaw");
});
it("renders astro pi component if sense hat imported", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "import sense_hat");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().contains("Visual output").click();
cy.get("editor-wc").shadow().find("#root").should("contain", "yaw");
});
it("does not render astro pi component if sense hat unimported", () => {
cy.get("editor-wc")
.shadow()
.find("div[class=cm-content]")
.invoke("text", "import sense_hat");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().find("div[class=cm-content]").invoke("text", "");
cy.get("editor-wc").shadow().find(".btn--run").click();
cy.get("editor-wc").shadow().contains("Visual output").click();
cy.get("editor-wc").shadow().find("#root").should("not.contain", "yaw");
});
});
describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {
const authKey = `oidc.user:https://auth-v1.raspberrypi.org:editor-api`;
const user = { access_token: "dummy-access-token" };
const originalIdentifier = "blank-python-starter";
const urlFor = (identifier) => {
const params = new URLSearchParams();
params.set("auth_key", authKey);
params.set("identifier", identifier);
params.set("load_remix_disabled", "true");
return `${origin}?${params.toString()}`;
};
beforeEach(() => {
cy.on('window:before:load', (win) => {
win.localStorage.setItem(authKey, JSON.stringify(user));
});
});
it("loads the original project in preference to the remixed version", () => {
// View the original project
cy.visit(urlFor(originalIdentifier));
cy.get("#project-identifier").should("have.text", originalIdentifier);
// Edit code
cy.get("editor-wc").shadow().find("[contenteditable]").type("# remixed!");
// Save project
cy.get("editor-wc").shadow().contains("Save").click();
// Check receipt of an event to trigger a redirect to the remixed project URL
cy.get("#project-identifier").should("not.have.text", originalIdentifier);
cy.get("#project-identifier").invoke("text").then((remixIdentifier) => {
// Check we're still seeing the changed code
cy.get("editor-wc").shadow().find("[contenteditable]").should("have.text", "# remixed!");
// Visit the original project again
cy.visit(urlFor(originalIdentifier));
// Check we no longer see the changed code, i.e. `load_remix_disabled=true` is respected
cy.get("editor-wc").shadow().find("[contenteditable]").should("not.have.text", "# remixed!");
// View the remixed project
cy.visit(urlFor(remixIdentifier));
// Check we're still seeing the changed code
cy.get("editor-wc").shadow().find("[contenteditable]").should("have.text", "# remixed!");
});
});
});