Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Improvements to Cypress specs in CI (#1017)
- Fix warnings and verbose output when starting Webpack Dev Server (#1018)
- Add e2e spec for project remix behaviour in web component (#1020)
- Fix initial value of `user` in `WebComponentLoader` (#1021)

## [0.23.0] - 2024-05-09

Expand Down
33 changes: 20 additions & 13 deletions cypress/e2e/spec-wc.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {
const user = { access_token: "dummy-access-token" };
const originalIdentifier = "blank-python-starter";

let baseUrl;

beforeEach(() => {
const urlFor = (identifier) => {
const params = new URLSearchParams();
params.set("auth_key", authKey);
params.set("identifier", originalIdentifier);
params.set("identifier", identifier);
params.set("load_remix_disabled", "true");
baseUrl = `${origin}?${params.toString()}`;
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", () => {
// Visit the original project URL
cy.visit(baseUrl);
// View the original project
cy.visit(urlFor(originalIdentifier));
cy.get("#project-identifier").should("have.text", originalIdentifier);

// Edit code
Expand All @@ -125,14 +125,21 @@ describe("when load_remix_disabled is true, e.g. in editor-standalone", () => {

// 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!");

// 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));

// Visit the original project URL
cy.visit(baseUrl);
// 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!");

// 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!");
});
});
});
5 changes: 4 additions & 1 deletion src/containers/WebComponentLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const WebComponentLoader = (props) => {
const { t } = useTranslation();
const [projectIdentifier, setProjectIdentifier] = useState(identifier);
localStorage.setItem("authKey", authKey);
const user = useSelector((state) => state.auth.user);
const localStorageUser = authKey
Comment thread
floehopper marked this conversation as resolved.
? JSON.parse(localStorage.getItem(authKey))
: null;
const user = useSelector((state) => state.auth.user || localStorageUser);
const [loadCache, setLoadCache] = useState(!!!user);
const [loadRemix, setLoadRemix] = useState(!!user);
const project = useSelector((state) => state.editor.project);
Expand Down
10 changes: 5 additions & 5 deletions src/containers/WebComponentLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe("When no user is in state", () => {
},
hasShownSavePrompt: true,
justLoaded: false,
user: undefined,
user: null,
saveTriggered: false,
});
});
Expand Down Expand Up @@ -146,16 +146,16 @@ describe("When no user is in state", () => {
expect(useProject).toHaveBeenCalledWith({
projectIdentifier: identifier,
code,
accessToken: undefined,
loadRemix: false,
loadCache: true,
accessToken: "my_token",
loadRemix: true,
loadCache: false,
remixLoadFailed: false,
});
});

test("Calls useProjectPersistence hook with correct attributes", () => {
expect(useProjectPersistence).toHaveBeenCalledWith({
user: undefined,
user,
project: { components: [] },
hasShownSavePrompt: true,
justLoaded: false,
Expand Down