Skip to content

Commit 59103fc

Browse files
authored
Merge pull request #895 from jsonwebtoken/fix-e2e-tests
Fix e2e tests
2 parents 862d475 + 6023a28 commit 59103fc

File tree

5 files changed

+102
-160
lines changed

5 files changed

+102
-160
lines changed

e2e/decoder.spec.ts

Lines changed: 67 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { MessageStatusValue, MessageTypeValue } from "./e2e.values";
2828
import { JwtDictionaryModel, JwtSignedWithDigitalModel } from "./e2e.models";
2929
import jwts from "./jwt.json" with { type: "json" };
30+
import { EncodingValues } from "@/features/common/values/encoding.values";
3031

3132
const TestJwts = (jwts as JwtDictionaryModel).byAlgorithm;
3233

@@ -39,7 +40,7 @@ test.describe("Can interact with JWT Decoder JWT editor", () => {
3940
const jwtEditorInput = getDecoderJwtEditorInput(page);
4041

4142
await expect(jwtEditorInput).toHaveValue(
42-
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30",
43+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"
4344
);
4445
});
4546

@@ -53,8 +54,13 @@ test.describe("Can interact with JWT Decoder JWT editor", () => {
5354
await expect(jwtEditorInput).toHaveValue(inputValue);
5455
});
5556

