Skip to content

Instantly share code, notes, and snippets.

View nottyo's full-sized avatar

Traitanit Huangsri nottyo

View GitHub Profile
@nottyo
nottyo / login-session.spec.js
Created May 1, 2022 03:36
login with session
describe('login with session', () => {
beforeEach(() => {
// login once for all test cases and preserve its login session.
cy.lineLoginWithSession(Cypress.env('email'), Cypress.env('password'));
cy.visit(Cypress.config('baseUrl'));
});
it('render profileUrl', () => {
cy.get('img[alt="profileUrl"]').should('be.visible');
});
@nottyo
nottyo / commands.js
Created May 1, 2022 03:35
login-with-session
Cypress.Commands.add('lineLoginWithSession', (email, password) => {
// v2 with session cache
const args = { email, password };
cy.intercept({
method: 'POST',
url: 'https://api.line.me/oauth2/v2.1/token',
}).as('createToken');
cy.session(
// use email, password as a session cache key
args,
@nottyo
nottyo / commands.js
Created May 1, 2022 03:13
custom-command login
Cypress.Commands.add('lineLoginWithoutSession', (email, password) => {
const args = { email, password };
// intercept token request for checking if it's success
cy.intercept({
method: 'POST',
url: 'https://api.line.me/oauth2/v2.1/token',
}).as('createToken');
cy.visit(Cypress.config('baseUrl'));
cy.get('[data-testid="login"]').click();
cy.origin('https://access.line.me', { args }, ({ email, password }) => {
@nottyo
nottyo / simple-login.spec.js
Last active May 1, 2022 03:26
login-custom-command
describe('simple login', () => {
beforeEach(() => {
// do login before each test case so number of login = number of test cases
cy.lineLoginWithoutSession(Cypress.env('email'), Cypress.env('password'));
});
it('render profileUrl', () => {
cy.get('img[alt="profileUrl"]').should('be.visible');
});
@nottyo
nottyo / simple-login.spec.js
Created April 30, 2022 11:14
cypress - line login - simple
describe('Simple Line Login', () => {
it('login without optimization', () => {
const args = { email: Cypress.env('email'), password: Cypress.env('password') };
cy.visit(Cypress.config('baseUrl'));
cy.get('[data-testid="login"]').click();
cy.origin('https://access.line.me', { args }, ({ email, password }) => {
cy.get('input[type="text"]').type(email);
cy.get('input[type="password"]').type(password);
cy.get('button[type="submit"]').click();
});
@nottyo
nottyo / App.tsx
Created April 25, 2022 07:21
Handle LIFF LINE In-App Browser
import { useEffect, useState } from "react";
import liff from "@line/liff";
import "./App.css";
function App() {
const [message, setMessage] = useState("");
const [data, setData] = useState({
isInLineInAppBrowser: false
});
const [error, setError] = useState("");
@nottyo
nottyo / index.js
Created April 25, 2022 06:24
isInLineInAppBrowser
const { userAgent } = navigator;
const isInLineInAppBrowser = !liff.isInClient() && userAgent.includes('Line');
@nottyo
nottyo / commands.js
Last active April 14, 2022 05:24
cypress - qrcode reader
import { BrowserMultiFormatReader } from '@zxing/browser';
const reader = new BrowserMultiFormatReader();
Cypress.Commands.add('readCode', { prevSubject: true }, (subject) => {
const img = subject[0];
const image = new Image();
image.width = img.width;
image.height = img.height;
image.src = img.src;
@nottyo
nottyo / qrcode.spec.js
Created April 14, 2022 05:14
cypress - qrcode reader
describe('QR Code', () => {
it('can read qrcode', () => {
cy.visit('./qrcode.html');
cy.get('[data-testid="qr-code-img"]')
.then($el => {
const img = $el[0];
const image = new Image();
image.width = img.width;
image.height = img.height;
image.src = img.src;
@nottyo
nottyo / .eslintrc.json
Last active March 4, 2022 09:11
ESLint Test Selectors - Custom Attribute Name
{
"plugins": [
"test-selectors"
],
"extends": [
"react-app",
"react-app/jest",
"plugin:test-selectors/recommendedWithErrors"
],
"rules": {