Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Nov 20, 2023
1 parent f748010 commit e294ac9
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion demos/test-app/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ lazy_static! {
// the string we are replacing here is inserted by vite during the front-end build
let index_html = index_html.replace(
r#"<script type="module" crossorigin src="/index.js"></script>"#,
&format!(r#"<script>var canisterId = '{canister_id}';</script><script type="module" crossorigin src="/index.js"></script>"#).to_string()
&format!(r#"<script data-canister-id="{canister_id}" type="module" crossorigin src="/index.js"></script>"#).to_string()
);
index_html
};
Expand Down
5 changes: 0 additions & 5 deletions demos/test-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ <h1>Contact the IC</h1>
>Replica URL:
</label>
<input type="text" id="hostUrl" value="https://ic0.app/" />
<br />
<label for="canisterId" style="display: inline-block; width: 120px"
>Canister ID:
</label>
<input type="text" id="canisterId" />
</div>
<div>
<button id="whoamiBtn">Who Am I?</button>
Expand Down
10 changes: 6 additions & 4 deletions demos/test-app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const alternativeOriginsEl = document.getElementById("alternativeOrigins");
const newAlternativeOriginsEl = document.getElementById(
"newAlternativeOrigins"
);
const canisterIdEl = document.getElementById("canisterId");
const principalEl = document.getElementById("principal");
const delegationEl = document.getElementById("delegation");
const expirationEl = document.getElementById("expiration");
Expand Down Expand Up @@ -142,11 +141,14 @@ window.addEventListener("message", (event) => {
}
});

const readCanisterId = () => {
return document.querySelector("[data-canister-id]").dataset.canisterId;
};

const init = async () => {
authClient = await AuthClient.create();
updateDelegationView(authClient.getIdentity());
await updateAlternativeOriginsView();
canisterIdEl.value = canisterId;
signInBtn.onclick = async () => {
let derivationOrigin =
derivationOriginEl.value !== "" ? derivationOriginEl.value : undefined;
Expand Down Expand Up @@ -239,7 +241,7 @@ const init = async () => {
};

updateAlternativeOriginsBtn.onclick = async () => {
const canisterId = Principal.fromText(canisterIdEl.value);
const canisterId = Principal.fromText(readCanisterId());
const httpAgent = new HttpAgent({ host: hostUrlEl.value });
await httpAgent.fetchRootKey();
const actor = Actor.createActor(idlFactory, {
Expand All @@ -265,7 +267,7 @@ init();

whoamiBtn.addEventListener("click", async () => {
const identity = await authClient.getIdentity();
const canisterId = Principal.fromText(canisterIdEl.value);
const canisterId = Principal.fromText(readCanisterId());
const actor = Actor.createActor(idlFactory, {
agent: new HttpAgent({
host: hostUrlEl.value,
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/test-e2e/pinAuth.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Principal } from "@dfinity/principal";
import {
DEVICE_NAME1,
II_URL,
TEST_APP_CANISTER_ID,
TEST_APP_NICE_URL,
} from "./constants";
import { DEVICE_NAME1, II_URL, TEST_APP_NICE_URL } from "./constants";
import { FLOWS } from "./flows";
import {
addVirtualAuthenticator,
Expand Down Expand Up @@ -143,7 +138,7 @@ test("Log into client application using PIN registration flow", async () => {
await FLOWS.registerPinNewIdentityAuthenticateView(pin, browser);

const principal = await demoAppView.waitForAuthenticated();
expect(await demoAppView.whoami(TEST_APP_CANISTER_ID)).toBe(principal);
expect(await demoAppView.whoami()).toBe(principal);

// default value
const exp = await browser.$("#expiration").getText();
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/test-e2e/register.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ import { AuthenticateView, DemoAppView, MainView } from "./views";

// Read canister ids from the corresponding dfx files.
// This assumes that they have been successfully dfx-deployed
import { readFileSync } from "fs";
import { DEVICE_NAME1, II_URL, TEST_APP_NICE_URL } from "./constants";
export const test_app_canister_ids = JSON.parse(
readFileSync("./demos/test-app/.dfx/local/canister_ids.json", "utf-8")
);

const TEST_APP_CANISTER_ID = test_app_canister_ids.test_app.local;

test("Register new identity and login with it", async () => {
await runInBrowser(async (browser: WebdriverIO.Browser) => {
Expand Down Expand Up @@ -60,7 +54,7 @@ test("Log into client application, after registration", async () => {
await switchToPopup(browser);
await FLOWS.registerNewIdentityAuthenticateView(browser);
const principal = await demoAppView.waitForAuthenticated();
expect(await demoAppView.whoami(TEST_APP_CANISTER_ID)).toBe(principal);
expect(await demoAppView.whoami()).toBe(principal);

// default value
const exp = await browser.$("#expiration").getText();
Expand Down Expand Up @@ -97,7 +91,7 @@ test("Register first then log into client application", async () => {
await authenticateView.pickAnchor(userNumber);
await FLOWS.skipRecoveryNag(browser);
const principal = await demoAppView.waitForAuthenticated();
expect(await demoAppView.whoami(TEST_APP_CANISTER_ID)).toBe(principal);
expect(await demoAppView.whoami()).toBe(principal);

// default value
const exp = await browser.$("#expiration").getText();
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/test-e2e/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,8 @@ export class DemoAppView extends View {
await fillText(this.browser, "derivationOrigin", derivationOrigin);
}

async whoami(testCanister: string): Promise<string> {
async whoami(): Promise<string> {
await fillText(this.browser, "hostUrl", this.replicaUrl);
await fillText(this.browser, "canisterId", testCanister);
await this.browser.$("#whoamiBtn").click();
const whoamiResponseElem = await this.browser.$("#whoamiResponse");
await whoamiResponseElem.waitUntil(
Expand Down

0 comments on commit e294ac9

Please sign in to comment.