56-
test("can copy value in JWT editor", async ({ page, context, browserName }) => {
57-
const permissions = browserName === 'firefox' ? [] : ["clipboard-read", "clipboard-write"]
57+
test("can copy value in JWT editor", async ({
58+
page,
59+
context,
60+
browserName,
61+
}) => {
62+
const permissions =
63+
browserName === "firefox" ? [] : ["clipboard-read", "clipboard-write"];
5864
const inputValue = (TestJwts.RS512 as JwtSignedWithDigitalModel).withPemKey
5965
.jwt;
6066
await context.grantPermissions(permissions);
@@ -76,7 +82,7 @@ test.describe("Can interact with JWT Decoder JWT editor", () => {
7682
await copyButton.click();
7783

7884
const clipboardContent = await page.evaluate(() =>
79-
navigator.clipboard.readText(),
85+
navigator.clipboard.readText()
8086
);
8187

8288
expect(clipboardContent).toBe(inputValue);
@@ -105,51 +111,14 @@ test.describe("Can generate JWT examples", () => {
105111
await page.goto(E2E_BASE_URL);
106112
});
107113

108-
test("Can open and close JWT Decoder example widget", async ({ page }) => {
109-
const lang = await getLang(page);
110-
expectToBeNonNull(lang);
111-
112-
const pickersUiDictionary = getPickersUiDictionary(lang);
113-
114-
const decoderWidget = page.getByTestId(dataTestidDictionary.decoder.id);
115-
116-
const exampleButton = decoderWidget.getByRole("button", {
117-
name: pickersUiDictionary.exampleAlgPicker.label,
118-
});
119-
120-
await exampleButton.click();
121-
122-
await expect(exampleButton).not.toBeVisible();
123-
124-
const closeButton = page.getByRole("button", {
125-
name: pickersUiDictionary.exampleAlgPicker.closeButton.label,
126-
});
127-
128-
await closeButton.click();
129-
130-
await expect(exampleButton).toBeVisible();
131-
await expect(closeButton).not.toBeVisible();
132-
});
133-
134114
test.describe("Can generate a JWT decoder example", () => {
135115
test.beforeEach(async ({ page }) => {
136116
const lang = await getLang(page);
137117
expectToBeNonNull(lang);
138118

139119
const pickersUiDictionary = getPickersUiDictionary(lang);
140-
141-
const decoderWidget = page.getByTestId(dataTestidDictionary.decoder.id);
142-
143-
const exampleButton = decoderWidget.getByRole("button", {
144-
name: pickersUiDictionary.exampleAlgPicker.label,
145-
});
146-
147-
await exampleButton.click();
148-
149-
await expect(exampleButton).not.toBeVisible();
150-
151-
const pickerIndicator = decoderWidget.getByText(
152-
pickersUiDictionary.exampleAlgPicker.defaultValue,
120+
const pickerIndicator = page.getByText(
121+
pickersUiDictionary.exampleAlgPicker.defaultValue
153122
);
154123

155124
await pickerIndicator.click();
@@ -174,7 +143,7 @@ test.describe("Can generate JWT examples", () => {
174143
const targetToken = DefaultTokensValues[option];
175144

176145
const jwtEditor = decoderWidget.getByTestId(
177-
dataTestidDictionary.decoder.jwtEditor.id,
146+
dataTestidDictionary.decoder.jwtEditor.id
178147
);
179148
const jwtEditorInput = jwtEditor.getByRole("textbox");
180149

@@ -203,7 +172,7 @@ test.describe("Can generate JWT examples", () => {
203172
});
204173

205174
const secretKeyEditor = decoderWidget.getByTestId(
206-
dataTestidDictionary.decoder.secretKeyEditor.id,
175+
dataTestidDictionary.decoder.secretKeyEditor.id
207176
);
208177
const secretKeyInput = secretKeyEditor.getByRole("textbox");
209178

@@ -217,9 +186,13 @@ test.describe("Can generate JWT examples", () => {
217186
status: MessageStatusValue.VISIBLE,
218187
});
219188

220-
const encodingValue = await secretKeyEditor
221-
.locator(".react-select__single-value")
222-
.innerText();
189+
const isEncodingSwitchChecked = await page
190+
.getByRole("switch")
191+
.isChecked();
192+
193+
const encodingValue = isEncodingSwitchChecked
194+
? EncodingValues.BASE64URL
195+
: EncodingValues.UTF8;
223196

224197
expect(encodingValue).toBe(symmetricToken.secretEncoding);
225198

@@ -236,8 +209,9 @@ test.describe("Can generate JWT examples", () => {
236209
status: MessageStatusValue.VISIBLE,
237210
});
238211

239-
const formatValue = await secretKeyEditor
212+
const formatValue = await page
240213
.locator(".react-select__single-value")
214+
.nth(1)
241215
.innerText();
242216

243217
expect(formatValue).toBe(asymmetricToken.publicKeyFormat);
@@ -270,7 +244,7 @@ test.describe("decode JWTs", () => {
270244
const decoderWidget = page.getByTestId(dataTestidDictionary.decoder.id);
271245

272246
const jwtEditor = decoderWidget.getByTestId(
273-
dataTestidDictionary.decoder.jwtEditor.id,
247+
dataTestidDictionary.decoder.jwtEditor.id
274248
);
275249
const jwtEditorInput = jwtEditor.getByRole("textbox");
276250

@@ -327,14 +301,14 @@ test.describe("decode JWTs", () => {
327301
});
328302

329303
const secretKeyEditor = decoderWidget.getByTestId(
330-
dataTestidDictionary.decoder.secretKeyEditor.id,
304+
dataTestidDictionary.decoder.secretKeyEditor.id
331305
);
332306
const secretKeyEditorInput = secretKeyEditor.getByRole("textbox");
333307

334308
await secretKeyEditorInput.fill(entryWithUtf8Secret.secret);
335309

336310
await expect(secretKeyEditorInput).toHaveValue(
337-
entryWithUtf8Secret.secret,
311+
entryWithUtf8Secret.secret
338312
);
339313

340314
await checkSecretKeyDecoderEditorStatusBarMessage({
@@ -343,9 +317,13 @@ test.describe("decode JWTs", () => {
343317
status: MessageStatusValue.VISIBLE,
344318
});
345319

346-
const encodingValue = await secretKeyEditor
347-
.locator(".react-select__single-value")
348-
.innerText();
320+
const isEncodingSwitchChecked = await page
321+
.getByRole("switch")
322+
.isChecked();
323+
324+
const encodingValue = isEncodingSwitchChecked
325+
? EncodingValues.BASE64URL
326+
: EncodingValues.UTF8;
349327

350328
expect(encodingValue).toBe(entryWithUtf8Secret.secretEncoding);
351329

@@ -388,17 +366,13 @@ test.describe("decode JWTs", () => {
388366
status: MessageStatusValue.VISIBLE,
389367
});
390368

391-
const formatPicker = secretKeyEditor.locator(
392-
".react-select__single-value",
393-
);
394-
395-
await formatPicker.click();
369+
const encodingSwitch = await page.getByTestId(dataTestidDictionary.encoder.switch)
370+
expect(encodingSwitch).toBeVisible()
396371

397-
await page
398-
.getByRole("option", {
399-
name: entryWithBase64urlSecret.secretEncoding,
400-
})
401-
.click();
372+
if (
373+
entryWithBase64urlSecret.secretEncoding === EncodingValues.BASE64URL
374+
)
375+
await encodingSwitch.click();
402376

403377
await secretKeyEditorInput.fill(entryWithBase64urlSecret.secret);
404378

@@ -451,7 +425,7 @@ test.describe("decode JWTs", () => {
451425
});
452426

453427
const secretKeyEditor = decoderWidget.getByTestId(
454-
dataTestidDictionary.decoder.secretKeyEditor.id,
428+
dataTestidDictionary.decoder.secretKeyEditor.id
455429
);
456430
const secretKeyEditorInput = secretKeyEditor.getByRole("textbox");
457431

@@ -465,7 +439,7 @@ test.describe("decode JWTs", () => {
465439
status: MessageStatusValue.VISIBLE,
466440
});
467441

468-
const formatValue = await secretKeyEditor
442+
const formatValue = await page
469443
.locator(".react-select__single-value")
470444
.innerText();
471445

@@ -511,8 +485,8 @@ test.describe("decode JWTs", () => {
511485
status: MessageStatusValue.VISIBLE,
512486
});
513487

514-
const formatPicker = secretKeyEditor.locator(
515-
".react-select__single-value",
488+
const formatPicker = page.locator(
489+
".react-select__single-value"
516490
);
517491

518492
await formatPicker.click();
@@ -530,7 +504,7 @@ test.describe("decode JWTs", () => {
530504
});
531505

532506
await secretKeyEditorInput.fill(
533-
JSON.stringify(entrywithJwkKey.publicKey, null, 2),
507+
JSON.stringify(entrywithJwkKey.publicKey, null, 2)
534508
);
535509

536510
await checkJwtEditorStatusBarMessage({
@@ -581,8 +555,8 @@ test.describe("decode JWTs", () => {
581555
status: MessageStatusValue.VISIBLE,
582556
});
583557

584-
const formatPicker = secretKeyEditor.locator(
585-
".react-select__single-value",
558+
const formatPicker = page.locator(
559+
".react-select__single-value"
586560
);
587561

588562
await formatPicker.click();
@@ -594,7 +568,7 @@ test.describe("decode JWTs", () => {
594568
.click();
595569

596570
await secretKeyEditorInput.fill(
597-
JSON.stringify(entrywithJwkKey.publicKey, null, 2),
571+
JSON.stringify(entrywithJwkKey.publicKey, null, 2)
598572
);
599573

600574
await checkJwtEditorStatusBarMessage({
@@ -642,10 +616,10 @@ test("Can decode JWTs signed with a non-supported algorithm", async ({
642616
kid: "sig",
643617
};
644618
const expectedDecodedPayload = {
645-
"sub": "1234567890",
646-
"name": "John Doe",
647-
"admin": true,
648-
"iat": 1516239022
619+
sub: "1234567890",
620+
name: "John Doe",
621+
admin: true,
622+
iat: 1516239022,
649623
};
650624

651625
await page.goto(E2E_BASE_URL);
@@ -656,7 +630,7 @@ test("Can decode JWTs signed with a non-supported algorithm", async ({
656630
const decoderWidget = page.getByTestId(dataTestidDictionary.decoder.id);
657631

658632
const jwtEditor = decoderWidget.getByTestId(
659-
dataTestidDictionary.decoder.jwtEditor.id,
633+
dataTestidDictionary.decoder.jwtEditor.id
660634
);
661635
const jwtEditorInput = jwtEditor.getByRole("textbox");
662636

@@ -678,22 +652,22 @@ test("Can decode JWTs signed with a non-supported algorithm", async ({
678652

679653
await expect(
680654
decoderWidget.getByTestId(
681-
dataTestidDictionary.decoder.decodedHeader.json.id,
682-
),
655+
dataTestidDictionary.decoder.decodedHeader.json.id
656+
)
683657
).toHaveText(JSON.stringify(expectedDecodedHeader, null, 2), {
684658
useInnerText: true,
685659
});
686660

687661
await expect(
688662
decoderWidget.getByTestId(
689-
dataTestidDictionary.decoder.decodedPayload.json.id,
690-
),
663+
dataTestidDictionary.decoder.decodedPayload.json.id
664+
)
691665
).toHaveText(JSON.stringify(expectedDecodedPayload, null, 2), {
692666
useInnerText: true,
693667
});
694668

695669
const secretKeyEditor = decoderWidget.getByTestId(
696-
dataTestidDictionary.decoder.secretKeyEditor.id,
670+
dataTestidDictionary.decoder.secretKeyEditor.id
697671
);
698672

699673
await expect(secretKeyEditor).not.toBeVisible();
@@ -711,10 +685,10 @@ test.describe("Decode pieces of JWTs in Base64Url", () => {
711685
jwtPiece:
712686
"eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0",
713687
expectedDecodedOutput: {
714-
"sub": "1234567890",
715-
"name": "John Doe",
716-
"admin": true,
717-
"iat": 1516239022
688+
sub: "1234567890",
689+
name: "John Doe",
690+
admin: true,
691+
iat: 1516239022,
718692
},
719693
},
720694
{
@@ -737,7 +711,7 @@ test.describe("Decode pieces of JWTs in Base64Url", () => {
737711
const decoderWidget = page.getByTestId(dataTestidDictionary.decoder.id);
738712

739713
const jwtEditor = decoderWidget.getByTestId(
740-
dataTestidDictionary.decoder.jwtEditor.id,
714+
dataTestidDictionary.decoder.jwtEditor.id
741715
);
742716
const jwtEditorInput = jwtEditor.getByRole("textbox");
743717

@@ -759,20 +733,20 @@ test.describe("Decode pieces of JWTs in Base64Url", () => {
759733

760734
await expect(
761735
decoderWidget.getByTestId(
762-
dataTestidDictionary.decoder.decodedHeader.json.id,
763-
),
736+
dataTestidDictionary.decoder.decodedHeader.json.id
737+
)
764738
).toHaveText(JSON.stringify(expectedDecodedOutput, null, 2), {
765739
useInnerText: true,
766740
});
767741

768742
await expect(
769743
decoderWidget.getByTestId(
770-
dataTestidDictionary.decoder.decodedPayload.json.id,
771-
),
744+
dataTestidDictionary.decoder.decodedPayload.json.id
745+
)
772746
).toBeEmpty();
773747

774748
const secretKeyEditor = decoderWidget.getByTestId(
775-
dataTestidDictionary.decoder.secretKeyEditor.id,
749+
dataTestidDictionary.decoder.secretKeyEditor.id
776750
);
777751

778752
await expect(secretKeyEditor).not.toBeVisible();

0 commit comments

Comments
 (0)